redis哨兵模式部署


配置文件sentinel.conf

port 26379
sentinel monitor mymaster 192.168.41.128 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 10000
sentinel deny-scripts-reconfig yes

启动1主2从

# 启动主节点
docker run -d --net host --name redis-server redis:6.2.5 redis-server --port 6379
# 启动从节点
docker run -d --net host --name redis-slave1 redis:6.2.5 redis-server --slaveof 192.168.41.128 6379  --port 6378
docker run -d --net host --name redis-slave2 redis:6.2.5 redis-server --slaveof 192.168.41.128 6379  --port 6377

启动哨兵

docker run -d -p 26379:26379 --name redis-sentinel1 -v $PWD/sentinel1.conf:/sentinel/sentinel.conf redis:6.2.5 redis-sentinel /sentinel/sentinel.conf
docker run -d -p 26378:26379 --name redis-sentinel2 -v $PWD/sentinel2.conf:/sentinel/sentinel.conf redis:6.2.5 redis-sentinel /sentinel/sentinel.conf
docker run -d -p 26377:26379 --name redis-sentinel3 -v $PWD/sentinel2.conf:/sentinel/sentinel.conf redis:6.2.5 redis-sentinel /sentinel/sentinel.conf

查看状态

[root@node1 redis]# docker exec -it redis-sentinel1 bash
root@be853924137f:/data# redis-cli -p 26379
127.0.0.1:26379> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=sdown,address=192.168.41.128:6379,slaves=1,sentinels=3

# 查看masters
127.0.0.1:26379> SENTINEL masters

# 查看slaves
127.0.0.1:26379> SENTINEL slaves mymaster

# 关闭redis-server
docker stop redis-server
# 刷新查看master节点是否更换
docker exec -it  redis-sentinel1 redis-cli -p 26379 sentinel masters

文章作者: wuzhiyong
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 wuzhiyong !
评论
 上一篇
mysql8用户密码问题 mysql8用户密码问题
问题navicat连接mysql8.0.26时报错. Client does not support authentication protocol requested by server; consider upgrading MySQL
2021-08-25
下一篇 
redis主从模式部署 redis主从模式部署
启动参数 --requirepass 123456:设置客户端连接redis的认证信息 --masterauth 123456:设置从节点连接redis的认证信息 一主一从# 启动主节点 docker run -d -p 6379:637
2021-08-19
  目录