redis 集群架构图:
需要先配置redis主从,我这边是单机部署的。
采用一主一从,两个sentinel。
redis host: 172.31.11.235
redis-master port: 6380 sentinel1: 26380
redis-slave port: 6381 sentinel2: 26381
redis master redis.conf中添加:
masterauth "xxxx"
requirepass "xxxx"
redis slave redis.conf中添加:
masterauth "xxxx"
requirepass "xxxx"
slaveof 172.31.11.235 6380
redis sentinel1配置:
bind 172.31.11.235
port 26380
daemonize yes
logfile "/usr/local/redis-4.0.9/sentinel.log.26380"
#master1
# 哨兵监控这个master,在至少1个哨兵实例都认为master down后把master标记为odown
sentinel monitor master1 172.31.11.235 6380 1
#多少毫秒后,sentinel 认定redis master 服务器已掉线
sentinel down-after-milliseconds master1 5000
# 若sentinel在该配置值内未能完成failover操作(即故障时master/slave自动切换),则认为本次failover失败
sentinel failover-timeout master1 10000
#sentinel can-failover master1 yes
sentinel parallel-syncs master1 2
# Generated by CONFIG REWRITE
dir "/usr/local/redis-4.0.9"
sentinel auth-pass master1 xxxxx
redis sentinel2配置:
bind 172.31.11.235
port 26381
daemonize yes
logfile "/usr/local/redis-4.0.9/sentinel.log.26381"
#master1
sentinel monitor master1 172.31.11.235 6380 1
sentinel down-after-milliseconds master1 5000
# Generated by CONFIG REWRITE
dir "/usr/local/redis-4.0.9"
sentinel failover-timeout master1 10000
sentinel auth-pass master1 xxxxx
分别启动 redis-master、redis-slave 和两个哨兵。
redis-server conf/redis.conf.6380 &
redis-server conf/redis.conf.6381 &
redis-sentinel sentinel.conf.26380 &
redis-sentinel sentinel.conf.26381 &
故障演练:
关闭 redis-master,查看master地址
可以看到主节点已正常完成切换,配置完成。
参考链接:http://www.yunweipai.com/archives/20444.html