RedisCluster 添加/删除节点

添加节点
新配置两个测试节点8008和9009

[root@--- ~]# /usr/local/redis-4.0./bin/redis-server /u02/redis//conf/redis_8008.conf

[root@--- ~]# /usr/local/redis-4.0./bin/redis-server /u02/redis//conf/redis_9009.conf

1、添加主点(redis cluster 扩容迁移槽和数据不影响其他节点读写)

[root@--- ~]# redis-trib.rb add-node 192.13.10.77: 192.13.10.77:
>>> Adding node 192.13.10.77: to cluster 192.13.10.77:
>>> Performing Cluster Check (using node 192.13.10.77:)
M: d49ebf2a5f3605487ea4c8deee7e2aa2782667e6 192.13.10.77:
slots:- ( slots) master
additional replica(s)
S: 06031e33797ef0aa6427bddb1ff958f7af0f1a4a 192.13.10.77:
slots: ( slots) slave
replicates 1dba8274e36bde79a215a77d1f241ae6fc81c03e
S: 46233f6d8b508be0cedafc5f07aca04210f654ea 192.13.10.77:
slots: ( slots) slave
replicates ef76f232efb578249e8d0ec8fef8ec02b3524010
M: ef76f232efb578249e8d0ec8fef8ec02b3524010 192.13.10.77:
slots:- ( slots) master
additional replica(s)
M: 1dba8274e36bde79a215a77d1f241ae6fc81c03e 192.13.10.77:
slots:- ( slots) master
additional replica(s)
S: b11fc826c15cdee6e026a59ed98f31c9fa490aaa 192.13.10.77:
slots: ( slots) slave
replicates d49ebf2a5f3605487ea4c8deee7e2aa2782667e6
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
>>> Send CLUSTER MEET to node 192.13.10.77: to make it join the cluster.

注释:
192.13.10.77:8008 新添加的节点
192.13.10.77:2002 集群任意一个节点

查看集群状态:

[root@--- ~]# redis-cli -h 192.13.10.77 -p  -c -a "ysBhqkYHDifB" cluster nodes
06031e33797ef0aa6427bddb1ff958f7af0f1a4a 192.13.10.77:@ slave 1dba8274e36bde79a215a77d1f241ae6fc81c03e connected
d49ebf2a5f3605487ea4c8deee7e2aa2782667e6 192.13.10.77:@ myself,master - connected -
46233f6d8b508be0cedafc5f07aca04210f654ea 192.13.10.77:@ slave ef76f232efb578249e8d0ec8fef8ec02b3524010 connected
ef76f232efb578249e8d0ec8fef8ec02b3524010 192.13.10.77:@ master - connected -
1dba8274e36bde79a215a77d1f241ae6fc81c03e 192.13.10.77:@ master - connected -
b11fc826c15cdee6e026a59ed98f31c9fa490aaa 192.13.10.77:@ slave d49ebf2a5f3605487ea4c8deee7e2aa2782667e6 connected
1600a0f3ae06f801a01be64dbda341d6a25c659a 192.13.10.77:@ master - connected

添加从节点:

[root@--- ~]# redis-trib.rb add-node --slave --master-id 1600a0f3ae06f801a01be64dbda341d6a25c659a 192.13.10.77: 192.13.10.77:
>>> Adding node 192.13.10.77: to cluster 192.13.10.77:
>>> Performing Cluster Check (using node 192.13.10.77:)
M: d49ebf2a5f3605487ea4c8deee7e2aa2782667e6 192.13.10.77:
slots:- ( slots) master
additional replica(s)
S: 06031e33797ef0aa6427bddb1ff958f7af0f1a4a 192.13.10.77:
slots: ( slots) slave
replicates 1dba8274e36bde79a215a77d1f241ae6fc81c03e
S: 46233f6d8b508be0cedafc5f07aca04210f654ea 192.13.10.77:
slots: ( slots) slave
replicates ef76f232efb578249e8d0ec8fef8ec02b3524010
M: ef76f232efb578249e8d0ec8fef8ec02b3524010 192.13.10.77:
slots:- ( slots) master
additional replica(s)
M: 1dba8274e36bde79a215a77d1f241ae6fc81c03e 192.13.10.77:
slots:- ( slots) master
additional replica(s)
S: b11fc826c15cdee6e026a59ed98f31c9fa490aaa 192.13.10.77:
slots: ( slots) slave
replicates d49ebf2a5f3605487ea4c8deee7e2aa2782667e6
M: 1600a0f3ae06f801a01be64dbda341d6a25c659a 192.13.10.77:
slots: ( slots) master
additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
>>> Send CLUSTER MEET to node 192.13.10.77: to make it join the cluster.
Waiting for the cluster to join.
>>> Configure node as replica of 192.13.10.77:.
[OK] New node added correctly.

