redis节点管理-节点的移除

原文:http://blog.sina.com.cn/s/blog_53b45c4d0102wg13.html

节点的移除

   和节点添加一样,移除节点也有移除主节点,从节点。

   1、移除主节点

       移除节点使用redis-trib的del-node命令,

        

[plain] view plain copy  在CODE上查看代码片派生到我的代码片
  1. redis-trib del-node 127.0.0.1:7002  ${node-id}  

    127.0.0.1:7002位集群节点,node-id为要删除的主节点。 和添加节点不同,移除节点node-id是必需的,测试删除7001主节点:

   

[plain] view plain copy  在CODE上查看代码片派生到我的代码片
  1. [root@localhost redis-cluster]# ./redis-trib.rb del-node 127.0.0.1:7001 dd19221c404fb2fc4da37229de56bab755c76f2b  
  2. >>> Removing node dd19221c404fb2fc4da37229de56bab755c76f2b from cluster 127.0.0.1:7002  
  3. [ERR] Node 127.0.0.1:7001 is not empty! Reshard data away and try again.  
  4. [root@localhost redis-cluster]#   

  redis cluster提示7001已经有数据了,不能够被删除,需要将他的数据转移出去,也就是和新增主节点一样需重新分片。

        

[plain] view plain copy  在CODE上查看代码片派生到我的代码片
  1. [root@localhost redis-cluster]# ./redis-trib.rb reshard 127.0.0.1:7002  

  执行以后会提示我们移除的大小,因为7001占用了4096个槽点

[plain] view plain copy  在CODE上查看代码片派生到我的代码片
  1. >>> Check for open slots...  
  2. >>> Check slots coverage...  
  3. [OK] All 16384 slots covered.  
  4. How many slots do you want to move (from 1 to 16384)?   


  输入4096

  提示移动的node id,填写7009的node id。(这里好像有误,应该填移动到的node id)

[plain] view plain copy  在CODE上查看代码片派生到我的代码片
  1. How many slots do you want to move (from 1 to 16384)? 4096  
  2. What is the receiving node ID?      (接收的nodeid)

   

   需要移动到全部主节点上还是单个主节点(这里好像有误,需要移动的的节点ID,可移动单个节点,也可移动多节点的槽位)

[plain] view plain copy  在CODE上查看代码片派生到我的代码片
  1. Please enter all the source node IDs.  
  2.   Type 'all' to use all the nodes as source nodes for the hash slots.  
  3.   Type 'done' once you entered all the source nodes IDs.  
  4. Source node #1:  


   将4096个槽点移动到7009上,填写7001的node id :dd19221c404fb2fc4da37229de56bab755c76f2b

[plain] view plain copy  在CODE上查看代码片派生到我的代码片
  1. Source node #1:dd19221c404fb2fc4da37229de56bab755c76f2b  
  2. Source node #2:done  
  3. Do you want to proceed with the proposed reshard plan (yes/no)? yes  

   确认之后会一个一个将7001的卡槽移到到7009上。

   

[plain] view plain copy  在CODE上查看代码片派生到我的代码片
  1. [root@localhost redis-cluster]# ./redis-trib.rb check 127.0.0.1:7009  
  2. >>> Performing Cluster Check (using node 127.0.0.1:7009)  
  3. M: 1f51443ede952b98724fea2a12f61fe710ab6cb1 127.0.0.1:7009  
  4.    slots:0-6826,10923-12287 (8192 slots) master  
  5.    3 additional replica(s)  
  6. S: ee3efb90e5ac0725f15238a64fc60a18a71205d7 127.0.0.1:7007  
  7.    slots: (0 slots) slave  
  8.    replicates 1f51443ede952b98724fea2a12f61fe710ab6cb1  
  9. S: 50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7004  
  10.    slots: (0 slots) slave  
  11.    replicates 1f51443ede952b98724fea2a12f61fe710ab6cb1  
  12. M: f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003  
  13.    slots:12288-16383 (4096 slots) master  
  14.    1 additional replica(s)  
  15. M: dd19221c404fb2fc4da37229de56bab755c76f2b 127.0.0.1:7001  
  16.    slots: (0 slots) master  
  17.    0 additional replica(s)  
  18. S: 2ab1b061c36f30ae35604e9a171ae3afdc3c87e5 127.0.0.1:7008  
  19.    slots: (0 slots) slave  
  20.    replicates 1f51443ede952b98724fea2a12f61fe710ab6cb1  
  21. S: 1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002  
  22.    slots: (0 slots) slave  
  23.    replicates a5db243087d8bd423b9285fa8513eddee9bb59a6  
  24. S: 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006  
  25.    slots: (0 slots) slave  
  26.    replicates f9886c71e98a53270f7fda961e1c5f730382d48f  
  27. M: a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005  
  28.    slots:6827-10922 (4096 slots) master  
  29.    1 additional replica(s)  
  30. [OK] All nodes agree about slots configuration.  
  31. >>> Check for open slots...  
  32. >>> Check slots coverage...  
  33. [OK] All 16384 slots covered.  
  34. [root@localhost redis-cluster]#   


     可以看到7001有0个卡槽,而7009有8192个卡槽。

     在执行移除操作

     

