加入收藏 | 设为首页 | 会员中心 | 我要投稿 焦作站长网 (https://www.0391zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

Redis Cluster 自动化配置,扩容和缩容

发布时间:2021-12-10 17:17:22 所属栏目:MySql教程 来源:互联网
导读:Redis Cluster 自动化安装,扩容和缩容 ASP站长网 之前写过一篇基于Python的redis集群自动化安装的实现,基于纯命令的集群实现还是相当繁琐的,因此官方提供了re

redis-cli -a redis@password --cluster reshard 127.0.0.1:10002 --cluster-from 64e634307bdc339b503574f5a77f1b156c021358 --cluster-to 3645e00a8ec3a902bd6effb4fc20c56a00f2c982 --cluster-slots 1365 --cluster-yes --cluster-timeout 50000 --cluster-pipeline 10000 --cluster-replace >/dev/null 2>&1

############################ execute reshard #########################################

redis-cli -a redis@password --cluster reshard 127.0.0.1:10003 --cluster-from 8b75325c59a7242344d0ebe5ee1e0068c66ffa2a --cluster-to 3645e00a8ec3a902bd6effb4fc20c56a00f2c982 --cluster-slots 1365 --cluster-yes --cluster-timeout 50000 --cluster-pipeline 10000 --cluster-replace >/dev/null 2>&1

 

################# cluster nodes info: #################

026f0179631f50ca858d46c2b2829b3af71af2c8 127.0.0.1:10004@20004 slave 6164025849a8ff9297664fc835bc851af5004f61 0 1575960493000 64 connected

9f265545ebb799d2773cfc20c71705cff9d733ae 127.0.0.1:10006@20006 slave 8b75325c59a7242344d0ebe5ee1e0068c66ffa2a 0 1575960493849 66 connected

64e634307bdc339b503574f5a77f1b156c021358 127.0.0.1:10002@20002 master - 0 1575960494852 65 connected 6826-10922

23e1871c4e1dc1047ce567326e74a6194589146c 127.0.0.1:10005@20005 slave 64e634307bdc339b503574f5a77f1b156c021358 0 1575960492000 65 connected

4854375c501c3dbfb4e2d94d50e62a47520c4f12 127.0.0.1:10008@20008 slave 3645e00a8ec3a902bd6effb4fc20c56a00f2c982 0 1575960493000 67 connected

8b75325c59a7242344d0ebe5ee1e0068c66ffa2a 127.0.0.1:10003@20003 master - 0 1575960493000 66 connected 12288-16383

3645e00a8ec3a902bd6effb4fc20c56a00f2c982 127.0.0.1:10007@20007 myself,master - 0 1575960493000 67 connected 0-1364 5461-6825 10923-12287

6164025849a8ff9297664fc835bc851af5004f61 127.0.0.1:10001@20001 master - 0 1575960492848 64 connected 1365-5460

可见新加的节点成功重新分配了slot,集群扩容成功。

 

这里有几个需要注意的两个问题,如果是自动化安装的话:

1,add-node之后(不管是柱节点还是从节点),要sleep足够长的时间(这里是20秒),让集群中所有的节点都meet到新节点,否则会扩容失败

2,新节点的reshard之后要sleep足够长的时间(这里是20秒),否则继续reshard其他节点的slot会导致上一个reshared失败

 

 

 

整个过程如下

 

[root@JD redis_install]# python3 create_redis_cluster.py

#########################cleanup instance#################################

#########################add node into cluster#################################

 redis-cli --cluster add-node 127.0.0.1:10007 127.0.0.1:10001  -a redis@password

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

>>> Adding node 127.0.0.1:10007 to cluster 127.0.0.1:10001

>>> Performing Cluster Check (using node 127.0.0.1:10001)

M: 6164025849a8ff9297664fc835bc851af5004f61 127.0.0.1:10001

   slots:[0-5460] (5461 slots) master

   1 additional replica(s)

S: 9f265545ebb799d2773cfc20c71705cff9d733ae 127.0.0.1:10006

   slots: (0 slots) slave

   replicates 8b75325c59a7242344d0ebe5ee1e0068c66ffa2a

M: 8b75325c59a7242344d0ebe5ee1e0068c66ffa2a 127.0.0.1:10003

   slots:[10923-16383] (5461 slots) master

   1 additional replica(s)

S: 026f0179631f50ca858d46c2b2829b3af71af2c8 127.0.0.1:10004

   slots: (0 slots) slave

   replicates 6164025849a8ff9297664fc835bc851af5004f61

S: 23e1871c4e1dc1047ce567326e74a6194589146c 127.0.0.1:10005

   slots: (0 slots) slave

   replicates 64e634307bdc339b503574f5a77f1b156c021358

M: 64e634307bdc339b503574f5a77f1b156c021358 127.0.0.1:10002

   slots:[5461-10922] (5462 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.

>>> Send CLUSTER MEET to node 127.0.0.1:10007 to make it join the cluster.

[OK] New node added correctly.

0

 redis-cli --cluster add-node 127.0.0.1:10008 127.0.0.1:10007 --cluster-slave --cluster-master-id 3645e00a8ec3a902bd6effb4fc20c56a00f2c982 -a ******

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

>>> Adding node 127.0.0.1:10008 to cluster 127.0.0.1:10007

>>> Performing Cluster Check (using node 127.0.0.1:10007)

M: 3645e00a8ec3a902bd6effb4fc20c56a00f2c982 127.0.0.1:10007

   slots: (0 slots) master

S: 026f0179631f50ca858d46c2b2829b3af71af2c8 127.0.0.1:10004

   slots: (0 slots) slave

   replicates 6164025849a8ff9297664fc835bc851af5004f61

S: 9f265545ebb799d2773cfc20c71705cff9d733ae 127.0.0.1:10006

   slots: (0 slots) slave

   replicates 8b75325c59a7242344d0ebe5ee1e0068c66ffa2a

M: 64e634307bdc339b503574f5a77f1b156c021358 127.0.0.1:10002

   slots:[5461-10922] (5462 slots) master

   1 additional replica(s)

S: 23e1871c4e1dc1047ce567326e74a6194589146c 127.0.0.1:10005

   slots: (0 slots) slave

   replicates 64e634307bdc339b503574f5a77f1b156c021358

M: 8b75325c59a7242344d0ebe5ee1e0068c66ffa2a 127.0.0.1:10003

   slots:[10923-16383] (5461 slots) master

   1 additional replica(s)

M: 6164025849a8ff9297664fc835bc851af5004f61 127.0.0.1:10001

   slots:[0-5460] (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.

>>> Send CLUSTER MEET to node 127.0.0.1:10008 to make it join the cluster.

Waiting for the cluster to join

 

>>> Configure node as replica of 127.0.0.1:10007.

[OK] New node added correctly.

0

#########################reshard slots#################################

############################ execute reshard #########################################

(编辑:焦作站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读