【Redis学习笔记】-- 集群中动态增加和移除节点

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/YYZZHC999/article/details/83474899

集群中添加节点

接着上篇文章集群中节点选举我们继续测试验证……
首先我们先再来一个redis节点,复制一个redis01吧,改下配置文件的端口,这里改为了7007。(注意复制的时候删掉aof,.rdb和以及nodes.conf文件,这些文件记录了当前redis节点的缓存以及所在集群的信息,若不删除加入新集群时会不可避免的出错)

[root@localhost redis-cluster]# cp -r  redis01 redis07  
[root@localhost redis-cluster]# cd redis07/  

启动7007redis服务

[root@localhost redis07]# ./redis-server redis.conf 

7007加进集群,7007是需要加入集群的新节点,后面的7002是集群中的任意端口,只是为了标识所要加入的集群。

[root@localhost redis-cluster]# ./redis-trib.rb add-node 127.0.0.1:7007 127.0.0.1:7002
>>> Adding node 127.0.0.1:7007 to cluster 127.0.0.1:7002
>>> Performing Cluster Check (using node 127.0.0.1:7002)
S: 1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002
   slots: (0 slots) slave
   replicates a5db243087d8bd423b9285fa8513eddee9bb59a6
M: f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
M: a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7001
   slots: (0 slots) slave
   replicates dd19221c404fb2fc4da37229de56bab755c76f2b
S: 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006
   slots: (0 slots) slave
   replicates f9886c71e98a53270f7fda961e1c5f730382d48f
M: dd19221c404fb2fc4da37229de56bab755c76f2b 127.0.0.1:7004
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 127.0.0.1:7007 to make it join the cluster.
[OK] New node added correctly.

可以看到7007加入这个Cluster,并成为一个新的节点。
可以check以下7007节点状态

[root@localhost redis-cluster]# ./redis-trib.rb check 127.0.0.1:7007
>>> Performing Cluster Check (using node 127.0.0.1:7007)
M: ee3efb90e5ac0725f15238a64fc60a18a71205d7 127.0.0.1:7007
   slots: (0 slots) master
   0 additional replica(s)
S: 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006
   slots: (0 slots) slave
   replicates f9886c71e98a53270f7fda961e1c5f730382d48f
M: dd19221c404fb2fc4da37229de56bab755c76f2b 127.0.0.1:7004
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002
   slots: (0 slots) slave
   replicates a5db243087d8bd423b9285fa8513eddee9bb59a6
M: a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7001
   slots: (0 slots) slave
   replicates dd19221c404fb2fc4da37229de56bab755c76f2b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

由check后的信息可知,现在有4个主节点,3个从节点,新加入的7007端口的主节点没有从节点,也没有分配任何哈希槽(0 slots)。

用reids07连接一下集群,查看当前节点状态,可知当前各个节点哈希槽分配的状态。

[root@localhost redis-cluster]# cd redis07/
[root@localhost redis07]# ./redis-cli -c -p 7007
127.0.0.1:7007> cluster nodes
8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006 slave f9886c71e98a53270f7fda961e1c5f730382d48f 0 1462955393326 3 connected
dd19221c404fb2fc4da37229de56bab755c76f2b 127.0.0.1:7004 master - 0 1462955388247 1 connected 0-5460
ee3efb90e5ac0725f15238a64fc60a18a71205d7 127.0.0.1:7007 myself,master - 0 0 0 connected
f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003 master - 0 1462955390270 3 connected 10923-16383
1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002 slave a5db243087d8bd423b9285fa8513eddee9bb59a6 0 1462955394334 7 connected
a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005 master - 0 1462955392309 7 connected 5461-10922
50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7001 slave dd19221c404fb2fc4da37229de56bab755c76f2b 0 1462955389663 1 connected
127.0.0.1:7007>

redis-cluster在新增节点时并未分配卡槽,需要我们手动对集群进行重新分片迁移数据,需要重新分片命令 reshard, redis-trib.rb reshard 127.0.0.1:7005
这个命令是用来迁移slot节点的,后面的127.0.0.1:7005是表示是哪个集群,端口填[7000-7007]都可以,执行结果如下

