################# cluster nodes info: #################
026f0179631f50ca858d46c2b2829b3af71af2c8 127.0.0.1:10004@20004 slave 6164025849a8ff9297664fc835bc851af5004f61 0 1575960493000 64 connected
9f265545ebb799d2773cfc20c71705cff9d733ae 127.0.0.1:10006@20006 slave 8b75325c59a7242344d0ebe5ee1e0068c66ffa2a 0 1575960493849 66 connected
64e634307bdc339b503574f5a77f1b156c021358 127.0.0.1:10002@20002 master - 0 1575960494852 65 connected 6826-10922
23e1871c4e1dc1047ce567326e74a6194589146c 127.0.0.1:10005@20005 slave 64e634307bdc339b503574f5a77f1b156c021358 0 1575960492000 65 connected
4854375c501c3dbfb4e2d94d50e62a47520c4f12 127.0.0.1:10008@20008 slave 3645e00a8ec3a902bd6effb4fc20c56a00f2c982 0 1575960493000 67 connected
8b75325c59a7242344d0ebe5ee1e0068c66ffa2a 127.0.0.1:10003@20003 master - 0 1575960493000 66 connected 12288-16383
3645e00a8ec3a902bd6effb4fc20c56a00f2c982 127.0.0.1:10007@20007 myself,master - 0 1575960493000 67 connected 0-1364 5461-6825 10923-12287
6164025849a8ff9297664fc835bc851af5004f61 127.0.0.1:10001@20001 master - 0 1575960492848 64 connected 1365-5460
可见新加的节点成功重新分配了slot,集群扩容成功。
这里有几个需要注意的两个问题,如果是自动化安装的话:
1,add-node之后(不管是柱节点还是从节点),要sleep足够长的时间(这里是20秒),让集群中所有的节点都meet到新节点,否则会扩容失败
2,新节点的reshard之后要sleep足够长的时间(这里是20秒),否则继续reshard其他节点的slot会导致上一个reshared失败
整个过程如下
[root@JD redis_install]# python3 create_redis_cluster.py #########################cleanup instance################################# #########################add node into cluster################################# redis-cli --cluster add-node 127.0.0.1:10007 127.0.0.1:10001 -a redis@password Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. >>> Adding node 127.0.0.1:10007 to cluster 127.0.0.1:10001 >>> Performing Cluster Check (using node 127.0.0.1:10001) M: 6164025849a8ff9297664fc835bc851af5004f61 127.0.0.1:10001 slots:[0-5460] (5461 slots) master 1 additional replica(s) S: 9f265545ebb799d2773cfc20c71705cff9d733ae 127.0.0.1:10006 slots: (0 slots) slave replicates 8b75325c59a7242344d0ebe5ee1e0068c66ffa2a M: 8b75325c59a7242344d0ebe5ee1e0068c66ffa2a 127.0.0.1:10003 slots:[10923-16383] (5461 slots) master 1 additional replica(s) S: 026f0179631f50ca858d46c2b2829b3af71af2c8 127.0.0.1:10004 slots: (0 slots) slave replicates 6164025849a8ff9297664fc835bc851af5004f61 S: 23e1871c4e1dc1047ce567326e74a6194589146c 127.0.0.1:10005 slots: (0 slots) slave replicates 64e634307bdc339b503574f5a77f1b156c021358 M: 64e634307bdc339b503574f5a77f1b156c021358 127.0.0.1:10002 slots:[5461-10922] (5462 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:10007 to make it join the cluster. [OK] New node added correctly. 0 redis-cli --cluster add-node 127.0.0.1:10008 127.0.0.1:10007 --cluster-slave --cluster-master-id 3645e00a8ec3a902bd6effb4fc20c56a00f2c982 -a ****** Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. >>> Adding node 127.0.0.1:10008 to cluster 127.0.0.1:10007 >>> Performing Cluster Check (using node 127.0.0.1:10007) M: 3645e00a8ec3a902bd6effb4fc20c56a00f2c982 127.0.0.1:10007 slots: (0 slots) master S: 026f0179631f50ca858d46c2b2829b3af71af2c8 127.0.0.1:10004 slots: (0 slots) slave replicates 6164025849a8ff9297664fc835bc851af5004f61 S: 9f265545ebb799d2773cfc20c71705cff9d733ae 127.0.0.1:10006 slots: (0 slots) slave replicates 8b75325c59a7242344d0ebe5ee1e0068c66ffa2a M: 64e634307bdc339b503574f5a77f1b156c021358 127.0.0.1:10002 slots:[5461-10922] (5462 slots) master 1 additional replica(s) S: 23e1871c4e1dc1047ce567326e74a6194589146c 127.0.0.1:10005 slots: (0 slots) slave replicates 64e634307bdc339b503574f5a77f1b156c021358 M: 8b75325c59a7242344d0ebe5ee1e0068c66ffa2a 127.0.0.1:10003 slots:[10923-16383] (5461 slots) master 1 additional replica(s) M: 6164025849a8ff9297664fc835bc851af5004f61 127.0.0.1:10001 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:10008 to make it join the cluster. Waiting for the cluster to join >>> Configure node as replica of 127.0.0.1:10007. [OK] New node added correctly. 0 #########################reshard slots################################# ############################ execute reshard ######################################### redis-cli -a redis@password --cluster reshard 127.0.0.1:10001 --cluster-from 6164025849a8ff9297664fc835bc851af5004f61 --cluster-to 3645e00a8ec3a902bd6effb4fc20c56a00f2c982 --cluster-slots 1365 --cluster-yes --cluster-timeout 50000 --cluster-pipeline 10000 --cluster-replace >/dev/null 2>&1 ############################ execute reshard ######################################### redis-cli -a redis@password --cluster reshard 127.0.0.1:10002 --cluster-from 64e634307bdc339b503574f5a77f1b156c021358 --cluster-to 3645e00a8ec3a902bd6effb4fc20c56a00f2c982 --cluster-slots 1365 --cluster-yes --cluster-timeout 50000 --cluster-pipeline 10000 --cluster-replace >/dev/null 2>&1 ############################ execute reshard ######################################### redis-cli -a redis@password --cluster reshard 127.0.0.1:10003 --cluster-from 8b75325c59a7242344d0ebe5ee1e0068c66ffa2a --cluster-to 3645e00a8ec3a902bd6effb4fc20c56a00f2c982 --cluster-slots 1365 --cluster-yes --cluster-timeout 50000 --cluster-pipeline 10000 --cluster-replace >/dev/null 2>&1 ################# cluster nodes info: ################# 026f0179631f50ca858d46c2b2829b3af71af2c8 127.0.0.1:10004@20004 slave 6164025849a8ff9297664fc835bc851af5004f61 0 1575960493000 64 connected 9f265545ebb799d2773cfc20c71705cff9d733ae 127.0.0.1:10006@20006 slave 8b75325c59a7242344d0ebe5ee1e0068c66ffa2a 0 1575960493849 66 connected 64e634307bdc339b503574f5a77f1b156c021358 127.0.0.1:10002@20002 master - 0 1575960494852 65 connected 6826-10922 23e1871c4e1dc1047ce567326e74a6194589146c 127.0.0.1:10005@20005 slave 64e634307bdc339b503574f5a77f1b156c021358 0 1575960492000 65 connected 4854375c501c3dbfb4e2d94d50e62a47520c4f12 127.0.0.1:10008@20008 slave 3645e00a8ec3a902bd6effb4fc20c56a00f2c982 0 1575960493000 67 connected 8b75325c59a7242344d0ebe5ee1e0068c66ffa2a 127.0.0.1:10003@20003 master - 0 1575960493000 66 connected 12288-16383 3645e00a8ec3a902bd6effb4fc20c56a00f2c982 127.0.0.1:10007@20007 myself,master - 0 1575960493000 67 connected 0-1364 5461-6825 10923-12287 6164025849a8ff9297664fc835bc851af5004f61 127.0.0.1:10001@20001 master - 0 1575960492848 64 connected 1365-5460 [root@JD redis_install]#
Redis集群缩容