注释:
--slave 表示添加的是从节点
--master-id 表示主节点的node-id,这里的node-id是前面刚添加的8008端口的node-id
192.13.10.77:9009 新添加的从节点
192.13.10.77:2002 集群中任意一个节点

重新分配slot
[root@192-13-10-77 ~]# redis-trib.rb reshard 192.13.10.77:2002   //下面是主要过程

How many slots do you want to move (from 1 to 16384)?          //设置slot数4096 
What is the receiving node ID? 1600a0f3ae06f801a01be64dbda341d6a25c659a     //新节点node 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   //表示全部节点重新洗牌
Do you want to proceed with the proposed reshard plan (yes/no)? yes   //确认重新分

或者 输入"源节点ID",最后用 done 结束

输入源节点ID,这里分别输入2002,3003,4004三个节点ID,最后用done结束
Source node #1: cfb28ef1deee4e0fa78da86abe5d24566744411e
Source node #2: 8e41673d59c9568aa9d29fb174ce733345b3e8f1
Source node #3: 40b8d09d44294d2e23c7c768efc8fcd153446746
Source node #4: done

新添加的主节点是没有slots的
1600a0f3ae06f801a01be64dbda341d6a25c659a 新添加的主节点,主节点如果没有slots的话,存取数据是不会被选中
可以把分配的过程理解成打扑克牌,all表示大家重新洗牌; 输入某个主节点的node-id,然后在输入done的话,就好比从某个节点抽牌

迁移之后用redis-trib.rb rebalance命令检查节点之间槽的均衡性

[root@--- conf]# redis-trib.rb rebalance 127.0.0.1:2002
>>> Performing Cluster Check (using node 127.0.0.1:)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
>>> Rebalancing across nodes. Total weight =
Moving slots from 127.0.0.1: to 192.13.10.77:
######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
Moving slots from 127.0.0.1: to 192.13.10.77:
#####################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
[root@--- conf]# redis-trib.rb rebalance 127.0.0.1:
>>> Performing Cluster Check (using node 127.0.0.1:)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
*** No rebalancing needed! All nodes are within the 2.0% threshold.(槽数据量差异在2%以内,集群节点数据相对均衡,无需在调整)

查看集群状态:

[root@--- ~]# redis-cli -h 192.13.10.77 -p  -c cluster nodes
1600a0f3ae06f801a01be64dbda341d6a25c659a 192.13.10.77:@ master - connected - - -
b11fc826c15cdee6e026a59ed98f31c9fa490aaa 192.13.10.77:@ slave d49ebf2a5f3605487ea4c8deee7e2aa2782667e6 connected
d49ebf2a5f3605487ea4c8deee7e2aa2782667e6 192.13.10.77:@ myself,master - connected -
ef76f232efb578249e8d0ec8fef8ec02b3524010 192.13.10.77:@ master - connected -
4e1e8dcfe075e61ec92d0f922ec12bdf7e71ee2c 192.13.10.77:@ slave 1600a0f3ae06f801a01be64dbda341d6a25c659a connected
1dba8274e36bde79a215a77d1f241ae6fc81c03e 192.13.10.77:@ master - connected -
06031e33797ef0aa6427bddb1ff958f7af0f1a4a 192.13.10.77:@ slave 1dba8274e36bde79a215a77d1f241ae6fc81c03e connected
46233f6d8b508be0cedafc5f07aca04210f654ea 192.13.10.77:@ slave ef76f232efb578249e8d0ec8fef8ec02b3524010 connected

