LinuxEye - Linux系统教程

LinuxEye - Linux系统教程

当前位置: 主页 > Linux教程 >

Redis 3.0集群(2)

时间:2015-04-29 09:12来源:未知 编辑:linuxeye 点击:
添加Master节点到集群 按照Redis集群一的方式,创建端口为7006的新实例,并启动该实例 将7006添加到集群: redis-trib.rb add-node 127.0.0.1:7006 127.0.0.1:7000 node:新节

添加Master节点到集群

按照Redis集群一的方式,创建端口为7006的新实例,并启动该实例

  • 将7006添加到集群:

    redis-trib.rb add-node 127.0.0.1:7006 127.0.0.1:7000
     node:新节点没有包含任何数据, 因为它没有包含任何slot。新加入的加点是一个主节点, 当集群需要将某个从节点升级为新的主节点时, 这个新节点不会被选中。
  • 给新节点分配哈希槽:
    redis-trib.rb reshard 127.0.0.1:7000
    #根据提示选择要迁移的slot数量(ps:这里选择500)
    How many slots do you want to move (from 1 to 16384)? 500
    #选择要接受这些slot的node-id
    What is the receiving node ID? f51e26b5d5ff74f85341f06f28f125b7254e61bf
    #选择slot来源:
    #all表示从所有的master重新分配,
    #或者数据要提取slot的master节点id,最后用done结束
    Please enter all the source node IDs.
      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:3375be2ccc321932e8853234ffa87ee9fde973ff
    Source node #2:done
    #打印被移动的slot后,输入yes开始移动slot以及对应的数据.
    #Do you want to proceed with the proposed reshard plan (yes/no)? yes
    #结束
  • 查看操作结果:
    redis-cli -c -p 7000
    cluster nodes
    可以看到返回的集群信息中,7006拥有了0-999哈希槽。

添加Slave节点到集群

  • 按照Redis集群一的方式,创建端口为7007的新实例,并启动该实例
  • 将7007添加到集群:
    redis-trib.rb add-node 127.0.0.1:7007 127.0.0.1:7000
  • 设置为7006的slave:
    redis-cli -c -p 7007
    #参数为master节点的ID
    cluster replicate 2b9ebcbd627ff0fd7a7bbcc5332fb09e72788835

删除一个Slave节点

#redis-trib del-node ip:port '<node-id>'  
redis-trib.rb del-node 127.0.0.1:7007 'c7ee2fca17cb79fe3c9822ced1d4f6c5e169e378'

删除一个Master节点

删除master节点之前首先要使用reshard移除master的全部slot,然后再删除当前节点(目前只能把被删除master的slot迁移到一个节点上)

redis-trib.rb reshard 127.0.0.1:7006
#根据提示选择要迁移的slot数量(ps:这里选择500)
How many slots do you want to move (from 1 to 16384)? 500
#选择要接受这些slot的node-id
What is the receiving node ID? f51e26b5d5ff74f85341f06f28f125b7254e61bf
#选择slot来源:
#all表示从所有的master重新分配,
#或者数据要提取slot的master节点id,最后用done结束
Please enter all the source node IDs.
  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:3375be2ccc321932e8853234ffa87ee9fde973ff
Source node #2:done
#打印被移动的slot后,输入yes开始移动slot以及对应的数据.
#Do you want to proceed with the proposed reshard plan (yes/no)? yes
#结束
 
#删除空master节点
redis-trib.rb del-node 127.0.0.1:7006 'c7ee2fca17cb79fe3c9822ced1d4f6c5e169e378'

转载请保留固定链接: https://linuxeye.com/Linux/2464.html

------分隔线----------------------------
标签:Redis集群
栏目列表
推荐内容