[plain] view plain copy  在CODE上查看代码片派生到我的代码片
  1. [root@localhost redis-cluster]# ./redis-trib.rb del-node 127.0.0.1:7002 dd19221c404fb2fc4da37229de56bab755c76f2b  
  2. >>> Removing node dd19221c404fb2fc4da37229de56bab755c76f2b from cluster 127.0.0.1:7002  
  3. >>> Sending CLUSTER FORGET messages to the cluster...  
  4. >>> SHUTDOWN the node.  
  5. [root@localhost redis-cluster]#   


    已经删除了7001节点。

  

[plain] view plain copy  在CODE上查看代码片派生到我的代码片
  1. [root@localhost redis-cluster]# ./redis-trib.rb check 127.0.0.1:7001  
  2. [ERR] Sorry, can't connect to node 127.0.0.1:7001  
  3. [root@localhost redis-cluster]# ./redis-trib.rb check 127.0.0.1:7009  
  4. >>> Performing Cluster Check (using node 127.0.0.1:7009)  
  5. M: 1f51443ede952b98724fea2a12f61fe710ab6cb1 127.0.0.1:7009  
  6.    slots:0-6826,10923-12287 (8192 slots) master  
  7.    3 additional replica(s)  
  8. S: ee3efb90e5ac0725f15238a64fc60a18a71205d7 127.0.0.1:7007  
  9.    slots: (0 slots) slave  
  10.    replicates 1f51443ede952b98724fea2a12f61fe710ab6cb1  
  11. S: 50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7004  
  12.    slots: (0 slots) slave  
  13.    replicates 1f51443ede952b98724fea2a12f61fe710ab6cb1  
  14. M: f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003  
  15.    slots:12288-16383 (4096 slots) master  
  16.    1 additional replica(s)  
  17. S: 2ab1b061c36f30ae35604e9a171ae3afdc3c87e5 127.0.0.1:7008  
  18.    slots: (0 slots) slave  
  19.    replicates 1f51443ede952b98724fea2a12f61fe710ab6cb1  
  20. S: 1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002  
  21.    slots: (0 slots) slave  
  22.    replicates a5db243087d8bd423b9285fa8513eddee9bb59a6  
  23. S: 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006  
  24.    slots: (0 slots) slave  
  25.    replicates f9886c71e98a53270f7fda961e1c5f730382d48f  
  26. M: a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005  
  27.    slots:6827-10922 (4096 slots) master  
  28.    1 additional replica(s)  
  29. [OK] All nodes agree about slots configuration.  
  30. >>> Check for open slots...  
  31. >>> Check slots coverage...  
  32. [OK] All 16384 slots covered.  
  33. [root@localhost redis-cluster]#   


  可以看到7001已经连接不了;而7001的从节点7004自动分配到了7009主节点中,7009现在3个从节点。

 2、移除从节点

     比如删除7009的7008节点:

      

[plain] view plain copy  在CODE上查看代码片派生到我的代码片
  1. [root@localhost redis-cluster]# ./redis-trib.rb del-node 127.0.0.1:7009 2ab1b061c36f30ae35604e9a171ae3afdc3c87e5  
  2. >>> Removing node 2ab1b061c36f30ae35604e9a171ae3afdc3c87e5 from cluster 127.0.0.1:7009  
  3. >>> Sending CLUSTER FORGET messages to the cluster...  
  4. >>> SHUTDOWN the node.  
  5. [root@localhost redis-cluster]# ./redis-trib.rb check 127.0.0.1:7008  
  6. [ERR] Sorry, can't connect to node 127.0.0.1:7008  
  7. [root@localhost redis-cluster]#   

     删除从节点比较方便,现在redis-cluster中有3个主节点,4个从节点,如下:

[plain] view plain copy  在CODE上查看代码片派生到我的代码片
    1. [root@localhost redis-cluster]# ./redis-trib.rb check 127.0.0.1:7009  
    2. >>> Performing Cluster Check (using node 127.0.0.1:7009)  
    3. M: 1f51443ede952b98724fea2a12f61fe710ab6cb1 127.0.0.1:7009  
    4.    slots:0-6826,10923-12287 (8192 slots) master  
    5.    2 additional replica(s)  
    6. S: ee3efb90e5ac0725f15238a64fc60a18a71205d7 127.0.0.1:7007  
    7.    slots: (0 slots) slave  
    8.    replicates 1f51443ede952b98724fea2a12f61fe710ab6cb1  
    9. S: 50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7004  
    10.    slots: (0 slots) slave  
    11.    replicates 1f51443ede952b98724fea2a12f61fe710ab6cb1  
    12. M: f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003  
    13.    slots:12288-16383 (4096 slots) master  
    14.    1 additional replica(s)  
    15. S: 1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002  
    16.    slots: (0 slots) slave  
    17.    replicates a5db243087d8bd423b9285fa8513eddee9bb59a6  
    18. S: 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006  
    19.    slots: (0 slots) slave  
    20.    replicates f9886c71e98a53270f7fda961e1c5f730382d48f  
    21. M: a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005  
    22.    slots:6827-10922 (4096 slots) master  
    23.    1 additional replica(s)  
    24. [OK] All nodes agree about slots configuration.  
    25. >>> Check for open slots...  
    26. >>> Check slots coverage...  
    27. [OK] All 16384 slots covered.  
    28. [root@localhost redis-cluster]#   
原文地址:https://www.cnblogs.com/shihaiming/p/5984025.html