Redis哨兵机制

 1. 指定主Redis节点IP以及端口

sentinel monitor mymaster 192.168.75.130 8001 1

2. 设置多长时间无法访问,将其置为宕机状态  单位 : 毫秒

sentinel down-after-milliseconds mymaster 5000

3.  从节点的数量

sentinel parallel-syncs mymaster 2

4. 启动哨兵机制 

 redis-server sentinel.conf --sentine

 5. 模拟主Redis宕机

root@ubuntu:/usr/local/redis-master-slave# ps -aux | grep redis
root       2500  0.0  0.2  69000  4680 ?        Ssl  23:06   0:01 redis-server 192.168.75.130:8001
root       2505  0.0  0.2  71048  5032 ?        Ssl  23:06   0:01 redis-server 192.168.75.130:8002
root       2511  0.0  0.2  71048  4688 ?        Ssl  23:06   0:01 redis-server 192.168.75.130:8003
root       2520  0.0  0.1  25792  2992 pts/0    S+   23:07   0:00 redis-cli -h 192.168.75.130 -p 8001
root       2552  0.0  0.1  25792  2980 pts/2    S+   23:08   0:00 redis-cli -h 192.168.75.130 -p 8002
root       2693  0.1  0.2  61320  5096 pts/3    Sl+  23:38   0:00 redis-server *:26379 [sentinel]
root       2736  0.0  0.0  21532  1056 pts/1    S+   23:44   0:00 grep --color=auto redis
root@ubuntu:/usr/local/redis-master-slave# kill 2500

6.  哨兵输出master节点转换

 mymaster 192.168.75.130 8001
2693:X 24 Sep 2019 23:44:58.559 # +failover-end master mymaster 192.168.75.130 8001
2693:X 24 Sep 2019 23:44:58.559 # +switch-master mymaster 192.168.75.130 8001 192.168.75.130 8003
2693:X 24 Sep 2019 23:44:58.559 * +slave slave 192.168.75.130:8002 192.168.75.130 8002 @ mymaster 192.168.75.130 8003

7. 查看8003节点是否成为新的master

Redis哨兵机制_第1张图片

 

 8. 重启Redis 8001

root@ubuntu:/home/song# redis-server /usr/local/redis-master-slave/8001/redis.conf 

 查看8001节点信息: info 

 Redis哨兵机制_第2张图片

 8003 节点新增一个slave从节点【小弟】 

2693:X 24 Sep 2019 23:55:15.631 * +convert-to-slave slave 192.168.75.130:8001 192.168.75.130 8001 @ mymaster 192.168.75.130 8003

 

 

你可能感兴趣的:(Redis)