Redis集群添加和删除节点(主和从)

一、原始集群(6个节点,3主3从):

(1)启动集群:因为集群创建一次就行,所以直接启动所有节点服务即可

[root@Master ~]# /usr/local/redis/bin/redis-server /usr/local/redis-cluster/7001/redis.conf

[root@Master ~]# /usr/local/redis/bin/redis-server /usr/local/redis-cluster/7002/redis.conf

[root@Master ~]# /usr/local/redis/bin/redis-server /usr/local/redis-cluster/7003/redis.conf

[root@Master ~]# /usr/local/redis/bin/redis-server /usr/local/redis-cluster/7004/redis.conf

[root@Master ~]# /usr/local/redis/bin/redis-server /usr/local/redis-cluster/7005/redis.conf

[root@Master ~]# /usr/local/redis/bin/redis-server /usr/local/redis-cluster/7006/redis.conf

(2)查看服务器的运行状态

[root@Master ~]# ps -ef | grep redis

root 2071 1 0 18:19 ? 00:00:00 /usr/local/redis/bin/redis-server 192.168.1.111:7001 [cluster]

root 2075 1 0 18:19 ? 00:00:00 /usr/local/redis/bin/redis-server 192.168.1.111:7002 [cluster]

root 2079 1 0 18:19 ? 00:00:00 /usr/local/redis/bin/redis-server 192.168.1.111:7003 [cluster]

root 2083 1 0 18:19 ? 00:00:00 /usr/local/redis/bin/redis-server 192.168.1.111:7004 [cluster]

root 2089 1 0 18:19 ? 00:00:00 /usr/local/redis/bin/redis-server 192.168.1.111:7005 [cluster]

root 2095 1 0 18:19 ? 00:00:00 /usr/local/redis/bin/redis-server 192.168.1.111:7006 [cluster]

root 2101 1974 0 18:19 pts/0 00:00:00 grep redis

(3)登录其中一个节点,查看集群状态

[root@Master src]# /usr/local/redis/bin/redis-cli -c -h 192.168.1.111 -p 7001

192.168.1.111:7001> cluster info

cluster_state:ok

cluster_slots_assigned:16384

cluster_slots_ok:16384

cluster_slots_pfail:0

cluster_slots_fail:0

cluster_known_nodes:6

cluster_size:3

cluster_current_epoch:6

cluster_my_epoch:1

cluster_stats_messages_sent:1366

cluster_stats_messages_received:866

二、新建集群节点操作

(4)我们将新建两个服务,在之前搭建的集群中新增两个节点(一主一从)

Master:7007 Slave:7008

步骤一:创建7007、7008文件夹,拷贝redis.conf文件到两个文件夹下,然后进行配置文件的修改

[root@bhz004 redis-cluster]# mkdir 7007

[root@Master redis-cluster]# mkdir 7008

[root@Master redis-cluster]# cd 7001

[root@Master 7001]# cp redis.conf /usr/local/redis-cluster/7007/

[root@Master 7001]# cp redis.conf /usr/local/redis-cluster/7008/

[root@Master 7001]# vim /usr/local/redis-cluster/7007/redis.conf

修改内容如下:

          port:7007

      dir /usr/local/redis-cluster/7007/

      cluster-config-file nodes7007.conf

[root@Master 7001]# vim /usr/local/redis-cluster/7008/redis.conf

修改内容如下:

          port:7008

      dir /usr/local/redis-cluster/7008/

      cluster-config-file nodes7008.conf

步骤二:启动7007和7008俩个服务并查看服务状态。

[root@bhz004 7001]# /usr/local/redis/bin/redis-server /usr/local/redis-cluster/7007/redis.conf

[root@bhz004 7001]# /usr/local/redis/bin/redis-server /usr/local/redis-cluster/7008/redis.conf

[root@bhz004 7001]# ps -el | grep redis

(5)先稍微看一下redis-trib脚本能怎么使用:

[root@Master src]# ./redis-trib.rb

Usage: redis-trib <command> <options> <arguments ...>



create host1:port1 ... hostN:portN

--replicas <arg>

check host:port

info host:port

fix host:port

--timeout <arg>

reshard host:port

--from <arg>

--to <arg>

--slots <arg>

--yes

--timeout <arg>

--pipeline <arg>

rebalance host:port

--weight <arg>

--auto-weights

--use-empty-masters

--timeout <arg>

--simulate

--pipeline <arg>

