os: ubuntu 16.04
redis:4.0.9
ruby:2.4.4
ip规划
192.168.0.101 7000,7001,7002,7003
192.168.0.102 7000,7001,7002,7003
192.168.0.103 7000,7001,7002,7003
上一篇blog介绍了 add-node、reshard ,这篇blog介绍下 del-node
下面简单记录下删除 redis 实例的过程。
# /usr/redis/redis-4.0.9/src/redis-trib.rb check 192.168.0.101:7000
>>> Performing Cluster Check (using node 192.168.0.101:7000)
M: bae1665a3a55f5f2f2c224e1533118a1168b6a1d 192.168.0.101:7000
slots:1972-5460 (3489 slots) master
2 additional replica(s)
M: fbf3b7827137251d03638436d28a2a9b82cea44c 192.168.0.102:7000
slots:6896-10922 (4027 slots) master
2 additional replica(s)
S: f5a34cea79ae1614241eb489808b9309514fa8eb 192.168.0.101:7002
slots: (0 slots) slave
replicates fbf3b7827137251d03638436d28a2a9b82cea44c
S: b7ee4163c0d14e7c763a2c4072f10042c84e4ca6 192.168.0.103:7003
slots: (0 slots) slave
replicates 4a77a0134068e2d9f2734213ead14bf9bce2e072
S: 550f9347512ee841cf558ef254dbdf3b4379f6a9 192.168.0.103:7001
slots: (0 slots) slave
replicates bae1665a3a55f5f2f2c224e1533118a1168b6a1d
M: ca76bd2110000f6285360e1d0979ac14fec7f86a 192.168.0.103:7000
slots:12894-16383 (3490 slots) master
2 additional replica(s)
S: 179d2cc1d16d59c479df8536e7720977772e75c8 192.168.0.102:7003
slots: (0 slots) slave
replicates 4a77a0134068e2d9f2734213ead14bf9bce2e072
S: d93a37d9fb2e526d01a5f4c6b6b9743674656286 192.168.0.101:7001
slots: (0 slots) slave
replicates ca76bd2110000f6285360e1d0979ac14fec7f86a
S: 464b9cab8863085b4bff880eca339a9e7983898c 192.168.0.103:7002
slots: (0 slots) slave
replicates fbf3b7827137251d03638436d28a2a9b82cea44c
M: 4a77a0134068e2d9f2734213ead14bf9bce2e072 192.168.0.101:7003
slots:0-1971,5461-6895,10923-12893 (5378 slots) master
2 additional replica(s)
S: bcdecbdb2528f2953145aa08c82d8c4a9a89e0a0 192.168.0.102:7002
slots: (0 slots) slave
replicates ca76bd2110000f6285360e1d0979ac14fec7f86a
S: 141c2cf5b07da8c0d5b4b7c6dc42335d7638946f 192.168.0.102:7001
slots: (0 slots) slave
replicates bae1665a3a55f5f2f2c224e1533118a1168b6a1d
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
# /usr/redis/redis-4.0.9/src/redis-trib.rb info 192.168.0.101:7000
192.168.0.101:7000 (bae1665a...) -> 0 keys | 3489 slots | 2 slaves.
192.168.0.102:7000 (fbf3b782...) -> 0 keys | 4027 slots | 2 slaves.
192.168.0.103:7000 (ca76bd21...) -> 0 keys | 3490 slots | 2 slaves.
192.168.0.101:7003 (4a77a013...) -> 0 keys | 5378 slots | 2 slaves.
[OK] 0 keys in 4 masters.
0.00 keys per slot on average.
基本情况如下:
192.168.0.101:7000 > 192.168.0.102:7001,192.168.0.103:7001
192.168.0.102:7000 > 192.168.0.101:7002,192.168.0.103:7002
192.168.0.103:7000 > 192.168.0.101:7001,192.168.0.102:7002
192.168.0.101:7003 > 192.168.0.102:7003,192.168.0.103:7003
节点上有数据时是无法删除节点的!
节点上有数据时是无法删除节点的!
节点上有数据时是无法删除节点的!
必须事先使用 reshard 把数据移到其他节点上。详细操作请参考<
# redis-trib.rb reshared 192.168.0.101:7003
node1 节点上操作
# ruby --version
ruby 2.4.4p296 (2018-03-28 revision 63013) [x86_64-linux]
# gem list |grep -i redis
redis (3.3.3)
# gem uninstall redis --version 4.0.2
# gem install redis -v 3.3.3
移除 master 实例 192.168.0.101:7003
# /usr/redis/redis-4.0.9/src/redis-trib.rb
del-node host:port node_id
# /usr/redis/redis-4.0.9/src/redis-trib.rb del-node 192.168.0.101:7003 4a77a0134068e2d9f2734213ead14bf9bce2e072
>>> Removing node 4a77a0134068e2d9f2734213ead14bf9bce2e072 from cluster 192.168.0.101:7003
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
# /usr/redis/redis-4.0.9/src/redis-trib.rb check 192.168.0.102:7003
>>> Performing Cluster Check (using node 192.168.0.102:7003)
S: 179d2cc1d16d59c479df8536e7720977772e75c8 192.168.0.102:7003
slots: (0 slots) slave
replicates bae1665a3a55f5f2f2c224e1533118a1168b6a1d
S: 141c2cf5b07da8c0d5b4b7c6dc42335d7638946f 192.168.0.102:7001
slots: (0 slots) slave
replicates bae1665a3a55f5f2f2c224e1533118a1168b6a1d
S: 550f9347512ee841cf558ef254dbdf3b4379f6a9 192.168.0.103:7001
slots: (0 slots) slave
replicates bae1665a3a55f5f2f2c224e1533118a1168b6a1d
M: fbf3b7827137251d03638436d28a2a9b82cea44c 192.168.0.102:7000
slots:1213-1281,6896-10922 (4096 slots) master
2 additional replica(s)
S: bcdecbdb2528f2953145aa08c82d8c4a9a89e0a0 192.168.0.102:7002
slots: (0 slots) slave
replicates ca76bd2110000f6285360e1d0979ac14fec7f86a
S: f5a34cea79ae1614241eb489808b9309514fa8eb 192.168.0.101:7002
slots: (0 slots) slave
replicates fbf3b7827137251d03638436d28a2a9b82cea44c
S: 464b9cab8863085b4bff880eca339a9e7983898c 192.168.0.103:7002
slots: (0 slots) slave
replicates fbf3b7827137251d03638436d28a2a9b82cea44c
M: bae1665a3a55f5f2f2c224e1533118a1168b6a1d 192.168.0.101:7000
slots:0-606,1282-6895,10923-12893 (8192 slots) master
4 additional replica(s)
M: ca76bd2110000f6285360e1d0979ac14fec7f86a 192.168.0.103:7000
slots:607-1212,12894-16383 (4096 slots) master
2 additional replica(s)
S: d93a37d9fb2e526d01a5f4c6b6b9743674656286 192.168.0.101:7001
slots: (0 slots) slave
replicates ca76bd2110000f6285360e1d0979ac14fec7f86a
S: b7ee4163c0d14e7c763a2c4072f10042c84e4ca6 192.168.0.103:7003
slots: (0 slots) slave
replicates bae1665a3a55f5f2f2c224e1533118a1168b6a1d
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
# /usr/redis/redis-4.0.9/src/redis-trib.rb info 192.168.0.102:7003
192.168.0.102:7000 (fbf3b782...) -> 0 keys | 4096 slots | 2 slaves.
192.168.0.101:7000 (bae1665a...) -> 1 keys | 8192 slots | 4 slaves.
192.168.0.103:7000 (ca76bd21...) -> 0 keys | 4096 slots | 2 slaves.
[OK] 1 keys in 3 masters.
0.00 keys per slot on average.
可以看出之前为 192.168.0.101:7003 的slave 变为当前某个master 的slave。
移除 slave 实例 192.168.0.102:7003、192.168.0.103:7003
# /usr/redis/redis-4.0.9/src/redis-trib.rb del-node 192.168.0.102:7003 179d2cc1d16d59c479df8536e7720977772e75c8
>>> Removing node 179d2cc1d16d59c479df8536e7720977772e75c8 from cluster 192.168.0.102:7003
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
# /usr/redis/redis-4.0.9/src/redis-trib.rb del-node 192.168.0.103:7003 b7ee4163c0d14e7c763a2c4072f10042c84e4ca6
>>> Removing node b7ee4163c0d14e7c763a2c4072f10042c84e4ca6 from cluster 192.168.0.103:7003
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
# /usr/redis/redis-4.0.9/src/redis-trib.rb info 192.168.0.101:7000
192.168.0.101:7000 (bae1665a...) -> 1 keys | 8192 slots | 2 slaves.
192.168.0.102:7000 (fbf3b782...) -> 0 keys | 4096 slots | 2 slaves.
192.168.0.103:7000 (ca76bd21...) -> 0 keys | 4096 slots | 2 slaves.
[OK] 1 keys in 3 masters.
0.00 keys per slot on average.
可以看到 两个 salve 节点已经删除成功了。
参考:
http://www.redis.cn/topics/cluster-tutorial.html