Redis集群(4) 删除添加节点

1. 进入其中一个节点; (任意) 查看集群信息;

redis-cli -c -p 6380
cluster info #集群信息
cluster nodes #集群节点信息, 端口 master, cluster, id很重要

2. 添加两个节点;

从 redis6380(现有的节点目录) ,拷贝两份,分别命名为 redis6386, redis6387

修改各自的 redis.conf 信息;

然后启动 6386, 6387 两个节点;

3. 添加第一个节点 (主节点),目前是在 6380 节点上 (其实随便一个集群节点都可以)

./redis-trib.rb add-node 192.168.1.141:6386 192.168.1.141:6380

前一个为新节点,后一个为已有集群节点; 这种方式创建的节点,都为 Master 节点;

4. 查看集群节点信息:

...
bdb0ce9cc5cca545b9182a09346246827af40490 192.168.1.141:6386 master - 0 1534848170916 0 connected

没有分配 hash slot; 现在要从其他节点上分配过来;

./redis-trib.rb reshard 192.168.1.141:6380

进入任意一个节点(已存在有slot ??),对集群重新分片 reshard;

主要执行 shard 信息

[OK] All 16384 slots covered.
 
(提示一)
 
How many slots do you want to move (from 1 to 16384)? 200
 
(提示二)
 
What is the receiving node ID? bdb0ce9cc5cca545b9182a09346246827af40490
 
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
...
Resharding plan:(执行分片计划日志)
...
Moving slot 10986 from fbd2b0bf4ec21c23af7d15a20964688fb23f214c
...... 
(提示三)
 
Do you want to proceed with the proposed reshard plan (yes/no)? yes
 
Moving slot 5461 from 192.168.1.141:6381 to 192.168.1.141:6386:
 
......
 
Moving slot 0 from 192.168.1.141:6381 to 192.168.1.141:6386:
 
Moving slot 1 from 192.168.1.141:6381 to 192.168.1.141:6386:
 
......
 
Moving slot 10923 from 192.168.1.141:6383 to 192.168.1.141:6386:

以上为从所有节点传移slot 到新节点上; 提示二为接收的(新)节点;

/////////////////////////////////////////////////////////////

添加第二节点 6387,方法与上面一样; 但生成的是 Master 节点,要将他转为 cluster 节点,并指定主节点,这里指定 6386 为其主节点;

./redis-trib.rb add-node 192.168.1.141:6387 192.168.1.141:6380

进入 6387 节点;

>redis-cli -c -p 6387
#为其指定主节点;
>cluster replicate bdb0ce9cc5cca545b9182a09346246827af40490

bdb0ce9cc5cca545b9182a09346246827af40490 为 6386 的节点id

然后为 6387 分配点 slot; (这步好像不用执行)

//////////////////////////////////////////////////////////////////////////////////////////////////

删除节点;

删除 cluster 节点,可以直接删除;

./redis-trib.rb del-node 192.168.1.141:6387 6101db56f13af2252e356eb08977b6bd2bb3e2f9

del-node IP:PORT 节点id,删除后该节点服务,也被停掉;

删除主节点,需要将 slot 分配给其他主节点;

./redis-trib.rb reshard 192.168.1.141:6386

输出:

M: bdb0ce9cc5cca545b9182a09346246827af40490 192.168.1.141:6386
slots:0-65,5461-5527,10923-10988 (199 slots) master
...
How many slots do you want to move (from 1 to 16384)? 199
 
(ps:这里填的就是7007拥有的slot槽数,上面有打印出来的)
 
What is the receiving node ID? 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac
 
(ps:这里是接收slot槽的主节点id,我填的是6380的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:bdb0ce9cc5cca545b9182a09346246827af40490
 
(ps:这里是数据源节点,当然填的是6386的Id了)
 
Source node #2:done
 
(ps:输入done表示可以开始生成迁移计划)
 
Ready to move 199 slots.
 
Source nodes:
 
M: bdb0ce9cc5cca545b9182a09346246827af40490 192.168.1.141:6386
 
slots:0-65,5461-5527,10923-10988 (199 slots) master
 
0 additional replica(s)
 
Destination node:
 
M: 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 192.168.1.141:6380
 
slots:66-5460 (5395 slots) master
...
...
Do you want to proceed with the proposed reshard plan (yes/no)? yes
 
(ps:输入yes表示可以开始执行迁移计划)
 
Moving slot 0 from 192.168.1.141:6386 to 192.168.1.141:6380:

查看节点信息:

cluster info
...
bdb0ce9cc5cca545b9182a09346246827af40490 192.168.1.141:6386 master - 0 1534862480550 7 connected
...

执行删除节点

./redis-trib.rb del-node 192.168.1.141:6386 bdb0ce9cc5cca545b9182a09346246827af40490
欢迎您的到来,感谢您的支持!

为您推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注