温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-06-30 06:27:52 来源:网络 阅读:677 作者:hgditren 栏目:关系型数据库

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

b3363a81c3c59d57143cd3323481259c044e66d2 192.168.8.196:5006@15006 slave 1b7aa419065c5477c0def9d5e25106963fbdda76 0 1572917132045 6 connected
9dc870942555447543694e42e40061823ed91271 192.168.8.196:5004@15004 slave d1a4b1aa3e924a5917efc240cdb2e3ada39e01c2 0 1572917130038 4 connected
1b7aa419065c5477c0def9d5e25106963fbdda76 192.168.8.196:5003@15003 master - 0 1572917131041 3 connected 10923-16383
b1b67d4e554e29605bdbe40deab6670a42dd8836 192.168.8.196:5002@15002 master - 0 1572917130000 2 connected 5461-10922
fbf9f23ecf0fea399debf7db42c73fece04b98fd 192.168.8.196:5005@15005 slave b1b67d4e554e29605bdbe40deab6670a42dd8836 0 1572917131000 5 connected
d1a4b1aa3e924a5917efc240cdb2e3ada39e01c2 192.168.8.196:5001@15001 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

b3363a81c3c59d57143cd3323481259c044e66d2 192.168.8.196:5006@15006 slave 1b7aa419065c5477c0def9d5e25106963fbdda76 0 1573003356000 3 connected
1b7aa419065c5477c0def9d5e25106963fbdda76 192.168.8.196:5003@15003 master - 0 1573003352829 3 connected 11089-16383
fbf9f23ecf0fea399debf7db42c73fece04b98fd 192.168.8.196:5005@15005 slave b1b67d4e554e29605bdbe40deab6670a42dd8836 0 1573003356842 2 connected
b1b67d4e554e29605bdbe40deab6670a42dd8836 192.168.8.196:5002@15002 master - 0 1573003355000 2 connected 5628-10922
d1a4b1aa3e924a5917efc240cdb2e3ada39e01c2 192.168.8.196:5001@15001 master - 0 1573003354837 1 connected 166-5460
9dc870942555447543694e42e40061823ed91271 192.168.8.196:5004@15004 slave d1a4b1aa3e924a5917efc240cdb2e3ada39e01c2 0 1573003357846 1 connected
63aa476d990dfa9f5f40eeeaa0315e7f9948554d 192.168.8.196:5007@15007 master - 0 1573003356000 7 connected 0-165 5461-5627 10923-11088
d3a9de370962873d17f1124bcf9ac166cc6ba950 192.168.8.196:5008@15008 myself,slave 63aa476d990dfa9f5f40eeeaa0315e7f9948554d 0 1573003350000 0 connected

大功告成。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI