redis--节点新增,切换,数据迁移

新增redis节点, redis版本为redis-3.0.7   ruby-2.2.2



添加主节点到集群命令: 

[xxxxxx src]# ./redis-trib.rb  add-node 192.168.76.116:6380 192.168.76.116:6379
>>> Adding node 192.168.76.116:6380 to cluster 192.168.76.116:6379
>>> Performing Cluster Check (using node 192.168.76.116:6379)
M: 0936588a1ea864fc020e40be4f22b557cf289471 192.168.76.116:6379
   slots: (0 slots) master
   0 additional replica(s)
M: ac0bed66e38ecb64e1fcf35363e773aab0a921ab 192.168.76.116:6382
   slots:0-16383 (16384 slots) master
   0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.76.116:6380 to make it join the cluster.
[OK] New node added correctly.
You have new mail in /var/spool/mail/root

命令解析: /redis-trib.rb  add-node 192.168.76.116:6380 192.168.76.116:6379  其中192.168.76.116:6380  需要添加的主节点, 为集群中已有的节点


添加从节点到集群: 


[xxxxxx src]# ./redis-trib.rb add-node --slave --master-id ac0bed66e38ecb64e1fcf35363e773aab0a921ab 192.168.76.116:6381 192.168.76.116:6382 
>>> Adding node 192.168.76.116:6381 to cluster 192.168.76.116:6382
>>> Performing Cluster Check (using node 192.168.76.116:6382)
M: ac0bed66e38ecb64e1fcf35363e773aab0a921ab 192.168.76.116:6382
   slots:0-16383 (16384 slots) master
   1 additional replica(s)
S: c6a480d33b94eb5396ec0d936542490171d49666 192.168.76.116:6383
   slots: (0 slots) slave
   replicates ac0bed66e38ecb64e1fcf35363e773aab0a921ab
S: 0fcf9d2d4f331a33dd319e8ee40d25595c38325a 192.168.76.116:6380
   slots: (0 slots) slave
   replicates 0936588a1ea864fc020e40be4f22b557cf289471
M: 0936588a1ea864fc020e40be4f22b557cf289471 192.168.76.116:6379
   slots: (0 slots) master
   1 additional replica(s)
M: 4c075686000e3050b38429cf95717253b2623dc9 192.168.76.116:6384
   slots: (0 slots) master
   0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.76.116:6381 to make it join the cluster.
Waiting for the cluster to join.
>>> Configure node as replica of 192.168.76.116:6382.
[OK] New node added correctly.
You have new mail in /var/spool/mail/root
[root@ndl-dg05 src]# 
[root@ndl-dg05 src]# 

命令解析: /redis-trib.rb add-node --slave --master-id ac0bed66e38ecb64e1fcf35363e773aab0a921ab 192.168.76.116:6381 192.168.76.116:6382 

其中 add-node --slave 表示添加的为从节点。  --master-id ac0bed66e38ecb64e1fcf35363e773aab0a921ab 指定主节点。  192.168.76.116:6381需要添加的从节点。

192.168.76.116:6382  集群中存在的任意节点


改变从节点的master 

