redis linux-集群新增删除节点流程

一。添加主节点

打开/usr/local/redis-3.2.7/cluster

        mkdir 6385

    #复制redis.conf配置文件并把端口改成6385

启动新增节点:./redis-server /usr/local/redis-3.2.7/cluster/6385/redis.conf

查看节点ps -ef | grep redis


添加节点

 打开/usr/local/redis-3.2.7/src执行./redis-trib.rb add-node 127.0.0.1:6385 127.0.0.1:6384

127.0.0.1:6385为新增节点

127.0.0.1:6384为已有集群中任何节点

出现以下信息表示新增成功


[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 120.77.61.47:6385 to make it join the cluster.
[OK] New node added correctly.


查看新节点状态:./redis-trib.rb check 127.0.0.1:6385


重新分配slots

./redis-trib.rb reshard 127.0.0.1:6384

127.0.0.1:6384为集群中任意节点


出现How many slots do you want to move (from 1 to 16384)?   时我们有4个master就平均分配输入16384/4=4096

出现What is the receiving node ID? 输入6835的id:ee3efb90e5ac0725f15238a64fc60a18a71205d7

出现Source node #1:时,如果不指定特定id直接输入all从所有节点中抽取

确认分配后结果:./redis-trib.rb check 127.0.0.1:6385

看到slots分配完毕这添加结束

二。添加从节点

打开/usr/local/redis-3.2.7/cluster

        mkdir 6386

    #复制redis.conf配置文件并把端口改成6386

启动新增节点:./redis-server /usr/local/redis-3.2.7/cluster/6386/redis.conf

查看节点ps -ef | grep redis

添加节点

 打开/usr/local/redis-3.2.7/src执行./redis-trib.rb add-node --slave 127.0.0.1:6386  127.0.0.1:6385

127.0.0.1:6386 为从节点

127.0.0.1:6385为要添加到的目标主节点


出现以下信息表示成功

[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Automatically selected master 127.0.0.1:6385
>>> Send CLUSTER MEET to node 127.0.0.1:6386 to make it join the cluster.
Waiting for the cluster to join.
>>> Configure node as replica of 127.0.0.1:6385.
[OK] New node added correctly.


查看结果./redis-trib.rb check 127.0.0.1:6386


三.删除节点(删除顺序是先删从节点再删除主节点)

   删除从节点./redis-trib.rb del-node 127.0.0.1:6386 b51de0185386c80b73fbe87a68b1b580bb558b4e


>>> Removing node b51de0185386c80b73fbe87a68b1b580bb558b4e from cluster 127.0.0.1:6386
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

查看结果./redis-trib.rb check 127.0.0.1:6385发现已经没有6386节点


 删除主节点:(因为在主节点中存放着数据,所以我们在删除之前,要把这些数据迁移走,并且把该节点上的哈希槽分配到其他主节点上)

移动哈希槽./redis-trib.rb reshard 127.0.0.1:6385

出现How many slots do you want to move (from 1 to 16384)? 由于6385上有4096个槽所以输入4096全部移除

出现What is the receiving node ID?选择要移动到的主节点

Source node #1:03ccad2ba5dd1e062464bc7590400441fafb63f2 //被删除master的node-id  
Source node #2:done 

查看结果./redis-trib.rb check 127.0.0.1:6385如果没有哈希槽就执行下一步

执行:./redis-trib.rb del-node 127.0.0.1:6385 61f786c40bcc170006a440abd7dc773e6dd15a19

查看结果./redis-trib.rb check 127.0.0.1:6385发现已经没有6385节点


错误处理:

[WARNING] Node 120.77.61.47:6379 has slots in migrating state (2156).
[WARNING] Node 120.77.61.47:6380 has slots in importing state (2156).
[WARNING] The following slots are open: 2156


使用./redis-trib.rb fix ./redis-trib.rb fix 127.0.0.1:6380修复

可以登录到相应的节点./redis-cli -h 127.0.0.1 -p 6380,使用命令“cluster setslot 2156 stable”修改,参数2156为问题显示的slot的ID


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值