zoukankan      html  css  js  c++  java
  • redis节点管理-新增从节点

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

     

    新增从节点

           新增一个节点7008节点,使用add-node --slave命令。

           

    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. [root@localhost redis-cluster]# cp -r redis01/ redis08  
    2. [root@localhost redis-cluster]# cd redis08/  
    3. [root@localhost redis08]# sed -i "s/7001/7008/g" ./redis.conf  
    4. [root@localhost redis08]# ./redis-server redis.conf   


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

    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. ./redis-trib.rb add-node --slave --master-id $[nodeid] 127.0.0.1:7008 127.0.0.1:7000  

        nodeid为要加到master主节点的node id,127.0.0.1:7008为新增的从节点,127.0.0.1:7000为集群的一个节点(集群的任意节点都行),用来辨识是哪个集群;如果没有给定那个主节点--master-id的话,redis-trib将会将新增的从节点随机到从节点较少的主节点上。

        现在我们添加一下7008,看是否会自动加到没有从节点的7007主节点上。

    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. [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  
    2. >>> Performing Cluster Check (using node 127.0.0.1:7001)  
    3. M: dd19221c404fb2fc4da37229de56bab755c76f2b 127.0.0.1:7001  
    4.    slots:1365-5460 (4096 slots) master  
    5.    1 additional replica(s)  
    6. M: ee3efb90e5ac0725f15238a64fc60a18a71205d7 127.0.0.1:7007  
    7.    slots:0-1364,5461-6826,10923-12287 (4096 slots) master  
    8.    0 additional replica(s)  
    9. M: a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005  
    10.    slots:6827-10922 (4096 slots) master  
    11.    1 additional replica(s)  
    12. S: 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006  
    13.    slots: (0 slots) slave  
    14.    replicates f9886c71e98a53270f7fda961e1c5f730382d48f  
    15. M: f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003  
    16.    slots:12288-16383 (4096 slots) master  
    17.    1 additional replica(s)  
    18. S: 1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002  
    19.    slots: (0 slots) slave  
    20.    replicates a5db243087d8bd423b9285fa8513eddee9bb59a6  
    21. S: 50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7004  
    22.    slots: (0 slots) slave  
    23.    replicates dd19221c404fb2fc4da37229de56bab755c76f2b  
    24. [OK] All nodes agree about slots configuration.  
    25. >>> Check for open slots...  
    26. >>> Check slots coverage...  
    27. [OK] All 16384 slots covered.  
    28. Automatically selected master 127.0.0.1:7007  
    29. >>> Send CLUSTER MEET to node 127.0.0.1:7008 to make it join the cluster.  
    30. Waiting for the cluster to join.  
    31. >>> Configure node as replica of 127.0.0.1:7007.  
    32. [OK] New node added correctly.  
    33. [root@localhost redis-cluster]#   


         可以看到自动选择了127.0.0.1:7007为master主节点,并且添加成功。

         可以check一下7008:

          

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

           可以看到7008作为了7007的从节点。

            

           再测试一下指定主节点添加从节点,给7007增加7009从节点。

            

    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. [root@localhost redis-cluster]# cp -r redis01/ redis09  
    2. [root@localhost redis-cluster]# cd redis09  
    3. [root@localhost redis09]# sed -i "s/7001/7009/g" ./redis.conf  
    4. [root@localhost redis09]# ./redis-server redis.conf   

           添加7007主节点上

           

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

         显示从节点7009节点添加到7007主节点,可以看一下7007的从节点,如下:

    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. [root@localhost redis-cluster]# cd ./redis07  
    2. [root@localhost redis07]# ./redis-cli -c -p 7007 cluster nodes | grep ee3efb90e5ac0725f15238a64fc60a18a71205d7   
    3. 1f51443ede952b98724fea2a12f61fe710ab6cb1 127.0.0.1:7009 slave ee3efb90e5ac0725f15238a64fc60a18a71205d7 0 1462962710266 8 connected  
    4. ee3efb90e5ac0725f15238a64fc60a18a71205d7 127.0.0.1:7007 myself,master - 0 0 8 connected 0-1364 5461-6826 10923-12287  
    5. 2ab1b061c36f30ae35604e9a171ae3afdc3c87e5 127.0.0.1:7008 slave ee3efb90e5ac0725f15238a64fc60a18a71205d7 0 1462962711607 8 connected  
    6. [root@localhost redis07]#   


         maser 7007有2个slave 7008,7009。

         我们测试一下7007节点挂掉,看7008和7009那个成为主节点。

       

    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. [root@localhost redis-cluster]# ps -ef | grep redis  
    2. root       7950      1  0 12:50 ?        00:02:05 ./redis-server 127.0.0.1:7001 [cluster]  
    3. root       7956      1  0 12:50 ?        00:02:11 ./redis-server 127.0.0.1:7003 [cluster]  
    4. root       7960      1  0 12:50 ?        00:01:47 ./redis-server 127.0.0.1:7004 [cluster]  
    5. root       7964      1  0 12:50 ?        00:02:07 ./redis-server 127.0.0.1:7005 [cluster]  
    6. root       7966      1  0 12:50 ?        00:01:46 ./redis-server 127.0.0.1:7006 [cluster]  
    7. root      12070      1  0 15:14 ?        00:01:08 ./redis-server 127.0.0.1:7002 [cluster]  
    8. root      13441      1  0 16:09 ?        00:01:25 ./redis-server 127.0.0.1:7007 [cluster]  
    9. root      15939      1  0 17:41 ?        00:00:20 ./redis-server 127.0.0.1:7008 [cluster]  
    10. root      16623      1  0 18:07 ?        00:00:10 ./redis-server 127.0.0.1:7009 [cluster]  
    11. root      17295  10581  0 18:37 pts/2    00:00:00 grep --color=auto redis  
    12. [root@localhost redis-cluster]# kill -9 13441  
    13. [root@localhost redis-cluster]# cd ./redis08  
    14. [root@localhost redis08]# ./redis-cli -c -p 7008  
    15. 127.0.0.1:7008> get name  
    16. -> Redirected to slot [5798] located at 127.0.0.1:7009  
    17. "andy"  
    18. 127.0.0.1:7009> cluster nodes  
    19. ee3efb90e5ac0725f15238a64fc60a18a71205d7 127.0.0.1:7007 master,fail - 1462963082317 1462963080194 8 disconnected  
    20. 50ce1ea59106b4c2c6bc502593a6a7a7dabf5041 127.0.0.1:7004 slave dd19221c404fb2fc4da37229de56bab755c76f2b 0 1462963170968 1 connected  
    21. f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003 master - 0 1462963168525 3 connected 12288-16383  
    22. dd19221c404fb2fc4da37229de56bab755c76f2b 127.0.0.1:7001 master - 0 1462963164466 1 connected 1365-5460  
    23. 2ab1b061c36f30ae35604e9a171ae3afdc3c87e5 127.0.0.1:7008 slave 1f51443ede952b98724fea2a12f61fe710ab6cb1 0 1462963167508 9 connected  
    24. 1f51443ede952b98724fea2a12f61fe710ab6cb1 127.0.0.1:7009 myself,master - 0 0 9 connected 0-1364 5461-6826 10923-12287  
    25. 1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002 slave a5db243087d8bd423b9285fa8513eddee9bb59a6 0 1462963170564 7 connected  
    26. 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006 slave f9886c71e98a53270f7fda961e1c5f730382d48f 0 1462963167915 3 connected  
    27. a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005 master - 0 1462963169538 7 connected 6827-10922  
    28. 127.0.0.1:7009>   

          可以看到7009代替7007成了主节点。

           重启7007之后,会自动变成7009的从节点。

           

    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
      1. [root@localhost redis-cluster]# cd redis07  
      2. [root@localhost redis07]# ./redis-server redis.conf   
      3. [root@localhost redis07]# cd ../  
      4. [root@localhost redis-cluster]# ./redis-trib.rb check 127.0.0.1:7007  
      5. >>> Performing Cluster Check (using node 127.0.0.1:7007)  
      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 dd19221c404fb2fc4da37229de56bab755c76f2b  
      12. M: 1f51443ede952b98724fea2a12f61fe710ab6cb1 127.0.0.1:7009  
      13.    slots:0-1364,5461-6826,10923-12287 (4096 slots) master  
      14.    2 additional replica(s)  
      15. S: 8bb3ede48319b46d0015440a91ab277da9353c8b 127.0.0.1:7006  
      16.    slots: (0 slots) slave  
      17.    replicates f9886c71e98a53270f7fda961e1c5f730382d48f  
      18. M: dd19221c404fb2fc4da37229de56bab755c76f2b 127.0.0.1:7001  
      19.    slots:1365-5460 (4096 slots) master  
      20.    1 additional replica(s)  
      21. M: a5db243087d8bd423b9285fa8513eddee9bb59a6 127.0.0.1:7005  
      22.    slots:6827-10922 (4096 slots) master  
      23.    1 additional replica(s)  
      24. S: 1f07d76585bfab35f91ec711ac53ab4bc00f2d3a 127.0.0.1:7002  
      25.    slots: (0 slots) slave  
      26.    replicates a5db243087d8bd423b9285fa8513eddee9bb59a6  
      27. M: f9886c71e98a53270f7fda961e1c5f730382d48f 127.0.0.1:7003  
      28.    slots:12288-16383 (4096 slots) master  
      29.    1 additional replica(s)  
      30. S: 2ab1b061c36f30ae35604e9a171ae3afdc3c87e5 127.0.0.1:7008  
      31.    slots: (0 slots) slave  
      32.    replicates 1f51443ede952b98724fea2a12f61fe710ab6cb1  
      33. [OK] All nodes agree about slots configuration.  
      34. >>> Check for open slots...  
      35. >>> Check slots coverage...  
      36. [OK] All 16384 slots covered.  
      37. [root@localhost redis-cluster]#   
  • 相关阅读:
    Kubernetes 集成研发笔记
    Rust 1.44.0 发布
    Rust 1.43.0 发布
    PAT 甲级 1108 Finding Average (20分)
    PAT 甲级 1107 Social Clusters (30分)(并查集)
    PAT 甲级 1106 Lowest Price in Supply Chain (25分) (bfs)
    PAT 甲级 1105 Spiral Matrix (25分)(螺旋矩阵,简单模拟)
    PAT 甲级 1104 Sum of Number Segments (20分)(有坑,int *int 可能会溢出)
    java 多线程 26 : 线程池
    OpenCV_Python —— (4)形态学操作
  • 原文地址:https://www.cnblogs.com/shihaiming/p/5984021.html
Copyright © 2011-2022 走看看