[xxxxxx bin]# 
[root@ndl-dg05 bin]# ./redis-cli  -c -p 6381
127.0.0.1:6381> cluster nodes
0fcf9d2d4f331a33dd319e8ee40d25595c38325a 192.168.76.116:6380 slave 0936588a1ea864fc020e40be4f22b557cf289471 0 1505381033845 1 connected
c6a480d33b94eb5396ec0d936542490171d49666 192.168.76.116:6383 slave ac0bed66e38ecb64e1fcf35363e773aab0a921ab 0 1505381028844 4 connected
95e9f52c3c0f3aad3b58191ffedb8ea6adf1db61 192.168.76.116:6381 myself,slave ac0bed66e38ecb64e1fcf35363e773aab0a921ab 0 0 0 connected
0936588a1ea864fc020e40be4f22b557cf289471 192.168.76.116:6379 master - 0 1505381030844 1 connected
ac0bed66e38ecb64e1fcf35363e773aab0a921ab 192.168.76.116:6382 master - 0 1505381032846 4 connected 0-16383
4c075686000e3050b38429cf95717253b2623dc9 192.168.76.116:6384 master - 0 1505381031844 0 connected
127.0.0.1:6381> 
127.0.0.1:6381> cluster replicate 4c075686000e3050b38429cf95717253b2623dc9
OK
127.0.0.1:6381> quit
You have new mail in /var/spool/mail/root
[root@ndl-dg05 bin]# ./redis-cli  -c -p 6381
127.0.0.1:6381> cluster nodes
0fcf9d2d4f331a33dd319e8ee40d25595c38325a 192.168.76.116:6380 slave 0936588a1ea864fc020e40be4f22b557cf289471 0 1505381096899 1 connected
c6a480d33b94eb5396ec0d936542490171d49666 192.168.76.116:6383 slave ac0bed66e38ecb64e1fcf35363e773aab0a921ab 0 1505381094899 4 connected
95e9f52c3c0f3aad3b58191ffedb8ea6adf1db61 192.168.76.116:6381 myself,slave 4c075686000e3050b38429cf95717253b2623dc9 0 0 0 connected
0936588a1ea864fc020e40be4f22b557cf289471 192.168.76.116:6379 master - 0 1505381095899 1 connected
ac0bed66e38ecb64e1fcf35363e773aab0a921ab 192.168.76.116:6382 master - 0 1505381091899 4 connected 0-16383
4c075686000e3050b38429cf95717253b2623dc9 192.168.76.116:6384 master - 0 1505381093899 0 connected
127.0.0.1:6381> 

如上面展示

95e9f52c3c0f3aad3b58191ffedb8ea6adf1db61 192.168.76.116:6381 myself,slave ac0bed66e38ecb64e1fcf35363e773aab0a921ab 0 0 0 connected 切换之前是

192.168.76.116:6382 的从,切换之后是192.168.76.116:6384  的从。 

命令解析: 127.0.0.1:6381> cluster replicate 4c075686000e3050b38429cf95717253b2623dc9

其中 4c075686000e3050b38429cf95717253b2623dc9 为需要的主节点node id 


数据迁移,将192.168.76.116:6382 节点slot迁移10个槽位到192.168.76.116:6379

[xxxxxx src]# ./redis-trib.rb reshard 192.168.76.116:6379     ----最开始执行的命令 
>>> Performing Cluster Check (using node 192.168.76.116:6379)
M: 0936588a1ea864fc020e40be4f22b557cf289471 192.168.76.116:6379
   slots: (0 slots) master
   1 additional replica(s)
M: ac0bed66e38ecb64e1fcf35363e773aab0a921ab 192.168.76.116:6382
   slots:0-16383 (16384 slots) master
   1 additional replica(s)
S: c6a480d33b94eb5396ec0d936542490171d49666 192.168.76.116:6383
   slots: (0 slots) slave
   replicates ac0bed66e38ecb64e1fcf35363e773aab0a921ab
S: 0fcf9d2d4f331a33dd319e8ee40d25595c38325a 192.168.76.116:6380
   slots: (0 slots) slave
   replicates 0936588a1ea864fc020e40be4f22b557cf289471
S: 95e9f52c3c0f3aad3b58191ffedb8ea6adf1db61 192.168.76.116:6381
   slots: (0 slots) slave
   replicates 4c075686000e3050b38429cf95717253b2623dc9
