使用Sentinel机制实现Redis高可用主从复制(4)

6640:X 23 Jan 00:39:07.305 # +sdown master mymaster 192.168.1.11 6379
6640:X 23 Jan 00:39:07.305 # +odown master mymaster 192.168.1.11 6379 #quorum 1/1
6640:X 23 Jan 00:39:07.305 # +new-epoch 1
6640:X 23 Jan 00:39:07.305 # +try-failover master mymaster 192.168.1.11 6379
6640:X 23 Jan 00:39:07.308 # +vote-for-leader 17c9ee07632d60c4c0aa75a853bbda93966caa22 1
6640:X 23 Jan 00:39:17.380 # -failover-abort-not-elected master mymaster 192.168.1.11 6379
6640:X 23 Jan 00:39:17.438 # Next failover delay: I will not start a failover before Mon Jan 23 00:41:07 2017
6640:X 23 Jan 00:41:07.432 # +new-epoch 2
6640:X 23 Jan 00:41:07.432 # +try-failover master mymaster 192.168.1.11 6379
6640:X 23 Jan 00:41:07.434 # +vote-for-leader 17c9ee07632d60c4c0aa75a853bbda93966caa22 2
6640:X 23 Jan 00:41:17.505 # -failover-abort-not-elected master mymaster 192.168.1.11 6379
6640:X 23 Jan 00:41:17.592 # Next failover delay: I will not start a failover before Mon Jan 23 00:43:07 2017

一直尝试恢复master失败,投票只有1票,重新选举出新主服数量不够

[root@station11 ~]#tail -f sentinel_master.log

6732:X 23 Jan 01:24:18.921 # +new-epoch 18
6732:X 23 Jan 01:24:18.933 # +vote-for-leader a78518e4955d3602c61e212be0cbdc378daa3cdc 18
6732:X 23 Jan 01:24:18.946 # +sdown master mymaster 192.168.1.11 6379
6732:X 23 Jan 01:24:18.946 # +odown master mymaster 192.168.1.11 6379 #quorum 1/1
6732:X 23 Jan 01:24:18.946 # Next failover delay: I will not start a failover before Mon Jan 23 01:26:19 2017
6732:X 23 Jan 01:24:19.240 # +config-update-from sentinel a78518e4955d3602c61e212be0cbdc378daa3cdc 192.168.1.13 26579 @ mymaster 192.168.1.11 6379
6732:X 23 Jan 01:24:19.240 # +switch-master mymaster 192.168.1.11 6379 192.168.1.12 6379  切换master从11到12
6732:X 23 Jan 01:24:19.241 * +slave slave 192.168.1.13:6379 192.168.1.13 6379 @ mymaster 192.168.1.12 6379
6732:X 23 Jan 01:24:19.241 * +slave slave 192.168.1.11:6379 192.168.1.11 6379 @ mymaster 192.168.1.12 6379
6732:X 23 Jan 01:24:24.258 # +sdown slave 192.168.1.11:6379 192.168.1.11 6379 @ mymaster 192.168.1.12 6379

[root@station11 ~]#tail -f /var/log/redis_slave1.log  #slave1启动master模式

7846:M 23 Jan 01:24:18.857 * MASTER MODE enabled (user request from 'id=7 addr=192.168.1.13:44615 fd=10 name=sentinel-a78518e4-cmd age=183 idle=0 flags=x db=0 sub=0 psub=0 multi=3 qbuf=0 qbuf-free=32768 obl=36 oll=0 omem=0 events=r cmd=exec')
7846:M 23 Jan 01:24:18.858 # CONFIG REWRITE executed with success.
7846:M 23 Jan 01:24:19.060 * Slave 192.168.1.13:6379 asks for synchronization
7846:M 23 Jan 01:24:19.061 * Full resync requested by slave 192.168.1.13:6379
7846:M 23 Jan 01:24:19.061 * Starting BGSAVE for SYNC with target: disk
7846:M 23 Jan 01:24:19.061 * Background saving started by pid 7852
7852:C 23 Jan 01:24:19.091 * DB saved on disk
7852:C 23 Jan 01:24:19.091 * RDB: 8 MB of memory used by copy-on-write
7846:M 23 Jan 01:24:19.178 * Background saving terminated with success
7846:M 23 Jan 01:24:19.178 * Synchronization with slave 192.168.1.13:6379 succeeded

[root@station12 ~]# redis-cli -h 192.168.1.12 -p 6379

192.168.1.12:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.1.13,port=6379,state=online,offset=65036,lag=0
master_repl_offset:65036
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:65035

[root@station12 ~]# redis-cli -h 192.168.1.12 -p 26479

192.168.1.12:26479> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=192.168.1.12:6379,slaves=2,sentinels=3
192.168.1.12:26479> sentinel masters
1)  1) "name"
    2) "mymaster"
    3) "ip"
    4) "192.168.1.12"
    5) "port"
    6) "6379"
    7) "runid"
    8) "0a4b1b8c6b3595dde9446697a025fca0f0530ac7"
    9) "flags"
  10) "master"
 ........................................................
  31) "num-slaves"
  32) "2"
  33) "num-other-sentinels"
  34) "2"
  35) "quorum"
  36) "1"
  37) "failover-timeout"
  38) "60000"
  39) "parallel-syncs"
  40) "1"
192.168.1.12:26479> sentinel slaves mymaster
1)  1) "name"
    2) "192.168.1.13:6379"
    3) "ip"
    4) "192.168.1.13"
    5) "port"
    6) "6379"
    7) "runid"
    8) "eb29d1741121071accc633db186f63b81fc33ffc"
    9) "flags"
  10) "slave"
 ........................................................
  29) "master-link-down-time"
  30) "0"
  31) "master-link-status"
  32) "ok"
  33) "master-host"
  34) "192.168.1.12"
  35) "master-port"
  36) "6379"
  37) "slave-priority"
  38) "97"
  39) "slave-repl-offset"
  40) "112029"
2)  1) "name"
    2) "192.168.1.11:6379"
    3) "ip"
    4) "192.168.1.11"
    5) "port"
    6) "6379"
    7) "runid"
    8) ""
    9) "flags"
  10) "s_down,slave,disconnected"
 ..............................................
  27) "role-reported"
  28) "slave"
  29) "role-reported-time"
  30) "546434"
  31) "master-link-down-time"
  32) "0"
  33) "master-link-status"
  34) "err"
  35) "master-host"
  36) "?"
  37) "master-port"
  38) "0"
  39) "slave-priority"
  40) "100"
  41) "slave-repl-offset"
  42) "0"

假如此时192.168.1.11这台服务器的redis-server恢复了,也会被加入slave队列中

[root@station11 ~]# nohup redis-server /etc/redis/redis.conf&

[root@station11 ~]# tail -f sentinel_master.log

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/8bb540c36180276257f85fb9f486a5ab.html