[root@localhost redis-cluster]# ./redis-trib.rb reshard 127.0.0.1:7005
>>> Performing Cluster Check (using node 127.0.0.1:7005)
M: a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7004
   slots: (0 slots) slave
   replicates dd19221c404fb2fc4da37229de56bab755c76f2b
M: f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002
   slots: (0 slots) slave
   replicates a5db243087d8bd423b9285fa8513eddee9bb59a6
M: ee3efb90e5ac0725f15238a64fc60a18a71205d7 127.0.0.1:7007
   slots: (0 slots) master
   0 additional replica(s)
M: dd19221c404fb2fc4da37229de56bab755c76f2b 127.0.0.1:7001
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006
   slots: (0 slots) slave
   replicates f9886c71e98a53270f7fda961e1c5f730382d48f
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

How many slots do you want to move (from 1 to 16384)? 4096
What is the receiving node ID?

这里可以把上面查看节点状态的7007节点id粘过来输入。

Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
Source node #1: all

这时redis-trib会询问你重新分片的源节点(source node)的分配方式: 第一种all指的是从全部节点中提取4096个哈希槽分配给7007节点,第二种done是指从特定节点上取特定数量的哈希槽分配到7007节点上,这里我选择了all方式,集群中所有的主节点都会成为源节点,redis-trib从7004,7002,7003,三个主节点上各取一部分哈希槽,共4096个移动到7007节点上,这样四个主节点共计4096*4=16384个哈希槽,依然是均等的。

Do you want to proceed with the proposed reshard plan (yes/no)? yes

确认之后会有一波漫长的刷屏操作,将哈希槽一个一个的移动到7007目标节点。
分片之后我们可以check各个节点的哈希槽状态。

[root@localhost redis-cluster]# ./redis-trib.rb check 127.0.0.1:7004
>>> Performing Cluster Check (using node 127.0.0.1:7004)
M: dd19221c404fb2fc4da37229de56bab755c76f2b 127.0.0.1:7004
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: ee3efb90e5ac0725f15238a64fc60a18a71205d7 127.0.0.1:7007
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   0 additional replica(s)
M: a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006
   slots: (0 slots) slave
   replicates f9886c71e98a53270f7fda961e1c5f730382d48f
M: f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003
   slots:12288-16383 (4096 slots) master
   1 additional replica(s)
S: 1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002
   slots: (0 slots) slave
   replicates a5db243087d8bd423b9285fa8513eddee9bb59a6
S: 50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7001
   slots: (0 slots) slave
   replicates dd19221c404fb2fc4da37229de56bab755c76f2b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[root@localhost redis-cluster]#

我们把重点放在这里:

M: ee3efb90e5ac0725f15238a64fc60a18a71205d7 127.0.0.1:7007
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   0 additional replica(s)

可以看出7007上的哈希槽并不是连续的而是分了三段,这三段分别是从7004,7002,7003,上间隔的移动过来的。

新增从节点:

这里我们给7007主节点新增一个从节点,可以使用add-node –slave命令。
复制一份redis节点,记得删除缓存文件,上面说过了哪些文件这里注意一下,更改端口,启服务。

[root@localhost redis-cluster] cp -r redis01/ redis08
[root@localhost redis-cluster] cd redis08/
[root@localhost redis08]sed -i "s/7001/7008/g" ./redis.conf
[root@localhost redis08]./redis-server redis.conf

redis-trib增加从节点的命令为:

./redis-trib.rb add-node --slave --master-id $[nodeid] 127.0.0.1:7008 127.0.0.1:7001

Nodeid是要加到master主节点的masterid,也就是我们的7007节点的id,后面的7008是待加入的从节点,7001是集群中的任意节点,标识所在集群。 也可以不指定nodeid, redis-trib会自动将待加入的从节点分配到从节点较少的主节点上。

这里我们的集群中只有7007主节点没有从节点,所以我们可以测试默认情况下会不会分到7007上:

[root@localhost redis-cluster]# ./redis-trib.rb add-node --slave 127.0.0.1:7008 127.0.0.1:7001
>>> Adding node 127.0.0.1:7008 to cluster 127.0.0.1:7001
Connecting to node 127.0.0.1:7001: OK
>>> Performing Cluster Check (using node 127.0.0.1:7001)
M: dabf91df0a01e87c514216bc5c7e810ca3f3b169 127.0.0.1:7001
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: fec78e5b09b378b876088d27311780ee77df5149 192.168.178.12:7007
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   0 additional replica(s)
S: 2d0ad242a0371981c0499b8cd56d666783dc3339 192.168.178.12:7004
   slots: (0 slots) slave
   replicates dabf91df0a01e87c514216bc5c7e810ca3f3b169