检查redis状态

[root@--- conf]# redis-trib.rb check 192.13.10.77:
>>> Performing Cluster Check (using node 192.13.10.77:)
M: e9883dd5b69227eb045ef85e0d95b5374c74b96a 192.13.10.77:
slots:- ( slots) master
additional replica(s)
S: a73c6e9c3540ab1630ed18233f08182cba328219 192.13.10.77:
slots: ( slots) slave
replicates a86fa76d2279c1f5685500a8b60ea2a600fc19f2
M: b3966e1ed00ae4616077577f24eab2d5b13ace7a 192.13.10.77:
slots:- ( slots) master
additional replica(s)
S: 64538f2f5ec58bedb344e4b5f0ac540d9c09f506 192.13.10.77:
slots: ( slots) slave
replicates e9883dd5b69227eb045ef85e0d95b5374c74b96a
M: 853a34de3d9c9347c5deac1127d3d3fe09788c2e 192.13.10.77:
slots:- ( slots) master
additional replica(s)
M: a86fa76d2279c1f5685500a8b60ea2a600fc19f2 192.13.10.77:
slots:- ( slots) master
additional replica(s)
S: 0268ecaf869839aac9cab7b9d96c7fbac7df04d6 192.13.10.77:
slots: ( slots) slave
replicates 853a34de3d9c9347c5deac1127d3d3fe09788c2e
S: 7070789bbcb15b6845d0aa6c4e1bc99be1c1d6ce 192.13.10.77:
slots: ( slots) slave
replicates b3966e1ed00ae4616077577f24eab2d5b13ace7a
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.

redis cluster 4.0.9版本若有密码,无法分配slots。 因此若有密码必须先删除密码

删除节点
删除从节点(若有密码无法操作)

[root@--- conf]# redis-trib.rb del-node 192.13.10.77: a86fa76d2279c1f5685500a8b60ea2a600fc19f2
>>> Removing node a86fa76d2279c1f5685500a8b60ea2a600fc19f2 from cluster 192.13.10.77:
[ERR] Node 192.13.10.77: is not empty! Reshard data away and try again.

查看4004主节点存在的slots数

[root@--- conf]# redis-trib.rb check 192.13.10.77:
>>> Performing Cluster Check (using node 192.13.10.77:)
S: a73c6e9c3540ab1630ed18233f08182cba328219 192.13.10.77:
slots: ( slots) slave
replicates a86fa76d2279c1f5685500a8b60ea2a600fc19f2
S: 64538f2f5ec58bedb344e4b5f0ac540d9c09f506 192.13.10.77:
slots: ( slots) slave
replicates e9883dd5b69227eb045ef85e0d95b5374c74b96a
M: b3966e1ed00ae4616077577f24eab2d5b13ace7a 192.13.10.77:
slots:- ( slots) master
additional replica(s)
S: 7070789bbcb15b6845d0aa6c4e1bc99be1c1d6ce 192.13.10.77:
slots: ( slots) slave
replicates b3966e1ed00ae4616077577f24eab2d5b13ace7a
M: a86fa76d2279c1f5685500a8b60ea2a600fc19f2 192.13.10.77:
slots:- ( slots) master
additional replica(s)
M: e9883dd5b69227eb045ef85e0d95b5374c74b96a 192.13.10.77:
slots:- ( slots) master
additional replica(s)
S: 0268ecaf869839aac9cab7b9d96c7fbac7df04d6 192.13.10.77:
slots: ( slots) slave
replicates 853a34de3d9c9347c5deac1127d3d3fe09788c2e
M: 853a34de3d9c9347c5deac1127d3d3fe09788c2e 192.13.10.77:
slots:- ( slots) master
additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.

删除从节点9009

[root@--- conf]# redis-trib.rb del-node 192.13.10.77: a73c6e9c3540ab1630ed18233f08182cba328219
>>> Removing node a73c6e9c3540ab1630ed18233f08182cba328219 from cluster 192.13.10.77:
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