--threshold <arg>

add-node new_host:new_port existing_host:existing_port

--slave

--master-id <arg>

del-node host:port node_id

set-timeout host:port milliseconds

call host:port command arg arg .. arg

import host:port

--from <arg>

--copy

--replace

help (show this help)



For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.

1 create:创建一个集群环境host1:port1 ... hostN:portN(集群中的主从节点比例)

2 call:可以执行redis命令

3 add-node:将一个节点添加到集群里,第一个参数为新节点的ip:port,第二个参数为集群中任意一个已经存在的节点的ip:port

4 del-node:移除一个节点

5 reshard:重新分片

6 check:检查集群状态

(6)新增一个主节点7007(Master)

步骤一:使用add-node命令,第一个为新增节点,第二个为集群中已知存在节点(任意一个)

[root@Master src]# ./redis-trib.rb add-node 192.168.1.111:7007 192.168.1.111:7001

>>> Adding node 192.168.1.111:7007 to cluster 192.168.1.111:7001

/usr/local/rvm/gems/ruby-2.4.4/gems/redis-3.2.1/lib/redis/client.rb:443: warning: constant ::Fixnum is deprecated

>>> Performing Cluster Check (using node 192.168.1.111:7001)

M: 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 192.168.1.111:7001

slots:0-5460 (5461 slots) master

1 additional replica(s)

S: 56fb12f39b02c38f2c43cfc19f7b9faafdd900a0 192.168.1.111:7006

slots: (0 slots) slave

replicates fbd2b0bf4ec21c23af7d15a20964688fb23f214c

M: b9e97e221fb3ae239cc0e2831779381ace7c6b9b 192.168.1.111:7002

slots:5461-10922 (5462 slots) master

1 additional replica(s)

S: 53e5b386290843bb57af3c9cea8af7ccc38314f9 192.168.1.111:7005

slots: (0 slots) slave

replicates b9e97e221fb3ae239cc0e2831779381ace7c6b9b

M: fbd2b0bf4ec21c23af7d15a20964688fb23f214c 192.168.1.111:7003

slots:10923-16383 (5461 slots) master

1 additional replica(s)

S: 146f1006dc5df60c3d4ac2867a21004deb8be6eb 192.168.1.111:7004

slots: (0 slots) slave

replicates 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

>>> Send CLUSTER MEET to node 192.168.1.111:7007 to make it join the cluster.

[OK] New node added correctly.

步骤二:查看集群节点状态:

[root@Master src]# /usr/local/redis/bin/redis-cli -c -h 192.168.1.111 -p 7001

192.168.1.111:7001> cluster nodes

3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 192.168.1.111:7001 myself,master - 0 0 1 connected 0-5460

56fb12f39b02c38f2c43cfc19f7b9faafdd900a0 192.168.1.111:7006 slave fbd2b0bf4ec21c23af7d15a20964688fb23f214c 0 1534848168901 6 connected

b9e97e221fb3ae239cc0e2831779381ace7c6b9b 192.168.1.111:7002 master - 0 1534848166887 2 connected 5461-10922

53e5b386290843bb57af3c9cea8af7ccc38314f9 192.168.1.111:7005 slave b9e97e221fb3ae239cc0e2831779381ace7c6b9b 0 1534848167894 5 connected

fbd2b0bf4ec21c23af7d15a20964688fb23f214c 192.168.1.111:7003 master - 0 1534848169908 3 connected 10923-16383

bdb0ce9cc5cca545b9182a09346246827af40490 192.168.1.111:7007 master - 0 1534848170916 0 connected

146f1006dc5df60c3d4ac2867a21004deb8be6eb 192.168.1.111:7004 slave 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 0 1534848171419 4 connected

192.168.1.111:7001>

注意:当添加节点以后,新增的节点不会有任何数据,因为它没分配任何的slot(hash槽),这是拿来存放数据的,Master必须得有才能存放数据。那么我们需要手动为新节点分配slot。

(7)为新节点7007分配slot槽

步骤一:使用redis-trib命令的reshard,找到集群中的任意一个主节点,对其进行重新分片工作。

[root@Master src]# ./redis-trib.rb reshard 192.168.1.111:7001

/usr/local/rvm/gems/ruby-2.4.4/gems/redis-3.2.1/lib/redis/client.rb:443: warning: constant ::Fixnum is deprecated

>>> Performing Cluster Check (using node 192.168.1.111:7001)

