主:
port 26379pidfile "/usr/local/redis/var/redis-sentinel.pid"
dir "/usr/local/redis/data/sentinel"
daemonize yes
logfile "/usr/local/redis/var/redis-sentinel.log"
sentinel myid aeff525d03a2234ef834808f7991761db03a1973
sentinel monitor mymaster 10.1.0.160 6379 2
sentinel parallel-syncs mymaster 2
sentinel auth-pass mymaster 20170310
# Generated by CONFIG REWRITE
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel known-slave mymaster 10.1.0.71 6379
sentinel known-slave mymaster 10.1.0.161 6379
sentinel current-epoch 0
从1:
port 26379pidfile "/usr/local/redis/var/redis-sentinel.pid"
dir "/usr/local/redis/data/sentinel"
daemonize yes
logfile "/usr/local/redis/var/redis-sentinel.log"
sentinel myid 01b1b7674abe648f6a2344fc5610e73b7e87cb8a
sentinel monitor mymaster 10.1.0.160 6379 2
sentinel config-epoch mymaster 0
# Generated by CONFIG REWRITE
sentinel leader-epoch mymaster 0
sentinel current-epoch 0
从2:
port 26379pidfile "/usr/local/redis/var/redis-sentinel.pid"
dir "/usr/local/redis/data/sentinel"
daemonize yes
logfile "/usr/local/redis/var/redis-sentinel.log"
sentinel myid f1589f48079b3b3b536add4e2e01a36304aeba8c
sentinel monitor mymaster 10.1.0.160 6379 2
sentinel config-epoch mymaster 0
# Generated by CONFIG REWRITE
sentinel leader-epoch mymaster 0
sentinel current-epoch 0
模拟主故障
[root@show160 redis]# /usr/local/redis/bin/redis-cli -p 6379127.0.0.1:6379> AUTH 20170310
OK
127.0.0.1:6379> DEBUG SEGFAULT
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> quit
从哨兵配置文件中可以看到当前的主库的已经发生了改变
4. 总结redis的哨兵端口26379使用redis-cli可以连接查看哨兵相关信息,要想连接此高可用redis,可使用官方的连接客户端。使用哨兵监控当主故障后会自动切换从为主,当主启动后就变成了从。至少要3哨兵和3redis节点才能允许挂一节点还能保证服务可用性。
下面关于Redis的文章您也可能喜欢,不妨参考下:
Ubuntu 14.04下Redis安装及简单测试
Ubuntu 16.04环境中安装PHP7.0 Redis扩展
CentOS 7.0 安装Redis 3.2.1详细过程和使用常见问题