删除主节点的slots数(平均分配删除的槽数到不同的主节点)

[root@--- conf]# redis-trib.rb reshard 192.13.10.77:
>>> Performing Cluster Check (using node 192.13.10.77:)
M: a86fa76d2279c1f5685500a8b60ea2a600fc19f2 192.13.10.77:
slots:- ( slots) master
additional replica(s)
S: 64538f2f5ec58bedb344e4b5f0ac540d9c09f506 192.13.10.77:
slots: ( slots) slave
replicates e9883dd5b69227eb045ef85e0d95b5374c74b96a
S: a73c6e9c3540ab1630ed18233f08182cba328219 192.13.10.77:
slots: ( slots) slave
replicates a86fa76d2279c1f5685500a8b60ea2a600fc19f2
M: b3966e1ed00ae4616077577f24eab2d5b13ace7a 192.13.10.77:
slots:- ( slots) master
additional replica(s)
S: 0268ecaf869839aac9cab7b9d96c7fbac7df04d6 192.13.10.77:
slots: ( slots) slave
replicates 853a34de3d9c9347c5deac1127d3d3fe09788c2e
M: e9883dd5b69227eb045ef85e0d95b5374c74b96a 192.13.10.77:
slots:- ( slots) master
additional replica(s)
M: 853a34de3d9c9347c5deac1127d3d3fe09788c2e 192.13.10.77:
slots:- ( slots) master
additional replica(s)
S: 7070789bbcb15b6845d0aa6c4e1bc99be1c1d6ce 192.13.10.77:
slots: ( slots) slave
replicates b3966e1ed00ae4616077577f24eab2d5b13ace7a
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
How many slots do you want to move (from to )? //删除的slots数
What is the receiving node ID? e9883dd5b69227eb045ef85e0d95b5374c74b96a // 接收的node-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 #:a86fa76d2279c1f5685500a8b60ea2a600fc19f2 //被删除master的node-id
Source node #:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes //取消slot后,reshard

删除4004主节点(redis cluster 最好使用redis-trib.rb del-node删除节点,尽量不要用cluster forget)

[root@--- conf]# redis-trib.rb del-node 192.13.10.77: a86fa76d2279c1f5685500a8b60ea2a600fc19f2
>>> Removing node a86fa76d2279c1f5685500a8b60ea2a600fc19f2 from cluster 192.13.10.77:
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

查看集群状态

[root@--- conf]# redis-cli -h 192.13.10.77 -p  -c cluster nodes
b3966e1ed00ae4616077577f24eab2d5b13ace7a 192.13.10.77:@ master - connected -
64538f2f5ec58bedb344e4b5f0ac540d9c09f506 192.13.10.77:@ slave e9883dd5b69227eb045ef85e0d95b5374c74b96a connected
853a34de3d9c9347c5deac1127d3d3fe09788c2e 192.13.10.77:@ master - connected -
e9883dd5b69227eb045ef85e0d95b5374c74b96a 192.13.10.77:@ myself,master - connected - -
0268ecaf869839aac9cab7b9d96c7fbac7df04d6 192.13.10.77:@ slave 853a34de3d9c9347c5deac1127d3d3fe09788c2e connected
7070789bbcb15b6845d0aa6c4e1bc99be1c1d6ce 192.13.10.77:@ slave b3966e1ed00ae4616077577f24eab2d5b13ace7a connected

