redis群集哨兵模式

主从配置参照之前的文章

http://www.wangfan.xyz/archives/96

redis主从配置

还是那三台centos,ip:10.211.55.14;    10.211.55.16;   10.211.55.17

修改sentinel.conf文件

daemonize yes   #后台模式运行

port 26379   #端口号默认

logfile “/home/parallels/program/redis-6.0.8/redis.log” #日志文件

 

#sentinel monitor <master-name> <ip> <redis-port> <quorum>

sentinel monitor mymaster 10.211.55.14 6379 2

#Master-name自己定义名字   ip master的IP地址,端口号,

#quorum是一个数字,表示有多少个哨兵认为master失效了。master才算真的失效。

sentinel auth-pass mymaster 1234   #密码

 

 

依次启动redis-server redis.conf   启动redis服务

在依次启动 redis-servier sentinel.conf  –sentinel 启动哨兵服务

这里我们的master是14,slaves是16,17

我们把master断开服务

会发现17被选举为master了,同过info,可以看到

role:master

connected_slaves:1

slave0:ip=10.211.55.16,port=6379,state=online,offset=26750,lag=1

master_replid:1bb5eb10fe019e891fa231a18a90058b20031061

master_replid2:1447aa565b3a56fb40aa73d2f15f96c531aa3e47

master_repl_offset:26889

second_repl_offset:17887

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:29

repl_backlog_histlen:26861

 

查看哨兵日志,可以看到

27616:X 22 Sep 2020 17:56:18.207 # +failover-state-reconf-slaves master mymaster 10.211.55.14 6379

27616:X 22 Sep 2020 17:56:18.266 * +slave-reconf-sent slave 10.211.55.16:6379 10.211.55.16 6379 @ mymaster 10.211.55.14 6379

27616:X 22 Sep 2020 17:56:19.118 # -odown master mymaster 10.211.55.14 6379

27616:X 22 Sep 2020 17:56:19.247 * +slave-reconf-inprog slave 10.211.55.16:6379 10.211.55.16 6379 @ mymaster 10.211.55.14 6379

27616:X 22 Sep 2020 17:56:19.247 * +slave-reconf-done slave 10.211.55.16:6379 10.211.55.16 6379 @ mymaster 10.211.55.14 6379

27616:X 22 Sep 2020 17:56:19.318 # +failover-end master mymaster 10.211.55.14 6379

27616:X 22 Sep 2020 17:56:19.318 # +switch-master mymaster 10.211.55.14 6379 10.211.55.17 6379

27616:X 22 Sep 2020 17:56:19.318 * +slave slave 10.211.55.16:6379 10.211.55.16 6379 @ mymaster 10.211.55.17 6379

27616:X 22 Sep 2020 17:56:19.318 * +slave slave 10.211.55.14:6379 10.211.55.14 6379 @ mymaster 10.211.55.17 6379

27616:X 22 Sep 2020 17:56:49.369 # +sdown slave 10.211.55.14:6379 10.211.55.14 6379 @ mymaster 10.211.55.17 6379

 

这里停止了14的master,选举17位master,有一个slaves 16

16的服务器上我们查看哨兵日志也可以看到

22738:X 22 Sep 2020 17:54:20.151 # +monitor master mymaster 10.211.55.14 6379 quorum 2

22738:X 22 Sep 2020 17:54:20.152 * +slave slave 10.211.55.16:6379 10.211.55.16 6379 @ mymaster 10.211.55.14 6379

22738:X 22 Sep 2020 17:54:20.153 * +slave slave 10.211.55.17:6379 10.211.55.17 6379 @ mymaster 10.211.55.14 6379

22738:X 22 Sep 2020 17:54:28.893 * +sentinel sentinel 808c3f67715ce88d5ac913d2a9243425aab932c2 10.211.55.17 26379 @ mymaster 10.211.55.14 6379

22738:X 22 Sep 2020 17:56:16.926 # +sdown master mymaster 10.211.55.14 6379

22738:X 22 Sep 2020 17:56:17.017 # +odown master mymaster 10.211.55.14 6379 #quorum 2/2

22738:X 22 Sep 2020 17:56:17.017 # +new-epoch 2

22738:X 22 Sep 2020 17:56:17.017 # +try-failover master mymaster 10.211.55.14 6379

22738:X 22 Sep 2020 17:56:17.983 # +new-epoch 3

22738:X 22 Sep 2020 17:56:17.984 # +vote-for-leader 808c3f67715ce88d5ac913d2a9243425aab932c2 3

22738:X 22 Sep 2020 17:56:18.043 # 808c3f67715ce88d5ac913d2a9243425aab932c2 voted for 808c3f67715ce88d5ac913d2a9243425aab932c2 3

22738:X 22 Sep 2020 17:56:18.268 # +config-update-from sentinel 808c3f67715ce88d5ac913d2a9243425aab932c2 10.211.55.17 26379 @ mymaster 10.211.55.14 6379

22738:X 22 Sep 2020 17:56:18.268 # +switch-master mymaster 10.211.55.14 6379 10.211.55.17 6379

22738:X 22 Sep 2020 17:56:18.268 * +slave slave 10.211.55.16:6379 10.211.55.16 6379 @ mymaster 10.211.55.17 6379

22738:X 22 Sep 2020 17:56:18.268 * +slave slave 10.211.55.14:6379 10.211.55.14 6379 @ mymaster 10.211.55.17 6379

[parallels@10 redis-6.0.8]$ redis-cli 

 

选举master为17

 

我们重新启动14,发现14自动变成slave了

在通过info查看17,会发现

# Replication

role:master

connected_slaves:2

slave0:ip=10.211.55.16,port=6379,state=online,offset=607473,lag=1

slave1:ip=10.211.55.14,port=6379,state=online,offset=607473,lag=1

master_replid:1bb5eb10fe019e891fa231a18a90058b20031061

master_replid2:1447aa565b3a56fb40aa73d2f15f96c531aa3e47

master_repl_offset:607751

second_repl_offset:17887

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:29

repl_backlog_histlen:607723

 

17显示有两个slaves了

发表评论

电子邮件地址不会被公开。