Chinaunix首页 | 论坛 | 博客

东南西北风andyhuang.blog.chinaunix.net

脚踏实地,一步一个脚印!

  • 博客访问: 2813279
  • 博文数量: 717
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 9933
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(717)

文章存档

2018年(24)

2017年(75)

2016年(48)

2015年(48)

2014年(169)

2013年(52)

2012年(177)

2011年(93)

2010年(30)

分类: 数据库开发技术

2018-01-18 15:04:57


1.查看集群情况
[root@pxc01 src]# ./redis-trib.rb check 192.168.56.91:6379
>>> Performing Cluster Check (using node 192.168.56.91:6379)
M: def4ff42e3c7759538d0273cc64d9a17cdd129b4 192.168.56.91:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: 9fb8db06a065d3c73b226b6499de167b0f078c1a 192.168.56.92:6379
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: a6e3625a31809a7cde6de1371f00b606c24966cc 192.168.56.93:7379
   slots: (0 slots) slave
   replicates 0aedad523787113cdbccc449f7651219ffb336fd
S: 3b53f11a7aaa49b89df6297062fd4e9581944cfa 192.168.56.91:7379
   slots: (0 slots) slave
   replicates 9fb8db06a065d3c73b226b6499de167b0f078c1a
S: f4be871dd3b25f1e1ec2de0df5f281b72bc54af3 192.168.56.92:7379
   slots: (0 slots) slave
   replicates def4ff42e3c7759538d0273cc64d9a17cdd129b4
M: 0aedad523787113cdbccc449f7651219ffb336fd 192.168.56.93:6379
   slots:10923-16383 (5461 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.

M代表主节点,S代表从节点,S栏replicates对应的ID,就是该从节点对应主节点的ID

2.删除从节点
./redis-trib.rb del-node 192.168.56.93:7379 'a6e3625a31809a7cde6de1371f00b606c24966cc'
./redis-trib.rb del-node 192.168.56.91:7379 '3b53f11a7aaa49b89df6297062fd4e9581944cfa'
./redis-trib.rb del-node 192.168.56.92:7379 'f4be871dd3b25f1e1ec2de0df5f281b72bc54af3'
删除从节点比较简单,以为不需要考虑slot移除情况

[root@pxc01 src]# ./redis-trib.rb check 192.168.56.91:6379
>>> Performing Cluster Check (using node 192.168.56.91:6379)
M: def4ff42e3c7759538d0273cc64d9a17cdd129b4 192.168.56.91:6379
   slots:0-5460 (5461 slots) master
   0 additional replica(s)
M: 9fb8db06a065d3c73b226b6499de167b0f078c1a 192.168.56.92:6379
   slots:5461-10922 (5462 slots) master
   0 additional replica(s)
M: 0aedad523787113cdbccc449f7651219ffb336fd 192.168.56.93:6379
   slots:10923-16383 (5461 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.
[root@pxc01 src]# 

删除之后发现集群里没有从节点了。


3.删除主节点
删除主节点之前需要将该节点的slot迁移到其他主节点
[root@pxc01 src]# ./redis-trib.rb reshard 192.168.56.92:6379
>>> Performing Cluster Check (using node 192.168.56.92:6379)
M: 9fb8db06a065d3c73b226b6499de167b0f078c1a 192.168.56.92:6379
   slots:5461-10922 (5462 slots) master
   0 additional replica(s)
M: 0aedad523787113cdbccc449f7651219ffb336fd 192.168.56.93:6379
   slots: (0 slots) master
   0 additional replica(s)
M: def4ff42e3c7759538d0273cc64d9a17cdd129b4 192.168.56.91:6379
   slots:0-5460,10923-16383 (10922 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.
How many slots do you want to move (from 1 to 16384)? 5462 ##需要移除slot的数量
What is the receiving node ID? def4ff42e3c7759538d0273cc64d9a17cdd129b4 ##接收移除slot的节点ID
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:9fb8db06a065d3c73b226b6499de167b0f078c1a ##移除节点的ID
Source node #2:done   

[root@pxc01 src]# ./redis-trib.rb reshard 192.168.56.93:6379
输出略...

[root@pxc01 src]# ./redis-trib.rb check 192.168.56.91:6379
>>> Performing Cluster Check (using node 192.168.56.91:6379)
M: def4ff42e3c7759538d0273cc64d9a17cdd129b4 192.168.56.91:6379
   slots:0-16383 (16384 slots) master
   0 additional replica(s)
M: 9fb8db06a065d3c73b226b6499de167b0f078c1a 192.168.56.92:6379
   slots: (0 slots) master
   0 additional replica(s)
M: 0aedad523787113cdbccc449f7651219ffb336fd 192.168.56.93:6379
   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.

查看节点情况,192.168.56.92:6379,192.168.56.92:6379的slot数量为0了,全部迁移到192.168.56.91:6379了,看到16384 slots

接着删除相应的主节点
./redis-trib.rb del-node 192.168.56.92:6379 '9fb8db06a065d3c73b226b6499de167b0f078c1a'
./redis-trib.rb del-node 192.168.56.93:6379 '0aedad523787113cdbccc449f7651219ffb336fd'
[root@pxc01 src]# ./redis-trib.rb check 192.168.56.91:6379
>>> Performing Cluster Check (using node 192.168.56.91:6379)
M: def4ff42e3c7759538d0273cc64d9a17cdd129b4 192.168.56.91:6379
   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.
看到只剩下192.168.56.91:6379一个节点了.




阅读(3128) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册