redis cluster 添加/删除节点操作的更多相关文章

  1. redis cluster 添加 删除 重分配 节点

    redis cluster配置好,并运行一段时间后,我们想添加节点,或者删除节点,该怎么办呢.  一,redis cluster命令 //集群(cluster) CLUSTER INFO 打印集群的信 ...

  2. Redis Cluster 添加/删除 完整折腾步骤

    Redis还是挺好玩的,今天测试了集群的添加.删除节点.重分配slot等.更深入的理解redis的游戏规则.步骤繁多,但是详细. 环境解释: 我是在一台Centos 6.9上测试的,各个redis节点 ...

  3. Redis Cluster 集群节点维护 (三)

    Redis Cluster 集群节点维护: 集群运行很久之后,难免由于硬件故障,网络规划,业务增长,等原因对已有集群进行相应的调整,比如增加redis nodes 节点,减少节点,节点迁移,更换服务器 ...

  4. 高级复制实验配置添加复制节点操作时报错:ORA-23308: object GP.T does not exist or is invalid

    出错原因: 使用高级复制时,在源端启动复制支持,执行语句:REPADMIN@bys1>execute dbms_repcat.generate_replication_support('gp', ...

  5. mongodb replica set 添加/删除节点方法--http://www.ii123.com/jc/bc/bczh/258948.html

    replica set多服务器主从,添加,删除节点,肯定会经常遇到的.下面详细说明一下,添加,删除节点的2种方法. 一,利用rs.reconfig,来添加,删除节点 1,添加节点  代码如下   re ...

  6. 向redis中添加删除list列表

    转: 向redis中添加删除list列表 2018年04月18日 15:44:54 luo_yu_1106 阅读数:4082   一.添加 向redis中添加队列有两种方式 1.lpush l是lef ...

  7. WebLogic Server添加删除补丁操作【转】【补】

    WebLogic Server添加删除补丁操作 0 查看当前weblogic版本 [weblogic@localhost bin]$ cd /data/bea/weblogic11/wlserver_ ...

  8. MongoDB添加删除节点

    副本集添加删除节点 sharding添加删除节点 先将节点设置为hidden,再remove

  9. redis集群添加删除节点

    Redis3.0集群添加节点 1:首先把需要添加的节点启动 cd /usr/local/cluster/ mkdir 7006 cp /usr/local/cluster/redis.conf  /u ...

随机推荐

  1. 《JavaScript高级程序设计》读书笔记(序)

    1.现大三暑假中,计划9月初北上找前端工作,大三一年时间都在健身和学习专业课知识,技术有点荒废了,7月份忙于学校安排的实习javaweb方向的,到现在才有整段的时间好好把基础巩固一. 2.这几天也在关 ...

  2. Java连载66-数组的两种初始化方式

    一.数组 1.数组中存储元素的类型是统一的,每一个元素在内存中所占用的空间大小是相同的,知道数组的首元素的内存地址,要查找的元素只要知道下标,就可以快速的计算出偏移量,通过首元素内存地址加上偏移量,就 ...

  3. 【协作式原创】自己动手写docker之run代码解析

    linux预备知识 urfave cli预备知识 准备工作 阿里云抢占式实例:centos7.4 每次实例释放后都要重新安装go wget https://dl.google.com/go/go1.1 ...

  4. java 多线程小记

    /*java里面实现多线程一般有两种方式 * 1,继承Thread类,实现run方法 * 2,实现Runnable接口,实现run方法 * start方法可以新建一个线程,创建多线程必须调用此方法 * ...

  5. 让eclipse恢复默认布局

    参考:https://blog.csdn.net/howlaa/article/details/39178359 Window -> Perspective -> Reset Perspe ...

  6. loadrunner 接口测试实战

    直接上代码: web_reg_save_param("Name",   //这个函数是为了获取服务器返回的值.我这个接口的返回值是这样子的 //将服务器返回的值放在Name里,Na ...

  7. while语句及批量创建用户!

    1.while 循环语句的作用:重复测试某个条件,只要条件成立则反复执行2.while 语句结构while 条件测试操作do命令序列done ============================= ...

  8. springcloud-zuul进阶篇

    一 前言 经过zuul初级篇(博客或者公主号springcloud专栏可以找到)的学习,读者都懂得如何简单的使用zuul进行路由网关配置,在进阶篇中你将获得zuul核心功能过滤器的基本使用,通过zuu ...

  9. 125、Java面向对象之引用传递实例三,int类型按值传递

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  10. 笔记||Python3进阶之装饰器

    # 装饰器# 特征: 是用一个@开头的字符串# 装饰器通常用来装饰函数.或者类的方法# 被装饰后的函数,通常是在原有的函数基础上,会多出增加一点功能# 一般来说装饰器本身也是一个函数## def te ...