M: 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 192.168.1.111:7001

slots:0-5460 (5461 slots) master

1 additional replica(s)

S: 56fb12f39b02c38f2c43cfc19f7b9faafdd900a0 192.168.1.111:7006

slots: (0 slots) slave

replicates fbd2b0bf4ec21c23af7d15a20964688fb23f214c

M: b9e97e221fb3ae239cc0e2831779381ace7c6b9b 192.168.1.111:7002

slots:5461-10922 (5462 slots) master

1 additional replica(s)

S: 53e5b386290843bb57af3c9cea8af7ccc38314f9 192.168.1.111:7005

slots: (0 slots) slave

replicates b9e97e221fb3ae239cc0e2831779381ace7c6b9b

M: fbd2b0bf4ec21c23af7d15a20964688fb23f214c 192.168.1.111:7003

slots:10923-16383 (5461 slots) master

1 additional replica(s)

M: bdb0ce9cc5cca545b9182a09346246827af40490 192.168.1.111:7007

slots: (0 slots) master

0 additional replica(s)

S: 146f1006dc5df60c3d4ac2867a21004deb8be6eb 192.168.1.111:7004

slots: (0 slots) slave

replicates 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[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



Ready to move 200 slots.

Source nodes:

M: 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 192.168.1.111:7001

slots:0-5460 (5461 slots) master

1 additional replica(s)

M: b9e97e221fb3ae239cc0e2831779381ace7c6b9b 192.168.1.111:7002

slots:5461-10922 (5462 slots) master

1 additional replica(s)

M: fbd2b0bf4ec21c23af7d15a20964688fb23f214c 192.168.1.111:7003

slots:10923-16383 (5461 slots) master

1 additional replica(s)

Destination node:

M: bdb0ce9cc5cca545b9182a09346246827af40490 192.168.1.111:7007

slots: (0 slots) master

0 additional replica(s)

Resharding plan:(执行分片计划日志)

Moving slot 5461 from b9e97e221fb3ae239cc0e2831779381ace7c6b9b

Moving slot 5462 from b9e97e221fb3ae239cc0e2831779381ace7c6b9b

......

Moving slot 0 from 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac

Moving slot 2 from 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac

.....

Moving slot 10923 from fbd2b0bf4ec21c23af7d15a20964688fb23f214c

Moving slot 10924 from fbd2b0bf4ec21c23af7d15a20964688fb23f214c

Moving slot 10925 from fbd2b0bf4ec21c23af7d15a20964688fb23f214c

....

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.111:7002 to 192.168.1.111:7007:

......

Moving slot 0 from 192.168.1.111:7001 to 192.168.1.111:7007:

Moving slot 1 from 192.168.1.111:7001 to 192.168.1.111:7007:

......

Moving slot 10923 from 192.168.1.111:7003 to 192.168.1.111:7007:

.....

提示一:你希望将多少个槽移动到新的节点上,可以自己设置,比如200个槽

提示二:接收这些槽的节点的id。下个提示是从哪些主节点抽取槽到新节点中:all为所有主节点,done:你可以指定节点:)

提示三:输入yes确认开始执行分年任务。

(8)在最后,我们查看一下集群状态:

[root@Master src]# /usr/local/redis/bin/redis-cli -c -h 192.168.1.111 -p 7001

192.168.1.111:7001> cluster nodes

3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 192.168.1.111:7001 myself,master - 0 0 1 connected 66-5460

56fb12f39b02c38f2c43cfc19f7b9faafdd900a0 192.168.1.111:7006 slave fbd2b0bf4ec21c23af7d15a20964688fb23f214c 0 1534850426284 6 connected

b9e97e221fb3ae239cc0e2831779381ace7c6b9b 192.168.1.111:7002 master - 0 1534850428299 2 connected 5528-10922

53e5b386290843bb57af3c9cea8af7ccc38314f9 192.168.1.111:7005 slave b9e97e221fb3ae239cc0e2831779381ace7c6b9b 0 1534850423259 5 connected

fbd2b0bf4ec21c23af7d15a20964688fb23f214c 192.168.1.111:7003 master - 0 1534850427294 3 connected 10989-16383

bdb0ce9cc5cca545b9182a09346246827af40490 192.168.1.111:7007 master - 0 1534850424268 7 connected 0-65 5461-5527 10923-10988

