1. Sentinel工具完成监控--操作步骤
(1)把redis解压包中的sentinel.conf拷贝到redis的安装目录下:
[root@192 redis]# cp /opt/redis-4.0.11/sentinel.conf ./
(2)修改配置文件sentinel.conf,修改内容如下:
[root@192 redis]# vi sentinel.conf
#sentinel monitor mymaster 127.0.0.1 6379 2
sentinel monitor mymaster 127.0.0.1 6379 1
sentinel down-after-milliseconds mymaster 30000
(3)启动redis服务
[root@192 redis]# ./bin/redis-server ./redis.conf
[root@192 redis]# ./bin/redis-server ./redis6380.conf
[root@192 redis]# ./bin/redis-server ./redis6381.conf
(4)启动sentinel监控:
[root@192 redis]# ./bin/redis-server ./sentinel.conf --sentinel
(5)把master宕掉:
127.0.0.1:6379> shutdown
(6)查看sentinel监控的变化
(7)查看从服务器的变化
127.0.0.1:6380> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=127.0.0.1,port=6381,state=online,offset=38168,lag=0
127.0.0.1:6381> info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6380
master_link_status:up