M: 4c075686000e3050b38429cf95717253b2623dc9 192.168.76.116:6384
   slots: (0 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 10                        ---这个地方填写需要迁移的槽位数
What is the receiving node ID? 0936588a1ea864fc020e40be4f22b557cf289471    ----这个地方填写接受槽位的nodeid 
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:ac0bed66e38ecb64e1fcf35363e773aab0a921ab                    ---这个地方填写需要分出槽位的nodeid 
Source node #2:done                                                 ---这个地方选择done 代表着只从填写的Source node 获取slot 
Ready to move 10 slots.
  Source nodes:
    M: ac0bed66e38ecb64e1fcf35363e773aab0a921ab 192.168.76.116:6382
   slots:0-16383 (16384 slots) master
   1 additional replica(s)
  Destination node:
    M: 0936588a1ea864fc020e40be4f22b557cf289471 192.168.76.116:6379
   slots: (0 slots) master
   1 additional replica(s)
  Resharding plan:
    Moving slot 0 from ac0bed66e38ecb64e1fcf35363e773aab0a921ab
    Moving slot 1 from ac0bed66e38ecb64e1fcf35363e773aab0a921ab
    Moving slot 2 from ac0bed66e38ecb64e1fcf35363e773aab0a921ab
    Moving slot 3 from ac0bed66e38ecb64e1fcf35363e773aab0a921ab
    Moving slot 4 from ac0bed66e38ecb64e1fcf35363e773aab0a921ab
    Moving slot 5 from ac0bed66e38ecb64e1fcf35363e773aab0a921ab
    Moving slot 6 from ac0bed66e38ecb64e1fcf35363e773aab0a921ab
    Moving slot 7 from ac0bed66e38ecb64e1fcf35363e773aab0a921ab
    Moving slot 8 from ac0bed66e38ecb64e1fcf35363e773aab0a921ab
    Moving slot 9 from ac0bed66e38ecb64e1fcf35363e773aab0a921ab
Do you want to proceed with the proposed reshard plan (yes/no)? yes    --输入yes 表示同意
Moving slot 0 from 192.168.76.116:6382 to 192.168.76.116:6379: 
Moving slot 1 from 192.168.76.116:6382 to 192.168.76.116:6379: 
Moving slot 2 from 192.168.76.116:6382 to 192.168.76.116:6379: 
Moving slot 3 from 192.168.76.116:6382 to 192.168.76.116:6379: 
Moving slot 4 from 192.168.76.116:6382 to 192.168.76.116:6379: 
Moving slot 5 from 192.168.76.116:6382 to 192.168.76.116:6379: 
Moving slot 6 from 192.168.76.116:6382 to 192.168.76.116:6379: 
Moving slot 7 from 192.168.76.116:6382 to 192.168.76.116:6379: 
Moving slot 8 from 192.168.76.116:6382 to 192.168.76.116:6379: 
Moving slot 9 from 192.168.76.116:6382 to 192.168.76.116:6379: 
You have new mail in /var/spool/mail/root
[root@ndl-dg05 src]#  


迁移后检测:

127.0.0.1:6381> cluster nodes 
0fcf9d2d4f331a33dd319e8ee40d25595c38325a 192.168.76.116:6380 slave 0936588a1ea864fc020e40be4f22b557cf289471 0 1505382099974 7 connected
c6a480d33b94eb5396ec0d936542490171d49666 192.168.76.116:6383 slave ac0bed66e38ecb64e1fcf35363e773aab0a921ab 0 1505382096973 4 connected
95e9f52c3c0f3aad3b58191ffedb8ea6adf1db61 192.168.76.116:6381 myself,slave 4c075686000e3050b38429cf95717253b2623dc9 0 0 0 connected
0936588a1ea864fc020e40be4f22b557cf289471 192.168.76.116:6379 master - 0 1505382100976 7 connected 0-9
ac0bed66e38ecb64e1fcf35363e773aab0a921ab 192.168.76.116:6382 master - 0 1505382097973 4 connected 10-16383
4c075686000e3050b38429cf95717253b2623dc9 192.168.76.116:6384 master - 0 1505382098974 0 connected
127.0.0.1:6381> 

 其中0936588a1ea864fc020e40be4f22b557cf289471 192.168.76.116:6379 master - 0 1505382100976 7 connected 0-9 表示迁移成功




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值