#1.命令 redis-cli -a [password] --cluster reshard [new_ip] #2.例子 redis-cli -a 123456 --cluster reshard 127.0.0.1:7004 [root@T98899999 redis]# redis-cli -a 123456 --cluster reshard 127.0.0.1:7004 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. >>> Performing Cluster Check (using node127.0.0.1:7004) M: 11c3459ccdb510973ed5e61a755aaecc923405f7 127.0.0.1:7004 slots: (0 slots) master S: c836695daad38bcea59eb71dece7f860eab5f15e 127.0.0.1:8003 slots: (0 slots) slave replicates 8140ca0e986ec863881b6dede6f7555d04fe5c06 S: 633546d3d75199e202d66ac56bca7e4c387bb453 127.0.0.1:8002 slots: (0 slots) slave replicates 145b99ca42e4ddf2ad7fc43bdbc410ed0729e818 M: 145b99ca42e4ddf2ad7fc43bdbc410ed0729e818 127.0.0.1:7001 slots:[0-5460] (5461 slots) master 1 additional replica(s) M: 8140ca0e986ec863881b6dede6f7555d04fe5c06 127.0.0.1:7002 slots:[5461-10922] (5462 slots) master 1 additional replica(s) S: e236e0ec685118abc67da92ad67c2db4b3f1abc6 127.0.0.1:8001 slots: (0 slots) slave replicates 4efa79ebad2f410049ab59edf695d6be63ed0a25 M: 4efa79ebad2f410049ab59edf695d6be63ed0a25 127.0.0.1:7003 slots:[10923-16383] (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. How many slots do you want to move (from 1 to 16384)? 100 What is the receiving nodeID? 11c3459ccdb510973ed5e61a755aaecc923405f7 Please enter all the source nodeIDs. 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: 145b99ca42e4ddf2ad7fc43bdbc410ed0729e818 Source node#2: done Ready to move 100 slots. Source nodes: M: 145b99ca42e4ddf2ad7fc43bdbc410ed0729e818 127.0.0.1:7001 slots:[0-5460] (5461 slots) master 1 additional replica(s) Destination node: M: 11c3459ccdb510973ed5e61a755aaecc923405f7 127.0.0.1:7004 slots: (0 slots) master Resharding plan: Moving slot 0 from 145b99ca42e4ddf2ad7fc43bdbc410ed0729e818 Moving slot 1 from 145b99ca42e4ddf2ad7fc43bdbc410ed0729e818 Moving slot 2 from 145b99ca42e4ddf2ad7fc43bdbc410ed0729e818 ..... Do you want to proceed with the proposed reshard plan (yes/no)? yes
说明下执行命令redis-cli -a 123456 --cluster reshard 127.0.0.1:7004时出现的询问:
How many slots do you want to move (from 1 to 16384)?:表示需要移动槽的数量。填写自己的需要即可。
What is the receiving node ID?:表示:那个id来接收它。即新的7004的id。
redis-cli -a 123456-c -p 7004 Warning: Using a passwordwith'-a'or'-u'optionon the command line interface may not be safe. 127.0.0.1:7004> get num Redirected to slot [2765] located at 127.0.0.1:7001 "10"
可以看到num的slot槽是2765。
查看是否添加成功。
1 2 3 4 5 6 7 8 9 10 11 12 13
redis-cli -a 123456 -p 7004 cluster nodes #结果,可以发现7004上有0-99共100个散列插槽 redis-cli -a 123456 -p 7004 cluster nodes Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. c836695daad38bcea59eb71dece7f860eab5f15e127.0.0.1:8003@18003 slave 8140ca0e986ec863881b6dede6f7555d04fe5c06 016563425980002 connected 11c3459ccdb510973ed5e61a755aaecc923405f7127.0.0.1:7004@17004 myself,master - 016563425950009 connected 0-99 633546d3d75199e202d66ac56bca7e4c387bb453127.0.0.1:8002@18002 slave 145b99ca42e4ddf2ad7fc43bdbc410ed0729e818 016563425970008 connected 145b99ca42e4ddf2ad7fc43bdbc410ed0729e818127.0.0.1:7001@17001 master - 016563425960008 connected 100-5460 8140ca0e986ec863881b6dede6f7555d04fe5c06127.0.0.1:7002@17002 master - 016563425988042 connected 5461-10922 e236e0ec685118abc67da92ad67c2db4b3f1abc6127.0.0.1:8001@18001 slave 4efa79ebad2f410049ab59edf695d6be63ed0a25 016563425978013 connected 4efa79ebad2f410049ab59edf695d6be63ed0a25127.0.0.1:7003@17003 master - 016563425957773 connected 10923-16383
#1.查看集群节点信息 -a password 如果没有密码就不需要这个命令 redis-cli -a 123456 -p 7004 cluster nodes Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. e236e0ec685118abc67da92ad67c2db4b3f1abc6 127.0.0.1:8001@18001slave4efa79ebad2f410049ab59edf695d6be63ed0a25 016540914525763 connected c836695daad38bcea59eb71dece7f860eab5f15e 127.0.0.1:8003@18003slave8140ca0e986ec863881b6dede6f7555d04fe5c06 016540914520002 connected 4efa79ebad2f410049ab59edf695d6be63ed0a25 127.0.0.1:7003@17003master- 016540914535933 connected 10923-16383 633546d3d75199e202d66ac56bca7e4c387bb453 127.0.0.1:8002@18002slave145b99ca42e4ddf2ad7fc43bdbc410ed0729e818 016540914520001 connected 11c3459ccdb510973ed5e61a755aaecc923405f7 127.0.0.1:7004@17004 myself,master- 016540914510007 connected 0-2999 8140ca0e986ec863881b6dede6f7555d04fe5c06 127.0.0.1:7002@17002master- 016540914530002 connected 5461-10922 145b99ca42e4ddf2ad7fc43bdbc410ed0729e818 127.0.0.1:7001@17001master- 016540914545971 connected 3000-5460 #2.移动slot槽:需要注意的是id顺序不要搞错了 #2.1 执行命令:redis-cli -a 123456 --cluster reshard 127.0.0.1:7004 #2.2 会出现如下的内容:能看到你要移除节点的slots槽 redis-cli -a 123456 --cluster reshard 127.0.0.1:7004 Warning: Using a 123456 with '-a' or '-u' option on the command line interface may not be safe. >>> Performing Cluster Check (using node127.0.0.1:7004) M: 11c3459ccdb510973ed5e61a755aaecc923405f7 127.0.0.1:7004 slots:[0-2999] (3000 slots) master 1 additional replica(s) S: e236e0ec685118abc67da92ad67c2db4b3f1abc6 127.0.0.1:8001 slots: (0 slots) slave replicates 4efa79ebad2f410049ab59edf695d6be63ed0a25 S: c836695daad38bcea59eb71dece7f860eab5f15e 127.0.0.1:8003 slots: (0 slots) slave replicates 8140ca0e986ec863881b6dede6f7555d04fe5c06 M: 4efa79ebad2f410049ab59edf695d6be63ed0a25 127.0.0.1:7003 slots:[10923-16383] (5461 slots) master 1 additional replica(s) S: 633546d3d75199e202d66ac56bca7e4c387bb453 127.0.0.1:8002 slots: (0 slots) slave replicates 11c3459ccdb510973ed5e61a755aaecc923405f7 M: 8140ca0e986ec863881b6dede6f7555d04fe5c06 127.0.0.1:7002 slots:[5461-10922] (5462 slots) master 1 additional replica(s) M: 145b99ca42e4ddf2ad7fc43bdbc410ed0729e818 127.0.0.1:7001 slots:[3000-5460] (2641 slots) master [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. #2.3表示移动slots的数量 How many slots do you want to move (from 1 to 16384)?3000 #2.4 表示移动到那个节点ID(或者说那个节点ID来接受这个移动的slots) What is the receiving nodeID? 145b99ca42e4ddf2ad7fc43bdbc410ed0729e818 #2.5 表示那个节点ID需要移动 Please enter all the source nodeIDs. 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: 11c3459ccdb510973ed5e61a755aaecc923405f7 #2.6输入done Source node#1:done #2.7最后确认是否是想要的结果 Do you want to proceed with the proposed reshard plan (yes/no)? yes #2.8 开始执行移动功能。等着移动完成后就可以删除节点了。 Moving slot 1546 from 127.0.0.1:7004 to 127.0.0.1:7001: Moving slot 1547 from 127.0.0.1:7004 to 127.0.0.1:7001: Moving slot 1548 from 127.0.0.1:7004 to 127.0.0.1:7001: Moving slot 1549 from 127.0.0.1:7004 to 127.0.0.1:7001: 省略..... #3.可以再次执行1命令检查一下
用到的命令:
redis-cli -a password -p 7004 cluster nodes
redis-cli -a password --cluster reshard host:prot
执行删除命令:
1 2 3 4 5 6 7 8 9
#1.命令 redis-cli -a password --cluster del-node ip:prot 删除点ID #2.例子 [root@T98899999 ~]# redis-cli -a 123456 --cluster del-node 127.0.0.1:700411c3459ccdb510973ed5e61a755aaecc923405f7 Warning: Using a password with'-a'or'-u' option on the command line interface may not be safe. >>> Removing node 11c3459ccdb510973ed5e61a755aaecc923405f7 from cluster 127.0.0.1:7004 >>> Sending CLUSTER FORGET messages to the cluster... >>> Sending CLUSTER RESET SOFTto the deleted node.
查看是否删除成功(发现已经没有这个节点了)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
[root@T98899999 ~]# redis-cli -a 123456 -p 7001 cluster nodes Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.