redis5集群扩容-增加主从节点

回顾上节redis cluster集群入门已经搭建完成的集群节点

b3363a81c3c59d57143cd3323481259c044e66d2 192.168.8.196:[email protected] slave 1b7aa419065c5477c0def9d5e25106963fbdda76 0 1572917132045 6 connected
9dc870942555447543694e42e40061823ed91271 192.168.8.196:[email protected] slave d1a4b1aa3e924a5917efc240cdb2e3ada39e01c2 0 1572917130038 4 connected
1b7aa419065c5477c0def9d5e25106963fbdda76 192.168.8.196:[email protected] master - 0 1572917131041 3 connected 10923-16383
b1b67d4e554e29605bdbe40deab6670a42dd8836 192.168.8.196:[email protected] master - 0 1572917130000 2 connected 5461-10922
fbf9f23ecf0fea399debf7db42c73fece04b98fd 192.168.8.196:[email protected] slave b1b67d4e554e29605bdbe40deab6670a42dd8836 0 1572917131000 5 connected
d1a4b1aa3e924a5917efc240cdb2e3ada39e01c2 192.168.8.196:[email protected] myself,master - 0 1572917127000 1 connected 0-5460

本章目标
上次存在6个节点,本次将要增加5007,5008一主从两节点来演示redis5如何实现动态扩容。

一、添加两个服务节点到集群

redis-cli --cluster add-node 192.168.8.196:5007 192.168.8.196:5001
redis-cli --cluster add-node 192.168.8.196:5008 192.168.8.196:5001

此时查看集群中的节点发现,5007,5008默认均为master

二、为master节点添加分片
这里将192.168.8.196:5007作为master节点,对其进行分片

redis-cli --cluster reshard 192.168.8.196:5007

这时,会出现以下选项:

How many slots do you want to move (from 1 to 16384)? 500
#这里填写分配多少个槽给5007

What is the receiving node ID? 63aa476d990dfa9f5f40eeeaa0315e7f9948554d
#这里添加接收节点的ID,我们填写5007服务节点的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: all
#这里填写槽的来源,all表示是所有服务节点

到这里,分片工作完成

三、设置从节点
这里我们将5008服务节点作为5007的从节点
先登录5008服务节点

redis-cli -c -h 192.168.8.196 -p 5008

指定5008从节点的主节点ID,这里我们填写5007服务节点ID

cluster replicate 63aa476d990dfa9f5f40eeeaa0315e7f9948554d

四、查看当前集群节点

cluster nodes

大功告成。

猜你喜欢

转载自blog.51cto.com/phpme/2447995
今日推荐