本文主要是介绍Redis6集群缩容,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Redis集群缩容有几种情况,
1,如果是删除故障主节点,通常故障的主节会先自动切换为从节点,再进行删除;
2, 如果是删除从节点,先为主节点添加新的从之后,再将其删除;
3, 如果是要删除整个主从节点,一般先删从,然后迁移slot,最后再删除主;
当前集群架构 4主4从:
127.0.0.1:8000> cluster nodes
e9aac3ea026f8b5b14267861021a282103671a9c 127.0.0.1:8003@18003 master - 0 1626234271000 18 connected 0-1365 5462-6826 10923-12287
e4ec27a4f61c66131faebab76d0c33c38fb5695c 127.0.0.1:8100@18100 slave 25d25af226ac55e9c03723288c20f53520420767 0 1626234272521 16 connected
68507c82e45915e6a257afbfc2626c2424684879 127.0.0.1:8001@18001 master - 0 1626234271517 14 connected 6827-10922
89609f9d318bbca243c622195dcffb0c4c739c21 127.0.0.1:8103@18103 slave e9aac3ea026f8b5b14267861021a282103671a9c 0 1626234269000 18 connected
25d25af226ac55e9c03723288c20f53520420767 127.0.0.1:8000@18000 myself,master - 0 1626234269000 16 connected 1366-5461
e4df1b413eb5731f4de442e3e38a14612dc65700 127.0.0.1:8102@18102 slave 3db06c21c6dea8701fadbebfebf1aa92e5b13037 0 1626234272000 12 connected
30bb3d720a0c7dad6aed79f17ab33313246a0629 127.0.0.1:8101@18101 slave 68507c82e45915e6a257afbfc2626c2424684879 0 1626234268000 14 connected
3db06c21c6dea8701fadbebfebf1aa92e5b13037 127.0.0.1:8002@18002 master - 0 1626234270514 12 connected 12288-16383
我希望删除127.0.0.1:8003 和127.0.0.1:8103;
首先先删除slave 127.0.0.1:8103;
[root@A01-R05-B308E3-I114-93 ~]# redis-cli --cluster del-node 127.0.0.1:8103 89609f9d318bbca243c622195dcffb0c4c739c21
>>> Removing node 89609f9d318bbca243c622195dcffb0c4c739c21 from cluster 127.0.0.1:8103
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.
然后重新分配slot
我希望删除节点 127.0.0.1:8003, 含有slot: 0-1365 5462-6826 10923-12287
需要进行三次reshard
第一次: 移动 0-1365 到 127.0.0.1:8000
第二次: 移动 5462-6826 到 127.0.0.1:8001
第三次: 移动 10923-12287 到 127.0.0.1:8002
执行如下:
[root@XXX ~]# redis-cli --cluster reshard 127.0.0.1:8000
>>> Performing Cluster Check (using node 127.0.0.1:8000)
M: 25d25af226ac55e9c03723288c20f53520420767 127.0.0.1:8000slots:[1366-5461] (4096 slots) master1 additional replica(s)
M: e9aac3ea026f8b5b14267861021a282103671a9c 127.0.0.1:8003slots:[0-1365],[5462-6826],[10923-12287] (4096 slots) master
S: e4ec27a4f61c66131faebab76d0c33c38fb5695c 127.0.0.1:8100slots: (0 slots) slavereplicates 25d25af226ac55e9c03723288c20f53520420767
M: 68507c82e45915e6a257afbfc2626c2424684879 127.0.0.1:8001slots:[6827-10922] (4096 slots) master1 additional replica(s)
S: e4df1b413eb5731f4de442e3e38a14612dc65700 127.0.0.1:8102slots: (0 slots) slavereplicates 3db06c21c6dea8701fadbebfebf1aa92e5b13037
S: 30bb3d720a0c7dad6aed79f17ab33313246a0629 127.0.0.1:8101slots: (0 slots) slavereplicates 68507c82e45915e6a257afbfc2626c2424684879
M: 3db06c21c6dea8701fadbebfebf1aa92e5b13037 127.0.0.1:8002slots:[12288-16383] (4096 slots) master1 additional replica(s)
[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)? 1366
What is the receiving node ID? 25d25af226ac55e9c03723288c20f53520420767
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: e9aac3ea026f8b5b14267861021a282103671a9c
Source node #2: doneReady to move 1366 slots.Source nodes:M: e9aac3ea026f8b5b14267861021a282103671a9c 127.0.0.1:8003slots:[0-1365],[5462-6826],[10923-12287] (4096 slots) masterDestination node:M: 25d25af226ac55e9c03723288c20f53520420767 127.0.0.1:8000slots:[1366-5461] (4096 slots) master1 additional replica(s)Resharding plan:Moving slot 0 from e9aac3ea026f8b5b14267861021a282103671a9cMoving slot 1 from e9aac3ea026f8b5b14267861021a282103671a9cMoving slot 2 from e9aac3ea026f8b5b14267861021a282103671a9cMoving slot 3 from e9aac3ea026f8b5b14267861021a282103671a9cMoving slot 4 from e9aac3ea026f8b5b14267861021a282103671a9c
迁移完毕之后的slot分布
此时127.0.0.1:8003上没有slot了,可以进行删除;
[root@XXX ~]# redis-cli --cluster del-node 127.0.0.1:8003 e9aac3ea026f8b5b14267861021a282103671a9c
>>> Removing node e9aac3ea026f8b5b14267861021a282103671a9c from cluster 127.0.0.1:8003
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.
查看当前slots分布,三主三从
127.0.0.1:8000> cluster slots
1) 1) (integer) 02) (integer) 54613) 1) "127.0.0.1"2) (integer) 80003) "25d25af226ac55e9c03723288c20f53520420767"4) 1) "127.0.0.1"2) (integer) 81003) "e4ec27a4f61c66131faebab76d0c33c38fb5695c"
2) 1) (integer) 54622) (integer) 109223) 1) "127.0.0.1"2) (integer) 80013) "68507c82e45915e6a257afbfc2626c2424684879"4) 1) "127.0.0.1"2) (integer) 81013) "30bb3d720a0c7dad6aed79f17ab33313246a0629"
3) 1) (integer) 109232) (integer) 163833) 1) "127.0.0.1"2) (integer) 80023) "3db06c21c6dea8701fadbebfebf1aa92e5b13037"4) 1) "127.0.0.1"2) (integer) 81023) "e4df1b413eb5731f4de442e3e38a14612dc65700"
127.0.0.1:8000>
这篇关于Redis6集群缩容的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!