redis 集群如何手动切换主从

版权声明:本文为博主原创文章,欢迎转载,转载请标明出处。 https://blog.csdn.net/qq_32523587/article/details/66968732

之前的结构是这样的:

主:192.168.10.13:30001  从: 192.168.10.14:30004

主:192.168.10.14:30003  从: 192.168.10.15:30006

主:192.168.10.15:30005  从: 192.168.10.13:30002


即,每台服务器既是一个分片的主,又是另一个分片的从,如此一来可以实现高可用。配置了sentinel(哨兵)以后,可以实现自动故障转移了。


现在我关闭了13这台服务器,sentinel探测结果如下:

19786:X 27 Mar 10:12:17.154 # +sdown master zhuyun3 192.168.10.13 30001
19786:X 27 Mar 10:12:17.220 # +odown master zhuyun3 192.168.10.13 30001 #quorum 2/2
19786:X 27 Mar 10:12:17.220 # +new-epoch 1
19786:X 27 Mar 10:12:17.220 # +try-failover master zhuyun3 192.168.10.13 30001
19786:X 27 Mar 10:12:17.277 # +vote-for-leader 7ab18d8c3a3bb85b7ba52e31e79b51a0a8570fa4 1
19786:X 27 Mar 10:12:17.284 # 5b5a466048a5c12c1de40e1e5de93482faa89f63 voted for 5b5a466048a5c12c1de40e1e5de93482faa89f63 1
19786:X 27 Mar 10:12:17.371 # 08eb3d779e7160d1ea54774dab59a6ad20eeaad2 voted for 7ab18d8c3a3bb85b7ba52e31e79b51a0a8570fa4 1
19786:X 27 Mar 10:12:17.431 # +elected-leader master zhuyun3 192.168.10.13 30001
19786:X 27 Mar 10:12:17.431 # +failover-state-select-slave master zhuyun3 192.168.10.13 30001
19786:X 27 Mar 10:12:17.521 # +selected-slave slave 192.168.10.15:30006 192.168.10.15 30006 @ zhuyun3 192.168.10.13 30001
19786:X 27 Mar 10:12:17.521 * +failover-state-send-slaveof-noone slave 192.168.10.15:30006 192.168.10.15 30006 @ zhuyun3 192.168.10.13 30001
19786:X 27 Mar 10:12:17.597 * +failover-state-wait-promotion slave 192.168.10.15:30006 192.168.10.15 30006 @ zhuyun3 192.168.10.13 30001
19786:X 27 Mar 10:12:18.443 # +promoted-slave slave 192.168.10.15:30006 192.168.10.15 30006 @ zhuyun3 192.168.10.13 30001
19786:X 27 Mar 10:12:18.443 # +failover-state-reconf-slaves master zhuyun3 192.168.10.13 30001
19786:X 27 Mar 10:12:18.453 # +failover-end master zhuyun3 192.168.10.13 30001
19786:X 27 Mar 10:12:18.453 # +switch-master zhuyun3 192.168.10.13 30001 192.168.10.15 30006


检测到13挂掉以后,该分片的主自动转移到了15服务器上,在15上用CLUSTER NODES显示结果如下:

cd9890519295f9d14b26e4335a3d720a7c73b70a 192.168.10.15:30005 master - 0 1490580783613 3 connected 10923-16383
4110f5d0a0e602e1fcac12d258bc9973653f9903 192.168.10.13:30002 slave,fail 66c08446d97616757f8ff481007fb68d06a01bc8 1490580720262 1490580718358 4 disconnected
66c08446d97616757f8ff481007fb68d06a01bc8 192.168.10.14:30003 myself,master - 0 0 2 connected 5461-10922
57763c3779240b13cb3ac0c0ac3907851dc942d2 192.168.10.14:30004 slave cd9890519295f9d14b26e4335a3d720a7c73b70a 0 1490580784620 5 connected
7457a755b443ddad613fc593d6b68482388cbece 192.168.10.15:30006 master - 0 1490580785626 6 connected 0-5460
1607487c467862b22ede849ff4abc28dbe2c601c 192.168.10.13:30001 master,fail - 1490580707118 1490580704311 1 disconnected

结果显示,13的主和从都是fail状态,现在15上有两个主


现在,我在将13的主和从启动,结果显示如下:

cd9890519295f9d14b26e4335a3d720a7c73b70a 192.168.10.15:30005 master - 0 1490580924089 3 connected 10923-16383
4110f5d0a0e602e1fcac12d258bc9973653f9903 192.168.10.13:30002 slave 66c08446d97616757f8ff481007fb68d06a01bc8 0 1490580925092 4 connected
66c08446d97616757f8ff481007fb68d06a01bc8 192.168.10.14:30003 myself,master - 0 0 2 connected 5461-10922
57763c3779240b13cb3ac0c0ac3907851dc942d2 192.168.10.14:30004 slave cd9890519295f9d14b26e4335a3d720a7c73b70a 0 1490580921078 5 connected
7457a755b443ddad613fc593d6b68482388cbece 192.168.10.15:30006 master - 0 1490580920075 6 connected 0-5460
1607487c467862b22ede849ff4abc28dbe2c601c 192.168.10.13:30001 slave 7457a755b443ddad613fc593d6b68482388cbece 0 1490580922081 6 connected


现在的问题就来了,15服务器上面始终有两个主,而13上面始终是两个从,如此一来,假如15服务器挂掉了,那数据库有2/3的数据就无法访问了。目前需要做的事情,就是如何将15的其中一个主转移到13上面来,具体如何实现还在探索中。

展开阅读全文

没有更多推荐了,返回首页