解决问题
自动故障修复
1.在主从模式的基础上,在主节点添加自己的认证密码即可
2.将代码客户端地址改为哨兵地址
-------------
主节点配置
daemonize yes
port 6379
bind 0.0.0.0
requirepass 123456
save 3600 1 300 100 60 10000
dir /usr/local/redis
dbfilename dump.rdb
logfile redis.log
pidfile redis.pid
masterauth 123456
从节点配置
daemonize yes
port 6379
bind 0.0.0.0
requirepass 123456
save 3600 1 300 100 60 10000
dir /usr/local/redis
dbfilename dump.rdb
logfile redis.log
pidfile redis.pid
replicaof 172.22.46.31 6379
masterauth 123456
-------------
哨兵节点配置
哨兵需要知道的内容
1.密码
1.要监控的集群(知道主节点地址即可)
2.下线的时间(主观下限)
3.法定人数(客观下线)
-----
sentinel.conf
daemonize yes
port 26379
bind 0.0.0.0
requirepass 123456
dir /usr/local/redis
logfile sentinel.log
pidfile sentinel.pid
sentinel monitor mymaster 172.22.46.31 6379 2
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 30000
#sentinel monitor mymaster 172.22.46.31 6379 2
#2代表法定人数
#30000代表超时时间
-------------
sentinel启动脚本
vim start-sentinel.sh
------
#!/bin/bash
/redis/bin/redis-sentinel /usr/local/redis/sentinel.conf
------
chmod start-sentinel.sh
-------------
-------------
vim stop-sentinel.sh
------
#!/bin/bash
export REDISCLI_AUTH=123456
/redis/bin/redis-cli -p 26379 SHUTDOWN
------
chmod stop-sentinel.sh
-------------
连接测试
info sentinel
获取主节点信息
SENTINEL GET-MASTER-ADDR-BY-NAME mymaster
获取详细信息
sentinel replicas mymaster
-------------
哨兵原理解析,redis频道订阅模式
注:哨兵频道订阅
subscribe __sentinel__:hello
publish __sentinel__:hello zhangsan