146f1006dc5df60c3d4ac2867a21004deb8be6eb 192.168.1.111:7004 slave 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 0 1534850429305 4 connected

如上所示,现在新增的主节点7007已经有自己的slot槽了,也就是说可以在7007上面进行读写数据咯~到现在为止,集群中已经有7个节点了,而且是4主3从。

那我们再给7007弄个Slave咯,不能太偏心。

(9)添加从节点(7008)到集群中

步骤一:使用add-node添加新节点

[root@Master src]# ./redis-trib.rb add-node 192.168.1.111:7008 192.168.1.111:7001

步骤二:提示成功后再查看一下集群的节点信息:

[root@Master src]# /usr/local/redis/bin/redis-cli -c -h 192.168.1.111 -p 7001

192.168.1.111:7001> cluster nodes

6101db56f13af2252e356eb08977b6bd2bb3e2f9 192.168.1.111:7008 master - 0 1534850805149 0 connected

3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 192.168.1.111:7001 myself,master - 0 0 1 connected 66-5460

56fb12f39b02c38f2c43cfc19f7b9faafdd900a0 192.168.1.111:7006 slave fbd2b0bf4ec21c23af7d15a20964688fb23f214c 0 1534850806155 6 connected

b9e97e221fb3ae239cc0e2831779381ace7c6b9b 192.168.1.111:7002 master - 0 1534850804647 2 connected 5528-10922

53e5b386290843bb57af3c9cea8af7ccc38314f9 192.168.1.111:7005 slave b9e97e221fb3ae239cc0e2831779381ace7c6b9b 0 1534850801627 5 connected

fbd2b0bf4ec21c23af7d15a20964688fb23f214c 192.168.1.111:7003 master - 0 1534850805653 3 connected 10989-16383

bdb0ce9cc5cca545b9182a09346246827af40490 192.168.1.111:7007 master - 0 1534850800622 7 connected 0-65 5461-5527 10923-10988

146f1006dc5df60c3d4ac2867a21004deb8be6eb 192.168.1.111:7004 slave 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 0 1534850803640 4 connected

如上面所示,但是我们可以看到,7008还是一个Master节点,而且没有拥有自己的slot槽。那么我们接下来要让它变成从节点。

步骤二:使用cluster replicate命名来给当前节点(从节点7008)指定主节点的id。

首先我们当然需要登录到7008节点的客户端,然后使用上面的命令来进行操作,现在我们让7007成为7008的主节点。

[root@Master src]# /usr/local/redis/bin/redis-cli -c -h 192.168.1.111 -p 7008

192.168.1.111:7008> cluster replicate bdb0ce9cc5cca545b9182a09346246827af40490

OK (提示OK则表示成功!)

步骤三:我们继续看一下集群的节点信息

192.168.1.111:7008> cluster nodes

b9e97e221fb3ae239cc0e2831779381ace7c6b9b 192.168.1.111:7002 master - 0 1534851019889 2 connected 5528-10922

53e5b386290843bb57af3c9cea8af7ccc38314f9 192.168.1.111:7005 slave b9e97e221fb3ae239cc0e2831779381ace7c6b9b 0 1534851021902 2 connected

bdb0ce9cc5cca545b9182a09346246827af40490 192.168.1.111:7007 master - 0 1534851016866 7 connected 0-65 5461-5527 10923-10988

fbd2b0bf4ec21c23af7d15a20964688fb23f214c 192.168.1.111:7003 master - 0 1534851022907 3 connected 10989-16383

3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 192.168.1.111:7001 master - 0 1534851018879 1 connected 66-5460

6101db56f13af2252e356eb08977b6bd2bb3e2f9 192.168.1.111:7008 myself,slave bdb0ce9cc5cca545b9182a09346246827af40490 0 0 0 connected

146f1006dc5df60c3d4ac2867a21004deb8be6eb 192.168.1.111:7004 slave 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 0 1534851020896 1 connected

56fb12f39b02c38f2c43cfc19f7b9faafdd900a0 192.168.1.111:7006 slave fbd2b0bf4ec21c23af7d15a20964688fb23f214c 0 1534851017874 3 connected

(10)我们可以对集群进行操作了,来验证是否可以进行读写。下面就不贴例子了。

(11)有添加当然就有删除节点的操作了。删除从节点非常简单,删除的时候指定ip+端口以及节点id即可。但是删除主节点可不能直接删除,一定要先将slot槽重新移动到其他主节点那里再进行删除操作,不然存放的数据就丢失了。我们现在先尝试删除一个从节点(7008)

