0%

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