redis集群工具创建集群
手动搭建集群需要很多步骤,当集群节点众多时,必然会加大搭建集群的复杂度和运维成本,因此官方提供了redis-trib.rb
的工具方便我们快速搭建集群
redis-trib.rb
是采用ruby实现的redis集群管理工具,内部通过cluster相关命令帮我们简化集群,创建,检查.槽迁移和均衡等常见运维操作,使用前要安装ruby依赖环境
安装ruby环境
[root@db01 ~]# yum install -y rubygems
[root@db01 ~]# gem sources --remove https://rubygems.org/ ##移除ruby国外源
[root@db01 ~]# gem sources -a https://mirrors.aliyun.com/rubygems/ ##添加国内阿里云源
[root@db01 ~]# gem update - system ###更新ruby系统
[root@db01 ~]# gem install redis -v 3.3.5 ##安装ruby环境的redis依赖包
清除原先的数据
在三台节点操作
pkill redis
rm -rf /data/redis_cluster/redis_6380/*
rm -rf /data/redis_cluster/redis_6381/*
再启动redis的节点
bash redis_shell.sh start 6380
bash redis_shell.sh start 6381
开始创建集群
事先准备三台主机每台主机安装2个redis实例,redis实例的安装可以参考我之前的redis文章
https://www.jianshu.com/p/f41862328ce4
在安装有ruby环境的54主机执行
[root@db01 src]# ./redis-trib.rb create --replicas 1 172.16.210.53:6380 172.16.210.54:6380 172.16.210.55:6380 172.16.210.53:6381 172.16.210.54:6381 172.16.210.55:6381
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
172.16.210.53:6380
172.16.210.54:6380
172.16.210.55:6380
Adding replica 172.16.210.54:6381 to 172.16.210.53:6380
Adding replica 172.16.210.53:6381 to 172.16.210.54:6380
Adding replica 172.16.210.55:6381 to 172.16.210.55:6380
M: 4f956397aa4ba097b636b60b35071fff2615f1d7 172.16.210.53:6380
slots:0-5460 (5461 slots) master
M: 4526d594b0ff88934d29e8224f8a2ea7cf977e9f 172.16.210.54:6380
slots:5461-10922 (5462 slots) master
M: 4b5966c3f4d940d7606166ad0f3fb1279f258095 172.16.210.55:6380
slots:10923-16383 (5461 slots) master
S: 48d7fe07cea7afcea50f5f37c762808edcdab1c7 172.16.210.53:6381
replicates 4526d594b0ff88934d29e8224f8a2ea7cf977e9f
S: 8ef420d0bea2dd420c94d4db3d4c742166cf1be7 172.16.210.54:6381
replicates 4f956397aa4ba097b636b60b35071fff2615f1d7
S: aa513b1e7245d69b64af0c79d8eea2f467ad9f65 172.16.210.55:6381
replicates 4b5966c3f4d940d7606166ad0f3fb1279f258095
Can I set the above configuration? (type 'yes' to accept): yes ##此处输入yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join..
>>> Performing Cluster Check (using node 172.16.210.53:6380)
M: 4f956397aa4ba097b636b60b35071fff2615f1d7 172.16.210.53:6380
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 4526d594b0ff88934d29e8224f8a2ea7cf977e9f 172.16.210.54:6380
slots:5461-10922 (5462 slots) master
1 additional replica(s)
M: 4b5966c3f4d940d7606166ad0f3fb1279f258095 172.16.210.55:6380
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 8ef420d0bea2dd420c94d4db3d4c742166cf1be7 172.16.210.54:6381
slots: (0 slots) slave
replicates 4f956397aa4ba097b636b60b35071fff2615f1d7
S: 48d7fe07cea7afcea50f5f37c762808edcdab1c7 172.16.210.53:6381
slots: (0 slots) slave
replicates 4526d594b0ff88934d29e8224f8a2ea7cf977e9f
S: aa513b1e7245d69b64af0c79d8eea2f467ad9f65 172.16.210.55:6381
slots: (0 slots) slave
replicates 4b5966c3f4d940d7606166ad0f3fb1279f258095
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
命令解析:
create
创建集群
replicas
复制
1 代表的是每一个节点都有个复制节点,然后再把主节点写在命令的前边,复制节点写在命令的后边
登录集群查看状态
172.16.210.53:6380> CLUSTER INFO
cluster_state:ok ##状态是ok的
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_sent:195
cluster_stats_messages_received:195
172.16.210.53:6380> CLUSTER NODES
4526d594b0ff88934d29e8224f8a2ea7cf977e9f 172.16.210.54:6380 master - 0 1592184209014 2 connected 5461-10922
4b5966c3f4d940d7606166ad0f3fb1279f258095 172.16.210.55:6380 master - 0 1592184205006 3 connected 10923-16383
4f956397aa4ba097b636b60b35071fff2615f1d7 172.16.210.53:6380 myself,master - 0 0 1 connected 0-5460
8ef420d0bea2dd420c94d4db3d4c742166cf1be7 172.16.210.54:6381 slave 4f956397aa4ba097b636b60b35071fff2615f1d7 0 1592184208011 5 connected
48d7fe07cea7afcea50f5f37c762808edcdab1c7 172.16.210.53:6381 slave 4526d594b0ff88934d29e8224f8a2ea7cf977e9f 0 1592184210016 4 connected
aa513b1e7245d69b64af0c79d8eea2f467ad9f65 172.16.210.55:6381 slave 4b5966c3f4d940d7606166ad0f3fb1279f258095 0 1592184206007 6 connected
但此时我们的复制关系还是有点问题的.我们的55从节点复制的是55主节点,这样当55这一台机挂了的时候,我们的主从复制都会挂,所以我们还需要调整一下复制关系
设置54的从节点复制55的主节点
[root@db02 ~]# bash redis_shell.sh login 6381
172.16.210.54:6381> CLUSTER NODES
4526d594b0ff88934d29e8224f8a2ea7cf977e9f 172.16.210.54:6380 master - 0 1592185238148 2 connected 5461-10922
48d7fe07cea7afcea50f5f37c762808edcdab1c7 172.16.210.53:6381 slave 4526d594b0ff88934d29e8224f8a2ea7cf977e9f 0 1592185240152 4 connected
4f956397aa4ba097b636b60b35071fff2615f1d7 172.16.210.53:6380 master - 0 1592185239150 1 connected 0-5460
4b5966c3f4d940d7606166ad0f3fb1279f258095 172.16.210.55:6380 master - 0 1592185241154 3 connected 10923-16383
aa513b1e7245d69b64af0c79d8eea2f467ad9f65 172.16.210.55:6381 slave 4b5966c3f4d940d7606166ad0f3fb1279f258095 0 1592185242156 6 connected
8ef420d0bea2dd420c94d4db3d4c742166cf1be7 172.16.210.54:6381 myself,slave 4f956397aa4ba097b636b60b35071fff2615f1d7 0 0 5 connected
172.16.210.54:6381> CLUSTER REPLICATE 4b5966c3f4d940d7606166ad0f3fb1279f258095
OK
设置55的从节点复制53的主节点
[root@db03 ~]# bash redis_shell.sh login 6381
172.16.210.55:6381> CLUSTER NODES
4f956397aa4ba097b636b60b35071fff2615f1d7 172.16.210.53:6380 master - 0 1592185315247 1 connected 0-5460
4526d594b0ff88934d29e8224f8a2ea7cf977e9f 172.16.210.54:6380 master - 0 1592185313243 2 connected 5461-10922
4b5966c3f4d940d7606166ad0f3fb1279f258095 172.16.210.55:6380 master - 0 1592185312242 3 connected 10923-16383
8ef420d0bea2dd420c94d4db3d4c742166cf1be7 172.16.210.54:6381 slave 4b5966c3f4d940d7606166ad0f3fb1279f258095 0 1592185314245 5 connected
aa513b1e7245d69b64af0c79d8eea2f467ad9f65 172.16.210.55:6381 myself,slave 4b5966c3f4d940d7606166ad0f3fb1279f258095 0 0 6 connected
48d7fe07cea7afcea50f5f37c762808edcdab1c7 172.16.210.53:6381 slave 4526d594b0ff88934d29e8224f8a2ea7cf977e9f 0 1592185316250 4 connected
172.16.210.55:6381> CLUSTER REPLICATE 4f956397aa4ba097b636b60b35071fff2615f1d7
OK
再次查看状态
[root@db01 ~]# redis-cli -c -h 172.16.210.53 -p 6380
172.16.210.53:6380> CLUSTER INFO
cluster_state:ok ##状态ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_sent:2852
cluster_stats_messages_received:2852
172.16.210.53:6380> CLUSTER NODES
4526d594b0ff88934d29e8224f8a2ea7cf977e9f 172.16.210.54:6380 master - 0 1592185467219 2 connected 5461-10922
4b5966c3f4d940d7606166ad0f3fb1279f258095 172.16.210.55:6380 master - 0 1592185468221 3 connected 10923-16383
4f956397aa4ba097b636b60b35071fff2615f1d7 172.16.210.53:6380 myself,master - 0 0 1 connected 0-5460
8ef420d0bea2dd420c94d4db3d4c742166cf1be7 172.16.210.54:6381 slave 4b5966c3f4d940d7606166ad0f3fb1279f258095 0 1592185469224 5 connected
48d7fe07cea7afcea50f5f37c762808edcdab1c7 172.16.210.53:6381 slave 4526d594b0ff88934d29e8224f8a2ea7cf977e9f 0 1592185463208 4 connected
aa513b1e7245d69b64af0c79d8eea2f467ad9f65 172.16.210.55:6381 slave 4f956397aa4ba097b636b60b35071fff2615f1d7 0 1592185466216 6 connected
可以看到状态是ok的,然后我们的主从复制关系也是配置理想的
也可以用集群工具查看状态是否正常
[root@db01 src]# ./redis-trib.rb check 172.16.210.53:6380
>>> Performing Cluster Check (using node 172.16.210.53:6380)
M: 4f956397aa4ba097b636b60b35071fff2615f1d7 172.16.210.53:6380
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 4526d594b0ff88934d29e8224f8a2ea7cf977e9f 172.16.210.54:6380
slots:5461-10922 (5462 slots) master
1 additional replica(s)
M: 4b5966c3f4d940d7606166ad0f3fb1279f258095 172.16.210.55:6380
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 8ef420d0bea2dd420c94d4db3d4c742166cf1be7 172.16.210.54:6381
slots: (0 slots) slave
replicates 4b5966c3f4d940d7606166ad0f3fb1279f258095
S: 48d7fe07cea7afcea50f5f37c762808edcdab1c7 172.16.210.53:6381
slots: (0 slots) slave
replicates 4526d594b0ff88934d29e8224f8a2ea7cf977e9f
S: aa513b1e7245d69b64af0c79d8eea2f467ad9f65 172.16.210.55:6381
slots: (0 slots) slave
replicates 4f956397aa4ba097b636b60b35071fff2615f1d7
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
检查节点误差是否平均
[root@db01 src]# ./redis-trib.rb rebalance 172.16.210.53:6380
>>> Performing Cluster Check (using node 172.16.210.53:6380)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
*** No rebalancing needed! All nodes are within the 2.0% threshold.
redis集群工具扩容

在53主机创建2个新节点
mkdir -p /opt/redis_cluster/redis_{6390,6391}/{conf,pid,logs} ##创建配置目录
mkdir -p /data/redis_cluster/redis_{6390,6391} ##创建数据 目录
cp redis_6380/conf/redis_6380.conf redis_6390/conf/redis_6390.conf
cp redis_6381/conf/redis_6381.conf redis_6391/conf/redis_6391.conf
sed -i 's#6380#6390#g' redis_6390/conf/redis_6390.conf
sed -i 's#6381#6391#g' redis_6391/conf/redis_6391.conf
启动节点
[root@db01 ~]# bash redis_shell.sh start 6390
[root@db01 ~]# bash redis_shell.sh start 6391
使用工具发现节点
[root@db01 ~]# cd /opt/redis_cluster/redis/src/
[root@db01 src]# ./redis-trib.rb add-node 172.16.210.53:6390 172.16.210.53:6380
>>> Adding node 172.16.210.53:6390 to cluster 172.16.210.53:6380
>>> Performing Cluster Check (using node 172.16.210.53:6380)
M: 4f956397aa4ba097b636b60b35071fff2615f1d7 172.16.210.53:6380
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 4526d594b0ff88934d29e8224f8a2ea7cf977e9f 172.16.210.54:6380
slots:5461-10922 (5462 slots) master
1 additional replica(s)
M: 4b5966c3f4d940d7606166ad0f3fb1279f258095 172.16.210.55:6380
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 8ef420d0bea2dd420c94d4db3d4c742166cf1be7 172.16.210.54:6381
slots: (0 slots) slave
replicates 4b5966c3f4d940d7606166ad0f3fb1279f258095
S: 48d7fe07cea7afcea50f5f37c762808edcdab1c7 172.16.210.53:6381
slots: (0 slots) slave
replicates 4526d594b0ff88934d29e8224f8a2ea7cf977e9f
S: aa513b1e7245d69b64af0c79d8eea2f467ad9f65 172.16.210.55:6381
slots: (0 slots) slave
replicates 4f956397aa4ba097b636b60b35071fff2615f1d7
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 172.16.210.53:6390 to make it join the cluster.
[OK] New node added correctly.
[root@db01 src]# ./redis-trib.rb add-node 172.16.210.53:6391 172.16.210.55:6381 ##后面的地址不管是集群中任意一个地址都可以
>>> Adding node 172.16.210.53:6391 to cluster 172.16.210.55:6380
>>> Performing Cluster Check (using node 172.16.210.55:6380)
M: 4b5966c3f4d940d7606166ad0f3fb1279f258095 172.16.210.55:6380
slots:10923-16383 (5461 slots) master
1 additional replica(s)
M: 4f956397aa4ba097b636b60b35071fff2615f1d7 172.16.210.53:6380
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: 48d7fe07cea7afcea50f5f37c762808edcdab1c7 172.16.210.53:6381
slots: (0 slots) slave
replicates 4526d594b0ff88934d29e8224f8a2ea7cf977e9f
M: 4526d594b0ff88934d29e8224f8a2ea7cf977e9f 172.16.210.54:6380
slots:5461-10922 (5462 slots) master
1 additional replica(s)
M: e38c5aba13fda70cbf5b3ab0488ffa9cf8a40ca5 172.16.210.53:6390
slots: (0 slots) master
0 additional replica(s)
S: aa513b1e7245d69b64af0c79d8eea2f467ad9f65 172.16.210.55:6381
slots: (0 slots) slave
replicates 4f956397aa4ba097b636b60b35071fff2615f1d7
S: 8ef420d0bea2dd420c94d4db3d4c742166cf1be7 172.16.210.54:6381
slots: (0 slots) slave
replicates 4b5966c3f4d940d7606166ad0f3fb1279f258095
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 172.16.210.53:6391 to make it join the cluster.
[OK] New node added correctly.
注意:由于我们的添加节点是使用工具添加的,所以主机之间主从复制关系可能不理想,可以根据自己的环境情况调整主从关系
调整主从关系命令:CLUSTER REPLICATE 节点id
分配槽位给新加入的节点
[root@db01 src]# ./redis-trib.rb reshard 172.16.210.53:6380
>>> Performing Cluster Check (using node 172.16.210.53:6380)
M: 4f956397aa4ba097b636b60b35071fff2615f1d7 172.16.210.53:6380
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 4526d594b0ff88934d29e8224f8a2ea7cf977e9f 172.16.210.54:6380
slots:5461-10922 (5462 slots) master
1 additional replica(s)
M: 4b5966c3f4d940d7606166ad0f3fb1279f258095 172.16.210.55:6380
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 8ef420d0bea2dd420c94d4db3d4c742166cf1be7 172.16.210.54:6381
slots: (0 slots) slave
replicates 4b5966c3f4d940d7606166ad0f3fb1279f258095
S: 48d7fe07cea7afcea50f5f37c762808edcdab1c7 172.16.210.53:6381
slots: (0 slots) slave
replicates 4526d594b0ff88934d29e8224f8a2ea7cf977e9f
S: aa513b1e7245d69b64af0c79d8eea2f467ad9f65 172.16.210.55:6381
slots: (0 slots) slave
replicates 4f956397aa4ba097b636b60b35071fff2615f1d7
M: e38c5aba13fda70cbf5b3ab0488ffa9cf8a40ca5 172.16.210.53:6390
slots: (0 slots) master
0 additional replica(s)
M: 0259881d9b4f3a50d9c9d81b7b64188bbdccdef2 172.16.210.53:6391
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.
How many slots do you want to move (from 1 to 16384)? 4096 ##每个节点想分配多少个槽位
What is the receiving node ID? e38c5aba13fda70cbf5b3ab0488ffa9cf8a40ca5 ##设置想要接受槽位的节点ID(6390)
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:all ##那个主节点发送槽位,这里我们输入all,所有主节点
--
--
Moving slot 12286 from 4b5966c3f4d940d7606166ad0f3fb1279f258095
Moving slot 12287 from 4b5966c3f4d940d7606166ad0f3fb1279f258095
Do you want to proceed with the proposed reshard plan (yes/no)? yes ##输入yes开始迁移

槽位迁移成功
reids工具收缩节点


操作步骤:
[root@db01 ~]# cd /opt/redis_cluster/redis/src/
[root@db01 src]# ./redis-trib.rb reshard 172.16.210.53:6380
>>> Performing Cluster Check (using node 172.16.210.53:6380)
M: 4f956397aa4ba097b636b60b35071fff2615f1d7 172.16.210.53:6380
slots:1365-5460 (4096 slots) master
1 additional replica(s)
M: 4526d594b0ff88934d29e8224f8a2ea7cf977e9f 172.16.210.54:6380
slots:6827-10922 (4096 slots) master
1 additional replica(s)
M: 4b5966c3f4d940d7606166ad0f3fb1279f258095 172.16.210.55:6380
slots:12288-16383 (4096 slots) master
1 additional replica(s)
S: 8ef420d0bea2dd420c94d4db3d4c742166cf1be7 172.16.210.54:6381
slots: (0 slots) slave
replicates 4b5966c3f4d940d7606166ad0f3fb1279f258095
S: 48d7fe07cea7afcea50f5f37c762808edcdab1c7 172.16.210.53:6381
slots: (0 slots) slave
replicates 4526d594b0ff88934d29e8224f8a2ea7cf977e9f
S: aa513b1e7245d69b64af0c79d8eea2f467ad9f65 172.16.210.55:6381
slots: (0 slots) slave
replicates 4f956397aa4ba097b636b60b35071fff2615f1d7
M: e38c5aba13fda70cbf5b3ab0488ffa9cf8a40ca5 172.16.210.53:6390
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
0 additional replica(s)
M: 0259881d9b4f3a50d9c9d81b7b64188bbdccdef2 172.16.210.53:6391
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.
How many slots do you want to move (from 1 to 16384)? 1365 ##设置要丟出去的槽数量
What is the receiving node ID? 4f956397aa4ba097b636b60b35071fff2615f1d7 ##设置接受的节点id(53的6380)
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:e38c5aba13fda70cbf5b3ab0488ffa9cf8a40ca5 ##设置发送的节点(53的6390)
Source node #2:done ##输入done
Do you want to proceed with the proposed reshard plan (yes/no)? yes ##输入yes确认
[root@db01 src]# ./redis-trib.rb reshard 172.16.210.53:6380
>>> Performing Cluster Check (using node 172.16.210.53:6380)
M: 4f956397aa4ba097b636b60b35071fff2615f1d7 172.16.210.53:6380
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 4526d594b0ff88934d29e8224f8a2ea7cf977e9f 172.16.210.54:6380
slots:6827-10922 (4096 slots) master
1 additional replica(s)
M: 4b5966c3f4d940d7606166ad0f3fb1279f258095 172.16.210.55:6380
slots:12288-16383 (4096 slots) master
1 additional replica(s)
S: 8ef420d0bea2dd420c94d4db3d4c742166cf1be7 172.16.210.54:6381
slots: (0 slots) slave
replicates 4b5966c3f4d940d7606166ad0f3fb1279f258095
S: 48d7fe07cea7afcea50f5f37c762808edcdab1c7 172.16.210.53:6381
slots: (0 slots) slave
replicates 4526d594b0ff88934d29e8224f8a2ea7cf977e9f
S: aa513b1e7245d69b64af0c79d8eea2f467ad9f65 172.16.210.55:6381
slots: (0 slots) slave
replicates 4f956397aa4ba097b636b60b35071fff2615f1d7
M: e38c5aba13fda70cbf5b3ab0488ffa9cf8a40ca5 172.16.210.53:6390
slots:5461-6826,10923-12287 (2731 slots) master
0 additional replica(s)
M: 0259881d9b4f3a50d9c9d81b7b64188bbdccdef2 172.16.210.53:6391
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.
How many slots do you want to move (from 1 to 16384)? 1365 ##设置要丟出去的槽数量
What is the receiving node ID? 4526d594b0ff88934d29e8224f8a2ea7cf977e9f ##设置接受的节点id(54的6380)
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:e38c5aba13fda70cbf5b3ab0488ffa9cf8a40ca5 ###设置发送的节点(53的6390)
Source node #2:done ##输入done
Do you want to proceed with the proposed reshard plan (yes/no)? yes ##输入yes来确认
[root@db01 src]# ./redis-trib.rb reshard 172.16.210.53:6380
>>> Performing Cluster Check (using node 172.16.210.53:6380)
M: 4f956397aa4ba097b636b60b35071fff2615f1d7 172.16.210.53:6380
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 4526d594b0ff88934d29e8224f8a2ea7cf977e9f 172.16.210.54:6380
slots:5461-6825,6827-10922 (5461 slots) master
1 additional replica(s)
M: 4b5966c3f4d940d7606166ad0f3fb1279f258095 172.16.210.55:6380
slots:12288-16383 (4096 slots) master
1 additional replica(s)
S: 8ef420d0bea2dd420c94d4db3d4c742166cf1be7 172.16.210.54:6381
slots: (0 slots) slave
replicates 4b5966c3f4d940d7606166ad0f3fb1279f258095
S: 48d7fe07cea7afcea50f5f37c762808edcdab1c7 172.16.210.53:6381
slots: (0 slots) slave
replicates 4526d594b0ff88934d29e8224f8a2ea7cf977e9f
S: aa513b1e7245d69b64af0c79d8eea2f467ad9f65 172.16.210.55:6381
slots: (0 slots) slave
replicates 4f956397aa4ba097b636b60b35071fff2615f1d7
M: e38c5aba13fda70cbf5b3ab0488ffa9cf8a40ca5 172.16.210.53:6390
slots:6826,10923-12287 (1366 slots) master
0 additional replica(s)
M: 0259881d9b4f3a50d9c9d81b7b64188bbdccdef2 172.16.210.53:6391
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.
How many slots do you want to move (from 1 to 16384)? 1366 ##填写53主机的6390还剩下的槽数量
What is the receiving node ID? 4b5966c3f4d940d7606166ad0f3fb1279f258095 ##接受的主机填写55主机的6380节点
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:e38c5aba13fda70cbf5b3ab0488ffa9cf8a40ca5
Source node #2:done ##输入done
Do you want to proceed with the proposed reshard plan (yes/no)? yes ##输入yes来确认
查看移动情况
[root@db01 src]# redis-cli -c -h 172.16.210.53 -p 6380
172.16.210.53:6380> CLUSTER NODES
4526d594b0ff88934d29e8224f8a2ea7cf977e9f 172.16.210.54:6380 master - 0 1592189569421 11 connected 5461-6825 6827-10922
4b5966c3f4d940d7606166ad0f3fb1279f258095 172.16.210.55:6380 master - 0 1592189573431 12 connected 6826 10923-16383
4f956397aa4ba097b636b60b35071fff2615f1d7 172.16.210.53:6380 myself,master - 0 0 10 connected 0-5460
8ef420d0bea2dd420c94d4db3d4c742166cf1be7 172.16.210.54:6381 slave 4b5966c3f4d940d7606166ad0f3fb1279f258095 0 1592189568420 12 connected
48d7fe07cea7afcea50f5f37c762808edcdab1c7 172.16.210.53:6381 slave 4526d594b0ff88934d29e8224f8a2ea7cf977e9f 0 1592189572428 11 connected
aa513b1e7245d69b64af0c79d8eea2f467ad9f65 172.16.210.55:6381 slave 4f956397aa4ba097b636b60b35071fff2615f1d7 0 1592189571926 10 connected
e38c5aba13fda70cbf5b3ab0488ffa9cf8a40ca5 172.16.210.53:6390 master - 0 1592189574433 9 connected
0259881d9b4f3a50d9c9d81b7b64188bbdccdef2 172.16.210.53:6391 master - 0 1592189570424 8 connected
可以看到53主机的6390节点就已经没有槽位了,此时,就可以将它下线
命令格式:
./redis-trib.rb del-node 主机加端口 节点id
[root@db01 src]# ./redis-trib.rb del-node 172.16.210.53:6390 e38c5aba13fda70cbf5b3ab0488ffa9cf8a40ca5 ##先下线53主机的6390节点
>>> Removing node e38c5aba13fda70cbf5b3ab0488ffa9cf8a40ca5 from cluster 172.16.210.53:6390
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
[root@db01 src]# ./redis-trib.rb del-node 172.16.210.53:6391 0259881d9b4f3a50d9c9d81b7b64188bbdccdef2 ##再下线53主机的6391节点
>>> Removing node 0259881d9b4f3a50d9c9d81b7b64188bbdccdef2 from cluster 172.16.210.53:6391
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
查看下线情况
172.16.210.53:6380> CLUSTER NODES
4526d594b0ff88934d29e8224f8a2ea7cf977e9f 172.16.210.54:6380 master - 0 1592189885154 11 connected 5461-6825 6827-10922
4b5966c3f4d940d7606166ad0f3fb1279f258095 172.16.210.55:6380 master - 0 1592189886157 12 connected 6826 10923-16383
4f956397aa4ba097b636b60b35071fff2615f1d7 172.16.210.53:6380 myself,master - 0 0 10 connected 0-5460
8ef420d0bea2dd420c94d4db3d4c742166cf1be7 172.16.210.54:6381 slave 4b5966c3f4d940d7606166ad0f3fb1279f258095 0 1592189892171 12 connected
48d7fe07cea7afcea50f5f37c762808edcdab1c7 172.16.210.53:6381 slave 4526d594b0ff88934d29e8224f8a2ea7cf977e9f 0 1592189890166 11 connected
aa513b1e7245d69b64af0c79d8eea2f467ad9f65 172.16.210.55:6381 slave 4f956397aa4ba097b636b60b35071fff2615f1d7 0 1592189891168 10 connected
可以看到53主机的6390和6391节点就已经成功从集群中下线.
网友评论