设置相关的key检查
master
127.0.0.1:6379> dbsize
(integer) 5
127.0.0.1:6379> keys *
1) "winnerlook"
2) "redis"
3) "bund"
4) "baidu"
5) "bund33"
127.0.0.1:6379>
slave
127.0.0.1:6379> dbsize
(integer) 5
127.0.0.1:6379> keys *
1) "winnerlook"
2) "redis"
3) "bund"
4) "baidu"
5) "bund33"
127.0.0.1:6379>
由此可见配置的redis主从是可以正常工作的,接下来就是准备配置Sentinel,并启动相关的服务。
10.1.4.99 sentinel 1配置文件
pdaemonize yes #后台运行
protected-mode no #保护模式关闭
# Generated by CONFIG REWRITE
dir "/etc/redis"
port 26379 #哨兵端口
sentinel monitor master1 10.1.4.99 6379 2 # 监听IP 端口 默认最少投票数量
sentinel down-after-milliseconds master1 5000
sentinel failover-timeout master1 5000 #选举超时时间
logfile "/data/redis/sentinel/sentinel_26379.log" #日志文件
sentinel auth-pass master1 Redis2017 #redis密码
10.1.4.99 sentinel 2配置文件
pdaemonize yes #后台运行
protected-mode no #保护模式关闭
# Generated by CONFIG REWRITE
dir "/etc/redis"
port 26380 #哨兵端口
sentinel monitor master1 10.1.4.99 6379 2 # 监听IP 端口 默认最少投票数量
sentinel down-after-milliseconds master1 5000
sentinel failover-timeout master1 5000 #选举超时时间
logfile "/data/redis/sentinel/sentinel_26379.log" #日志文件
sentinel auth-pass master1 Redis2017 #redis密码
10.1.4.82 sentinel 1配置
pdaemonize yes #后台运行
protected-mode no #保护模式关闭
# Generated by CONFIG REWRITE
dir "/etc/redis"
port 26379 #哨兵端口
sentinel monitor master1 10.1.4.99 6379 2 # 监听IP 端口 默认最少投票数量
sentinel down-after-milliseconds master1 5000
sentinel failover-timeout master1 5000 #选举超时时间
logfile "/data/redis/sentinel/sentinel_26379.log" #日志文件
sentinel auth-pass master1 Redis2017 #redis密码
10.1.4.82 sentinel 2配置
pdaemonize yes #后台运行
protected-mode no #保护模式关闭
# Generated by CONFIG REWRITE
dir "/etc/redis"
port 26380 #哨兵端口
sentinel monitor master1 10.1.4.99 6379 2 # 监听IP 端口 默认最少投票数量
sentinel down-after-milliseconds master1 5000
sentinel failover-timeout master1 5000 #选举超时时间
logfile "/data/redis/sentinel/sentinel_26379.log" #日志文件
sentinel auth-pass master1 Redis2017 #redis密码
启动哨兵服务的两种方式
1、redis-sentinel /path/to/sentinel.conf
2、redis-server /path/to/sentinel.conf --sentinel
启动10.1.4.99的哨兵服务
redis-sentinel /etc/redis/sentinel_26380.conf
redis-sentinel /etc/redis/sentinel_26379.conf
检查26379端口相关日志
[root@bundcredit sentinel]# tail -f sentinel_26379.log
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
27098:X 13 Aug 21:51:25.242 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
27098:X 13 Aug 21:51:25.242 # Sentinel ID is 361c7d3014a041a1a74163355882d88f5fab7581
27098:X 13 Aug 21:51:25.242 # +monitor master master1 10.1.4.99 6379 quorum 2
27098:X 13 Aug 21:51:30.271 # +sdown sentinel 76d5a26748410e72ca703e255f44a5ed2b3f83e4 10.1.4.99 26380 @ master1 10.1.4.99 6379
27098:X 13 Aug 21:51:30.410 # -sdown sentinel 76d5a26748410e72ca703e255f44a5ed2b3f83e4 10.1.4.99 26380 @ master1 10.1.4.99 6379
27098:X 13 Aug 21:52:30.617 # +sdown sentinel 5c3033c0ea6d1e0d861e9d9e99e94edb49c5daac 10.1.4.82 26379 @ master1 10.1.4.99 6379
27098:X 13 Aug 21:53:23.855 # -sdown sentinel 5c3033c0ea6d1e0d861e9d9e99e94edb49c5daac 10.1.4.82 26379 @ master1 10.1.4.99 6379
27098:X 13 Aug 21:53:34.463 # +sdown master master1 10.1.4.99 6379
27098:X 13 Aug 21:53:34.532 # +odown master master1 10.1.4.99 6379 #quorum 2/2
27098:X 13 Aug 21:53:34.532 # +new-epoch 1
27098:X 13 Aug 21:53:34.532 # +try-failover master master1 10.1.4.99 6379
27098:X 13 Aug 21:53:34.541 # +vote-for-leader 361c7d3014a041a1a74163355882d88f5fab7581 1
27098:X 13 Aug 21:53:34.542 # b73258f1019f65c5fee3b88b9c2eae7f85d985f3 voted for b73258f1019f65c5fee3b88b9c2eae7f85d985f3 1
27098:X 13 Aug 21:53:34.559 # 5c3033c0ea6d1e0d861e9d9e99e94edb49c5daac voted for b73258f1019f65c5fee3b88b9c2eae7f85d985f3 1
27098:X 13 Aug 21:53:34.560 # 76d5a26748410e72ca703e255f44a5ed2b3f83e4 voted for b73258f1019f65c5fee3b88b9c2eae7f85d985f3 1
27098:X 13 Aug 21:53:35.156 # +config-update-from sentinel b73258f1019f65c5fee3b88b9c2eae7f85d985f3 10.1.4.82 26380 @ master1 10.1.4.99 6379
27098:X 13 Aug 21:53:35.156 # +switch-master master1 10.1.4.99 6379 10.1.4.82 6379
27098:X 13 Aug 21:53:35.156 * +slave slave 10.1.4.99:6379 10.1.4.99 6379 @ master1 10.1.4.82 6379
27098:X 13 Aug 21:53:40.173 # +sdown slave 10.1.4.99:6379 10.1.4.99 6379 @ master1 10.1.4.82 6379
27098:X 13 Aug 21:54:07.583 # -sdown slave 10.1.4.99:6379 10.1.4.99 6379 @ master1 10.1.4.82 6379