S: 4af5a32724d226e988c6f255cadfd99edc9070a7 192.168.178.12:7006
   slots: (0 slots) slave
   replicates e19e54c3373ac25267617f623eafb332e9008fee
M: e19e54c3373ac25267617f623eafb332e9008fee 192.168.178.12:7003
   slots:12288-16383 (4096 slots) master
   1 additional replica(s)
M: 7eacea6776c380422a4535da657c9996804513aa 192.168.178.12:7002
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: 74b0b1fc4ae9d1063380c4d841cc9fda2eb8ef52 192.168.178.12:7005
   slots: (0 slots) slave
   replicates 7eacea6776c380422a4535da657c9996804513aa
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Automatically selected master 192.168.178.12:7007
Connecting to node 127.0.0.1:7008: OK
>>> Send CLUSTER MEET to node 127.0.0.1:7008 to make it join the cluster.
Waiting for the cluster to join.
>>> Configure node as replica of 192.168.178.12:7007.
[OK] New node added correctly.

重点看在这里:

Automatically selected master 192.168.178.12:7007
Connecting to node 127.0.0.1:7008: OK
>>> Send CLUSTER MEET to node 127.0.0.1:7008 to make it join the cluster.
Waiting for the cluster to join.
>>> Configure node as replica of 192.168.178.12:7007.
[OK] New node added correctly.

可以看到7008自动选择了7007为master主节点,并且添加成功。可以check一下7008查看详情。这里不贴详情结果了。

集群中移除节点

移除节点的命令:前面的127.0.0.1:7003是集群的任意节点,标识所在集群,这里后面的node-id是必不可少的,nodeid标识的才是真正要移除的节点,可以用cluster nodes。

redis-trib del-node 127.0.0.1:7003  ${node-id}

这里测试删除7002节点,后面跟的是7003节点的id。

[root@localhost redis-cluster]# ./redis-trib.rb del-node 127.0.0.1:7003 7eacea6776c380422a4535da657c9996804513aa
>>> Removing node 7eacea6776c380422a4535da657c9996804513aa from cluster 127.0.0.1:7002
Connecting to node 127.0.0.1:7002: OK
Connecting to node 192.168.178.12:7008: OK
Connecting to node 192.168.178.12:7007: OK
Connecting to node 192.168.178.12:7001: OK
Connecting to node 192.168.178.12:7004: OK
Connecting to node 192.168.178.12:7003: OK
Connecting to node 192.168.178.12:7005: OK
Connecting to node 192.168.178.12:7006: OK
[ERR] Node 127.0.0.1:7002 is not empty! Reshard data away and try again.

提示这个错误的原因是我们要删除的节点目前是有数据的,所以不能直接删除,后面给的建议是将她的数据转移出去,再重试。也就是我们在移动集群的某一节点时候需要重新分配哈希槽,将要删除节点的哈希槽分配到其他节点上去。

这里测试把7002节点的数据移至7001节点,然后再删除7002节点。

[root@localhost redis-cluster]# ./redis-trib.rb reshard 127.0.0.1:7001
Connecting to node 127.0.0.1:7001: OK
Connecting to node 192.168.178.12:7007: OK
Connecting to node 127.0.0.1:7008: OK
Connecting to node 192.168.178.12:7004: OK
Connecting to node 192.168.178.12:7006: OK
Connecting to node 192.168.178.12:7003: OK
Connecting to node 192.168.178.12:7002: OK
Connecting to node 192.168.178.12:7005: OK
>>> Performing Cluster Check (using node 127.0.0.1:7001)
M: dabf91df0a01e87c514216bc5c7e810ca3f3b169 127.0.0.1:7001
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: fec78e5b09b378b876088d27311780ee77df5149 192.168.178.12:7007
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   1 additional replica(s)
S: 02cba50c405b02120e139b07b8968691e5803661 127.0.0.1:7008
   slots: (0 slots) slave
   replicates fec78e5b09b378b876088d27311780ee77df5149
