redis主从配置启动(1主2从)

一、安装redis
https://www.cnblogs.com/velloLei/p/18410629

二、主节点配置文件

bind 0.0.0.0
port 6879
daemonize yes
pidfile /usr/local/redis/sentinel/data/redis-6879.pid
logfile "/usr/local/redis/sentinel/logs/redis-6879.log"
dbfilename redis-6879.rdb
dir /usr/local/redis/sentinel/data/
appendonly yes
appendfilename "appendonly-6879.aof"

databases 16

save ""

save 900 1

save 300 10

save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes
rdbchecksum yes

dbfilename dump.rdb
dir /usr/local/redis/data/

如果做故障切换,不论主从节点都要填写密码且要保持一致

masterauth linlin

slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 100

requirepass linlin

appendonly yes
appendfilename "appendonly.aof"

appendfsync always

appendfsync everysec

appendfsync no

no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes

lua-time-limit 5000

slowlog-log-slower-than 1000
slowlog-max-len 1000

latency-monitor-threshold 0

notify-keyspace-events ""

hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000

activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

hz 10
aof-rewrite-incremental-fsync yes

三、从节点配置文件

只需要复制主节点配置,增加slaveof xxx
修改6879端口 使用 sed -i 's/6879/6880/g' 6880.conf就可以

bind 0.0.0.0
port 6880
daemonize yes
pidfile /opt/redis5/bin/sentinel/data/redis-6880.pid
logfile "/opt/redis5/bin/sentinel/logs/redis-6880.log"
dbfilename redis-6880.rdb
dir /opt/redis5/bin/sentinel/data/
appendonly yes
appendfilename "appendonly-6880.aof"

同台机器多个端口 一定要用 127.0.0.1 ,否则无法同步

replicaof 127.0.0.1 6879

四、同上配置6381节点的配置文件
修改6880端口 使用 sed -i 's/6880/6881/g' 6881.conf就可以

五、启动
主节点启动
./redis-server 6879.conf
会报logs文件夹不存在
可以使用 mkdir -p /usr/local/xxx/logs 完成logs文件夹的创建
可以使用 mkdir -p /usr/local/xxx/data完成data文件夹的创建
./redis-server 6880.conf
./redis-server 6881.conf

六、启动完毕后查看 redis集群
./redis-cli -p 6379 -a xxx密码 info replication

posted @   vello  阅读(226)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示