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

新增从节点

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

[plain] view plain copy

 

  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

 

  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

 

  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

 

  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

 

  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

 

  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

 

  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

 

  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

 

    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]#

redis节点管理-新增从节点的更多相关文章

  1. redis节点管理-新增主节点

    原文:http://blog.sina.com.cn/s/blog_53b45c4d0102wg11.html 集群节点添加 节点新增包括新增主节点.从节点两种情况.以下分别做一下测试: 1.新增主节 ...

  2. redis 集群添加新节点

    准备好需要添加的节点:如何创建节点 启动创建的节点: 启动成功: 添加新节点:redis-cli --cluster add-node 127.0.0.1:7006 127.0.0.1:7000  第 ...

  3. Redis服务之集群节点管理

    上一篇博客主要聊了下redis cluster的部署配置,以及使用redis.trib.rb工具所需ruby环境的搭建.使用redis.trib.rb工具创建.查看集群相关信息等,回顾请参考https ...

  4. redis 集群新增节点,slots槽分配,删除节点, [ERR] Calling MIGRATE ERR Syntax error, try CLIENT (LIST | KILL | GET...

    redis reshard 重新分槽(slots) https://github.com/antirez/redis/issues/5029 redis 官方已确认该bug redis 集群重新(re ...

  5. redis cluster节点管理测试

    ####redis v3.2.0###添加节点:1.添加master节点 170 ./redis-trib.rb add-node 127.0.0.1:7007 127.0.0.1:7001 171 ...

  6. redis集群添加删除节点

    Redis3.0集群添加节点 1:首先把需要添加的节点启动 cd /usr/local/cluster/ mkdir 7006 cp /usr/local/cluster/redis.conf  /u ...

  7. Redis 集群环境添加节点失败问题

    最近在给公司网管系统Redis集群环境添加节点时候遇到一个问题,提示新增的Node不为空: [root@node00 src]# ./redis-trib.rb add-node --slave -- ...

  8. redis cluster 添加 删除 重分配 节点

    redis cluster配置好,并运行一段时间后,我们想添加节点,或者删除节点,该怎么办呢.  一,redis cluster命令 //集群(cluster) CLUSTER INFO 打印集群的信 ...

  9. element-ui组件,全选树节点,新增数据子节点数据,出现回填问题

    案情分析:全选后父节点被选中保存,在这个树节点下新增数据时,就会出现,也被选中,事实上数据是没有被选中,也就意味着权限未被配置,而显示是已经配置了,显然这个是一个bug 1.处理前,直接用下面的方法很 ...

随机推荐

  1. 关闭自动弹出照片自动弹出iTunes以及关闭手机照片流

    关闭自动弹出照片自动弹出iTunes以及关闭手机照片流 如何阻止iPhone连接Mac后自动弹出照片? 时间:2015/6/18 17:07:15来源:本站原创作者:Chenjh我要评论 很多新 iP ...

  2. Linux Python apache的cgi配置

    一.找到安装Apache的目录/usr/local/apache2/conf,并对httpd.conf配置文件进行修改 1.加载cgi模块 去掉注释: LoadModule cgid_module m ...

  3. highcharts 折线,饼状,条状综合图

    完整代码如下: <head> <meta http-equiv="Content-Type" content="text/html; charset=u ...

  4. 一个有趣的基于Django的调试插件--django-debug-toolbar

    django-debug-toolbar 介绍 django-debug-toolbar 是一组可配置的面板,可显示有关当前请求/响应的各种调试信息,并在单击时显示有关面板内容的更多详细信息. git ...

  5. hdu 2883(构图+最大流+压缩区间)

    kebab Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. python 网络爬虫框架scrapy使用说明

    1 创建项目scrapy startproject tutorial 2 定义Itemimport scrapyclass DmozItem(scrapy.Item):    title = scra ...

  7. Python—HTTP处理Gzip压缩数据

    HTTP 请求中包含Accept-encoding: gzip头信息可以告诉服务器,如果它有任何新数据要发送给我时,请以压缩的格式发送.如果服务器支持压缩,它将返回由 gzip 压缩的数据并且使用Co ...

  8. netbeans 开启调试

    在URL中加入一个参数 XDEBUG_SESSION_START=netbeans-xdebug

  9. SyntaxError: Non-ASCII character '\xe7' in file 9.py on line 13, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

    解决方法: #!/usr/bin/python #-*-coding:utf-8-*-

  10. 剑指offer-树中两个节点的最低公共祖先

    普通二叉树 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; ...