步骤一:删除子节点用del-node命令。此命令需要制定删除节点的ip和端口,以及节点的id。

[root@Master src]# ./redis-trib.rb del-node 192.168.1.111:7008 6101db56f13af2252e356eb08977b6bd2bb3e2f9
输出如下:

>>> Removing node 6101db56f13af2252e356eb08977b6bd2bb3e2f9 from cluster 192.168.1.111:7008

/usr/local/rvm/gems/ruby-2.4.4/gems/redis-3.2.1/lib/redis/client.rb:443: warning: constant ::Fixnum is deprecated

>>> Sending CLUSTER FORGET messages to the cluster...

>>> SHUTDOWN the node.

步骤二:删除后我们再次查看集群的节点信息,如下所示,7008从节点已经被移除掉。

[root@Master src]# /usr/local/redis/bin/redis-cli -c -h 192.168.1.111 -p 7001

192.168.1.111:7001> cluster nodes

3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 192.168.1.111:7001 myself,master - 0 0 1 connected 66-5460

56fb12f39b02c38f2c43cfc19f7b9faafdd900a0 192.168.1.111:7006 slave fbd2b0bf4ec21c23af7d15a20964688fb23f214c 0 1534861607148 6 connected

b9e97e221fb3ae239cc0e2831779381ace7c6b9b 192.168.1.111:7002 master - 0 1534861607651 2 connected 5528-10922

53e5b386290843bb57af3c9cea8af7ccc38314f9 192.168.1.111:7005 slave b9e97e221fb3ae239cc0e2831779381ace7c6b9b 0 1534861606140 5 connected

fbd2b0bf4ec21c23af7d15a20964688fb23f214c 192.168.1.111:7003 master - 0 1534861605134 3 connected 10989-16383

bdb0ce9cc5cca545b9182a09346246827af40490 192.168.1.111:7007 master - 0 1534861608155 7 connected 0-65 5461-5527 10923-10988

146f1006dc5df60c3d4ac2867a21004deb8be6eb 192.168.1.111:7004 slave 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 0 1534861609160 4 connected

步骤三:另外,我们可以发现,7008的redis服务进程也被kill掉了。

[root@Master src]# ps -ef | grep 7008

root 4079 1974 0 22:27 pts/0 00:00:00 grep 7008

(12)删除从节点就是这么简单,那么我们现在开始尝试删除之前添加的主节点7007,当然了,我们必须要记得先将7007的slot槽重新放回其他可用的主节点中,然后再进行删除节点操作。

步骤一:删除7007(master)节点之前,我们需要先把其全部的数据(slot槽)移动到其他节点上去(目前只能把master的数据迁移到一个节点上,暂时做不了平均分配功能)。其实就像是我们给7007分配slot槽的操作,只是双方角色互换了一下,用到的当然也是reshard命令了。

[root@Master src]# ./redis-trib.rb reshard 192.168.1.111:7007

输出如下:

/usr/local/rvm/gems/ruby-2.4.4/gems/redis-3.2.1/lib/redis/client.rb:443: warning: constant ::Fixnum is deprecated

>>> Performing Cluster Check (using node 192.168.1.111:7007)

M: bdb0ce9cc5cca545b9182a09346246827af40490 192.168.1.111:7007

slots:0-65,5461-5527,10923-10988 (199 slots) master

0 additional replica(s)

S: 146f1006dc5df60c3d4ac2867a21004deb8be6eb 192.168.1.111:7004

slots: (0 slots) slave

replicates 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac

S: 56fb12f39b02c38f2c43cfc19f7b9faafdd900a0 192.168.1.111:7006

slots: (0 slots) slave

replicates fbd2b0bf4ec21c23af7d15a20964688fb23f214c

M: b9e97e221fb3ae239cc0e2831779381ace7c6b9b 192.168.1.111:7002

slots:5528-10922 (5395 slots) master

M: 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 192.168.1.111:7001

slots:66-5460 (5395 slots) master

1 additional replica(s)

M: fbd2b0bf4ec21c23af7d15a20964688fb23f214c 192.168.1.111:7003

slots:10989-16383 (5395 slots) master

1 additional replica(s)

S: 53e5b386290843bb57af3c9cea8af7ccc38314f9 192.168.1.111:7005

slots: (0 slots) slave