S: 2d0ad242a0371981c0499b8cd56d666783dc3339 192.168.178.12:7004
   slots: (0 slots) slave
   replicates dabf91df0a01e87c514216bc5c7e810ca3f3b169
S: 4af5a32724d226e988c6f255cadfd99edc9070a7 192.168.178.12:7006
   slots: (0 slots) slave
   replicates e19e54c3373ac25267617f623eafb332e9008fee
M: e19e54c3373ac25267617f623eafb332e9008fee 192.168.178.12:7003
   slots:12288-16383 (4096 slots) master
   1 additional replica(s)
M: 7eacea6776c380422a4535da657c9996804513aa 192.168.178.12:7002
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: 74b0b1fc4ae9d1063380c4d841cc9fda2eb8ef52 192.168.178.12:7005
   slots: (0 slots) slave
   replicates 7eacea6776c380422a4535da657c9996804513aa
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 4096

输入4096 因为7004上原分配了4096个哈希槽,这里提示输入移动到目标节点的ID,这块我们测试移动到7007节点上。

What is the receiving node ID? dabf91df0a01e87c514216bc5c7e810ca3f3b169

后面输入的是7001节点ID (receiving是接收的意思,也就是目标节点):,因为我们之前测试过了all方式分配哈希槽,这次我们测试另一种方式给指定节点分配哈希槽。

Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
Source node #1:

输入要移动的7002节点id(要移动的源节点),

Source node #1: 7eacea6776c380422a4535da657c9996804513aa  //要移动的源节点7002的id
Source node #2:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes 

之后就又是一波move操作。。。

查看一下目标节点7001的哈希槽有没有变多。

[root@localhost redis-cluster]# ./redis-trib.rb check 127.0.0.1:7002
Connecting to node 127.0.0.1:7002: OK
>>> Performing Cluster Check (using node 127.0.0.1:7002)
M: 7eacea6776c380422a4535da657c9996804513aa 127.0.0.1:7002
   slots: (0 slots) master                                     //7002主节点暂无哈希槽
   1 additional replica(s)                                     //7002主节点有一个从节点
S: 02cba50c405b02120e139b07b8968691e5803661 192.168.178.12:7008
   slots: (0 slots) slave
   replicates fec78e5b09b378b876088d27311780ee77df5149
M: fec78e5b09b378b876088d27311780ee77df5149 127.0.0.1:7007
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   1 additional replica(s)
M: dabf91df0a01e87c514216bc5c7e810ca3f3b169 192.168.178.12:7001
   slots:1365-5460,6827-10922 (8192 slots) master      //7001主节点的哈希槽比原来增加了一段
   1 additional replica(s)
S: 2d0ad242a0371981c0499b8cd56d666783dc3339 192.168.178.12:7004
   slots: (0 slots) slave
   replicates dabf91df0a01e87c514216bc5c7e810ca3f3b169
M: e19e54c3373ac25267617f623eafb332e9008fee 192.168.178.12:7003
   slots:12288-16383 (4096 slots) master
   1 additional replica(s)
S: 74b0b1fc4ae9d1063380c4d841cc9fda2eb8ef52 192.168.178.12:7005
   slots: (0 slots) slave
   replicates 7eacea6776c380422a4535da657c9996804513aa
S: 4af5a32724d226e988c6f255cadfd99edc9070a7 192.168.178.12:7006
   slots: (0 slots) slave
   replicates e19e54c3373ac25267617f623eafb332e9008fee
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

重点放在这里:

M: 7eacea6776c380422a4535da657c9996804513aa 127.0.0.1:7002
   slots: (0 slots) master
   1 additional replica(s)
M: dabf91df0a01e87c514216bc5c7e810ca3f3b169 192.168.178.12:7001
   slots:1365-5460,6827-10922 (8192 slots) master
   1 additional replica(s)

7002节点上原有的4096个哈希槽全部移至7001节点上了,7001变成了8192个节点。此时7002节点上无哈希槽可以执行接下来的移除节点操作。

>>> Sending CLUSTER FORGET messages to the cluster...
>>> 192.168.178.12:7005 as replica of 127.0.0.1:7002
  //请关照一下来自7005节点(7002的从节点)的呼唤,,,
