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. problem :无法显示activemq的管理界面

    点击 Manage ActiveMQ broker 无法显示admin界面 解决方法:修改activemq.xml 和 jetty.xml文件 把所有0.0.0.0修改为127.0.0.1 成功: 账 ...

  2. linux下的npm安装

    curl --silent --location https://rpm.nodesource.com/setup_10.x | bash - yum install -y nodejs npm in ...

  3. 设计模式课程 设计模式精讲 4-2 简单工厂coding

    1 代码演练 1.1 未使用简单工厂模式代码 1.2 使用简单工厂模式 1.3 使用反射机制简单工行模式 1 代码演练 1.1 未使用简单工厂模式代码 测试类: package com.geely.d ...

  4. Kali 2020.1 默认密码不是toor

    官方2020年一月28日的文章中指出root/toor is dead. Long live kali/kali. 登录用户名和密码是kali:kali 但是虚拟机镜像下载页面没有及时更新,仍然提示登 ...

  5. oracle的decode、sign、nvl,case...then函数

    ORACLE几种常用的方法 1.decode 常见的用法 : 格式:decode(condition,value1,result[, value2,result2], default_result) ...

  6. PAT T1010 Lehmer Code

    跟1009几乎是同一道题~ #include<bits/stdc++.h> using namespace std; ; int a[maxn]; ]; int r[maxn]; int ...

  7. 什么是Socket:

    先了解一些前提: 网络由下往上分为 物理层 .数据链路层 . 网络层 . 传输层 . 会话层 . 表现层 和 应用层.通过初步了解,我知道IP协议对应于网络层,TCP协议对应于传输层,而HTTP协议对 ...

  8. docker基础镜像ubuntu添加jdk1.8

    首先pull ubuntu18.04 docker pull ubuntu:18.04 下载jdk1.8 jdk-8u191-linux-x64.tar.gz 创建Dockerfile文件 编写文件如 ...

  9. cookie、 Session Storage 、 Local Storage

    问题描述: 使用Ajax, Controller 传回来 JSON 字符串(待处理的信息) 在 Ajax 中实现页面跳转 window.location.href="/jsp/index.j ...

  10. angular 自定义服务封装自定义http请求

    在angular中将http请求,放置在一起封装成服务,可减少代码重复,方便使用 var ngpohttprest = angular.module('ngpohttprest', []); ngpo ...