redis sentinel单机搭建记录

本文详细介绍了Redis主从配置及哨兵集群的搭建过程,包括master和slave节点的配置,哨兵节点的设置,以及如何通过哨兵实现故障转移。文章还提供了测试连接的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • redis安装那么简单的就不记录了 随便百度就ok

redis master 的配置

  • 本机外网ip:139.105.140.119

master redis.conf

port 6379
tcp-backlog 100
timeout 0
tcp-keepalive 0
daemonize yes
supervised no
pidfile "/var/run/redis.pid"
loglevel notice
logfile "/tty/dev/data/log/redis/redis01.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
dir "/tty/dev/data/redis"
masterauth "how123"
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
requirepass "how123"
rename-command FLUSHALL ""
rename-command FLUSHDB ""
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
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 10
slowlog-max-len 128
latency-monitor-threshold 1
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
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

slave redis.conf

port 6378
tcp-backlog 100
timeout 0
tcp-keepalive 0
daemonize yes
supervised no
pidfile "/var/run/redis.pid"
loglevel notice
logfile "/tty/dev/data/log/redis/redis01.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
dir "/tty/dev/data/redis"
masterauth "how123"
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
requirepass "how123"
rename-command FLUSHALL ""
rename-command FLUSHDB ""
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
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 10
slowlog-max-len 128
latency-monitor-threshold 1
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
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 139.105.140.119 6379

master sentinel.conf

port 26379 
sentinel myid 10ea243b09fa79b3ab66b1823c3bb6a65e6db64d    #当前sentinel地址
dir "/tmp"
sentinel monitor redis_master 139.105.140.119  6379 2    #redis master的地址
sentinel down-after-milliseconds redis_master 10000
sentinel auth-pass redis_master redispassword
sentinel config-epoch redis_master 91
sentinel leader-epoch redis_master 91
bind 0.0.0.0
sentinel known-slave redis_master 139.105.140.119  6378   #redis slave地址
#sentinel known-sentinel redis_master 139.105.140.119  26378  a0123093ee65a6648c246a3e9b8e52011ef66f32 #另一台sentinel的地址+端口
sentinel current-epoch 91

slave sentinel.conf

port 26378
sentinel myid a0123093ee65a6648c246a3e9b8e52011ef66f32      #当前sentinel地址
dir "/tmp"
sentinel monitor redis_master 139.105.140.119 6378 2         #redis slave地址
sentinel down-after-milliseconds redis_master 10000
sentinel auth-pass redis_master redispassword
sentinel config-epoch redis_master 91
sentinel leader-epoch redis_master 91
bind 0.0.0.0
sentinel known-slave redis_master 139.105.140.119 6379     #redis master的地址+端口
sentinel known-sentinel redis_master 139.105.140.119 26379 10ea243b09fa79b3ab66b1823c3bb6a65e6db64d #另一台sentinel的地址+端口
sentinel current-epoch 91

装好后测试:

redis-cli -h 139.105.140.119 -p 26379 -a redispassword
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阳十三

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值