/usr/local/share/gems/gems/redis-3.0.0/lib/redis/client.rb:79:in `call': ERR Can't forget my master! (Redis::CommandError)       
  	from /usr/local/share/gems/gems/redis-3.0.0/lib/redis.rb:2190:in `block in method_missing'
	from /usr/local/share/gems/gems/redis-3.0.0/lib/redis.rb:36:in `block in synchronize'
	from /usr/share/ruby/monitor.rb:211:in `mon_synchronize'
	from /usr/local/share/gems/gems/redis-3.0.0/lib/redis.rb:36:in `synchronize'
	from /usr/local/share/gems/gems/redis-3.0.0/lib/redis.rb:2189:in `method_missing'
	from ./redis-trib.rb:1086:in `block in delnode_cluster_cmd'
	from ./redis-trib.rb:1078:in `each'
	from ./redis-trib.rb:1078:in `delnode_cluster_cmd'
	from ./redis-trib.rb:1373:in `<main>'

这时直接删除7002依旧是失败的,原因是7002的从节点7005不乐意了,当删除redis主节点时不仅要转移其所有哈希槽而且必须转移其后的所有从节点到其他主节点。
删除7005节点。

[root@localhost redis-cluster]# ./redis-trib.rb del-node 127.0.0.1:7005 74b0b1fc4ae9d1063380c4d841cc9fda2eb8ef52
>>> Removing node 74b0b1fc4ae9d1063380c4d841cc9fda2eb8ef52 from cluster 127.0.0.1:7005
Connecting to node 192.168.178.12:7008: OK
Connecting to node 192.168.178.12:7007: OK
Connecting to node 192.168.178.12:7001: OK
Connecting to node 192.168.178.12:7004: OK
Connecting to node 192.168.178.12:7002: OK
Connecting to node 192.168.178.12:7003: OK
Connecting to node 192.168.178.12:7008: OK
Connecting to node 192.168.178.12:7006: OK
>>> Sending CLUSTER FORGET messages to the cluster...   //7005节点被移除的消息已发往各个节点
>>> SHUTDOWN the node.

从节点被移除之后,我们来移除7002主节点。

  [root@localhost redis-cluster]# ./redis-trib.rb del-node 127.0.0.1:7002 7eacea6776c380422a4535da657c9996804513aa     //后面跟的是7002节点的id
    >>> Removing node 7eacea6776c380422a4535da657c9996804513aa from cluster 127.0.0.1:7002
    Connecting to node 192.168.178.12:7008: OK
    Connecting to node 127.0.0.1:7007: OK
    Connecting to node 192.168.178.12:7001: OK
    Connecting to node 192.168.178.12:7004: OK
    Connecting to node 192.168.178.12:7003: OK
    Connecting to node 192.168.178.12:7006: OK
    >>> Sending CLUSTER FORGET messages to the cluster...
    >>> SHUTDOWN the node.

另外说明一下:这里的节点移除并不是kill掉7005和7002两个节点,他们的进程依旧是在后台运行的,只是不在当前的redis集群了,这两个节点目前呈单节点状态运行,随后依旧可以重新加入集群。大家可以用cluster info或 cluster nodes查看一下集群的状态和各个节点的状态验证我这块的说明,篇幅问题我这就不贴代码了。

好了 ,这波测试验证先到此为止。

小结:

这两篇文章是对Redis集群的高可用的测试,经过测试我们可以验证redis集群的哨兵机制能够自动化的系统监控,做好故障恢复。当监控到一个主节点挂了之后,哨兵会自动选取一个从节点变为主节点,主从数据一致。
当集群需要扩容时,可以方便的增加节点,只需把其他节点的哈希槽移动到新的节点即可,在保证哈希槽的总数量为16384范围内,集群可以一直增加节点扩容。当集群需要移除主节点时,只需把移除的节点的哈希槽挪到其他节点而且保证所有从节点也已移除就可以,哈希槽可以不连续,移除后的主节点也可以作为其他主节点的从节点等集群需要扩容时再次加入集群继续保证高可用。

猜你喜欢

转载自blog.csdn.net/YYZZHC999/article/details/83474899