replicates b9e97e221fb3ae239cc0e2831779381ace7c6b9b

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

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,我填的是7001的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:这里是数据源节点,当然填的是7007的Id了)

Source node #2:done

(ps:输入done表示可以开始生成迁移计划)

Ready to move 199 slots.

Source nodes:

M: bdb0ce9cc5cca545b9182a09346246827af40490 192.168.1.111:7007

slots:0-65,5461-5527,10923-10988 (199 slots) master

0 additional replica(s)

Destination node:

M: 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 192.168.1.111:7001

slots:66-5460 (5395 slots) master

1 additional replica(s)

Resharding plan:

Moving slot 0 from bdb0ce9cc5cca545b9182a09346246827af40490

.......

Do you want to proceed with the proposed reshard plan (yes/no)? yes

(ps:输入yes表示可以开始执行迁移计划)

Moving slot 0 from 192.168.1.111:7007 to 192.168.1.111:7001:

.........

步骤二:到此为止,我们应该是将7007主节点的slot槽全部迁移到7001上面去了,我们可以看一下现在的集群节点信息即可,可以看到,7007后面已经没有slot槽的信息了,而7001也多出了slot槽。

[root@Master src]# /usr/local/redis/bin/redis-cli -c -h 192.168.1.111 -p 7001

192.168.1.111:7001> cluster nodes

3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 192.168.1.111:7001 myself,master - 0 0 8 connected 0-5527 10923-10988

56fb12f39b02c38f2c43cfc19f7b9faafdd900a0 192.168.1.111:7006 slave fbd2b0bf4ec21c23af7d15a20964688fb23f214c 0 1534862478538 6 connected

b9e97e221fb3ae239cc0e2831779381ace7c6b9b 192.168.1.111:7002 master - 0 1534862483568 2 connected 5528-10922

53e5b386290843bb57af3c9cea8af7ccc38314f9 192.168.1.111:7005 slave b9e97e221fb3ae239cc0e2831779381ace7c6b9b 0 1534862479544 5 connected

fbd2b0bf4ec21c23af7d15a20964688fb23f214c 192.168.1.111:7003 master - 0 1534862482563 3 connected 10989-16383

bdb0ce9cc5cca545b9182a09346246827af40490 192.168.1.111:7007 master - 0 1534862480550 7 connected

146f1006dc5df60c3d4ac2867a21004deb8be6eb 192.168.1.111:7004 slave 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 0 1534862476524 8 connected

步骤三:最后我们可以直接使用del-node命令来删除7007主节点了。

[root@Master src]# ./redis-trib.rb del-node 192.168.1.111:7007 bdb0ce9cc5cca545b9182a09346246827af40490

>>> Removing node bdb0ce9cc5cca545b9182a09346246827af40490 from cluster 192.168.1.111:7007

/usr/local/rvm/gems/ruby-2.4.4/gems/redis-3.2.1/lib/redis/client.rb:443: warning: constant ::Fixnum is deprecated

>>> Sending CLUSTER FORGET messages to the cluster...

>>> SHUTDOWN the node.

最后:我们查看集群的节点信息,一切将还原到最初状态~

[root@Master src]# /usr/local/redis/bin/redis-cli -c -h 192.168.1.111 -p 7001

192.168.1.111:7001> cluster nodes

3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 192.168.1.111:7001 myself,master - 0 0 8 connected 0-5527 10923-10988

56fb12f39b02c38f2c43cfc19f7b9faafdd900a0 192.168.1.111:7006 slave fbd2b0bf4ec21c23af7d15a20964688fb23f214c 0 1534863137104 6 connected

b9e97e221fb3ae239cc0e2831779381ace7c6b9b 192.168.1.111:7002 master - 0 1534863140120 2 connected 5528-10922

53e5b386290843bb57af3c9cea8af7ccc38314f9 192.168.1.111:7005 slave b9e97e221fb3ae239cc0e2831779381ace7c6b9b 0 1534863141124 5 connected

fbd2b0bf4ec21c23af7d15a20964688fb23f214c 192.168.1.111:7003 master - 0 1534863143138 3 connected 10989-16383

146f1006dc5df60c3d4ac2867a21004deb8be6eb 192.168.1.111:7004 slave 3a9f07e1ed2f9a8c5e42d51f96bce53dc6a567ac 0 1534863142132 8 connected

192.168.1.111:7001>

猜你喜欢

转载自blog.csdn.net/Howinfun/article/details/81938161