上一篇说明了基于Redis Cluster搭建Redis集群的过程,下面继续说明下Redis集群中node增减过程。
我们再来测试一下,新加入一个节点,分2种情况,1是作为主节点,2是作为一个节点的从节点。我们分别来试一下:
[root@spg 7006]# ps -ef | grep redis
root 3063 2974 0 20:04 pts/0 00:00:12 redis-server *:7001 [cluster]
root 3081 2974 0 20:05 pts/0 00:00:11 redis-server *:7002 [cluster]
root 3093 2974 0 20:05 pts/0 00:00:11 redis-server *:7003 [cluster]
root 3109 2974 0 20:06 pts/0 00:00:11 redis-server *:7004 [cluster]
root 3123 2974 0 20:06 pts/0 00:00:11 redis-server *:7005 [cluster]
root 3487 2974 0 20:30 pts/0 00:00:06 redis-server *:7000 [cluster]
root 3981 2974 0 21:09 pts/0 00:00:00 redis-server *:7006 [cluster]
root 3993 2974 0 21:09 pts/0 00:00:00 grep --color=auto redis
将7006节点加入集群中:
redis-trib.rb add-node 127.0.0.1:7006 127.0.0.1:7000
add-node是加入指令,127.0.0.1:7006 表示新加入的节点,127.0.0.1:7000 表示加入的集群的一个节点,用来辨识是哪个集群,理论上哪个都可以。
[root@spg 7006]# redis-trib.rb add-node 127.0.0.1:7006 127.0.0.1:7000
>>> Adding node 127.0.0.1:7006 to cluster 127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7005: OK
>>> Performing Cluster Check (using node 127.0.0.1:7000)
S: be26c521481afcd6e739e2bfef69e9dcfb63d0a6 127.0.0.1:7000
slots: (0 slots) slave
replicates 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c
M: 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c 127.0.0.1:7003
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 947cc4a9e890672cfad4806a5921e9f8bdf05c05 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 05ac96f9cdee679f98e8f7ce8e97cf1cbea608ca 127.0.0.1:7004
slots: (0 slots) slave
replicates ce06b13387702c3ee63e0118dd10c5f81a1285b5
M: ce06b13387702c3ee63e0118dd10c5f81a1285b5 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: b65f33d97416795226964aa22f3b4a8ac7366a99 127.0.0.1:7005
slots: (0 slots) slave
replicates 947cc4a9e890672cfad4806a5921e9f8bdf05c05
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Connecting to node 127.0.0.1:7006: OK
>>> Send CLUSTER MEET to node 127.0.0.1:7006 to make it join the cluster.
[OK] New node added correctly.
从上面可以看出节点7006已经成功加入到集群中,此时可以查看集群节点状态
[root@spg 7006]# redis-trib.rb check 127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7005: OK
>>> Performing Cluster Check (using node 127.0.0.1:7000)
S: be26c521481afcd6e739e2bfef69e9dcfb63d0a6 127.0.0.1:7000
slots: (0 slots) slave
replicates 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c
M: fe595e7a38c659a6eb6949bb31fd7474881d6422 127.0.0.1:7006
slots: (0 slots) master
0 additional replica(s)
M: 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c 127.0.0.1:7003
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 947cc4a9e890672cfad4806a5921e9f8bdf05c05 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 05ac96f9cdee679f98e8f7ce8e97cf1cbea608ca 127.0.0.1:7004
slots: (0 slots) slave
replicates ce06b13387702c3ee63e0118dd10c5f81a1285b5
M: ce06b13387702c3ee63e0118dd10c5f81a1285b5 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: b65f33d97416795226964aa22f3b4a8ac7366a99 127.0.0.1:7005
slots: (0 slots) slave
replicates 947cc4a9e890672cfad4806a5921e9f8bdf05c05
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
可以很清楚的看到节点7006已经成功作为主节点加入到集群中了。
PS:也可以连接到客户端查看集群中节点状态,如下所示:
[root@spg 7006]# redis-cli -c -p 7006
127.0.0.1:7006> cluster nodes
fe595e7a38c659a6eb6949bb31fd7474881d6422 127.0.0.1:7006 myself,master - 0 0 0 connected
be26c521481afcd6e739e2bfef69e9dcfb63d0a6 127.0.0.1:7000 slave 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c 0 1456667011409 7 connected
947cc4a9e890672cfad4806a5921e9f8bdf05c05 127.0.0.1:7002 master - 0 1456667008376 3 connected 10923-16383
ce06b13387702c3ee63e0118dd10c5f81a1285b5 127.0.0.1:7001 master - 0 1456667007371 2 connected 5461-10922
b65f33d97416795226964aa22f3b4a8ac7366a99 127.0.0.1:7005 slave 947cc4a9e890672cfad4806a5921e9f8bdf05c05 0 1456667013968 3 connected
05ac96f9cdee679f98e8f7ce8e97cf1cbea608ca 127.0.0.1:7004 slave ce06b13387702c3ee63e0118dd10c5f81a1285b5 0 1456667013457 2 connected
1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c 127.0.0.1:7003 master - 0 1456667012429 7 connected 0-5460
但是,通过上面发现:
M: fe595e7a38c659a6eb6949bb31fd7474881d6422 127.0.0.1:7006
slots: (0 slots) master
0 additional replica(s)
0 slots?也就是说,虽然它现在是主节点,但是,却没有分配任何节点给它,也就是它现在还不负责数据存取。
看来,redis cluster 不是在新加节点的时候帮我们做好了迁移工作,需要我们手动对集群进行重新分片迁移,也是这个命令:
redis-trib.rb reshard 127.0.0.1:7000
这个命令是用来迁移slot节点的,后面的127.0.0.1:7000是表示是哪个集群,端口填[7000-7006]都可以,我们结果运行如下:
[root@spg 7006]# redis-trib.rb reshard 127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7005: OK
>>> Performing Cluster Check (using node 127.0.0.1:7000)
S: be26c521481afcd6e739e2bfef69e9dcfb63d0a6 127.0.0.1:7000
slots: (0 slots) slave
replicates 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c
M: fe595e7a38c659a6eb6949bb31fd7474881d6422 127.0.0.1:7006
slots: (0 slots) master
0 additional replica(s)
M: 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c 127.0.0.1:7003
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 947cc4a9e890672cfad4806a5921e9f8bdf05c05 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 05ac96f9cdee679f98e8f7ce8e97cf1cbea608ca 127.0.0.1:7004
slots: (0 slots) slave
replicates ce06b13387702c3ee63e0118dd10c5f81a1285b5
M: ce06b13387702c3ee63e0118dd10c5f81a1285b5 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: b65f33d97416795226964aa22f3b4a8ac7366a99 127.0.0.1:7005
slots: (0 slots) slave
replicates 947cc4a9e890672cfad4806a5921e9f8bdf05c05
[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)?
它提示我们需要迁移多少slot到7006上,我们可以算一下:16384/4 = 4096,也就是说,为了平衡分配起见,我们需要移动4096个槽点到7006上。
好,那输入4096:
How many slots do you want to move (from 1 to 16384)? 4096
What is the receiving node ID?
此时又提示我们,接受的node ID是多少,7006的id 我们通过上面就可以看到是fe595e7a38c659a6eb6949bb31fd7474881d6422
What is the receiving node ID? fe595e7a38c659a6eb6949bb31fd7474881d6422
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:
接着, redis-trib 会向你询问重新分片的源节点(source node), 也即是, 要从哪个节点中取出 4096 个哈希槽, 并将这些槽移动到7006节点上面。
如果我们不打算从特定的节点上取出指定数量的哈希槽, 那么可以向 redis-trib 输入 all , 这样的话, 集群中的所有主节点都会成为源节点, redis-trib 将从各个源节点中各取出一部分哈希槽, 凑够 4096 个, 然后移动到7006节点上:
Source node #1:all
接下来就开始迁移了,并且会询问你是否确认:
Do you want to proceed with the proposed reshard plan (yes/no)?
输入 yes 并使用按下回车之后, redis-trib 就会正式开始执行重新分片操作, 将指定的哈希槽从源节点一个个地移动到7006节点上面。
迁移完毕之后,我们来检查下:
[root@spg 7006]# redis-trib.rb check 127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7005: OK
>>> Performing Cluster Check (using node 127.0.0.1:7000)
S: be26c521481afcd6e739e2bfef69e9dcfb63d0a6 127.0.0.1:7000
slots: (0 slots) slave
replicates 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c
M: fe595e7a38c659a6eb6949bb31fd7474881d6422 127.0.0.1:7006
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
0 additional replica(s)
M: 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c 127.0.0.1:7003
slots:1365-5460 (4096 slots) master
1 additional replica(s)
M: 947cc4a9e890672cfad4806a5921e9f8bdf05c05 127.0.0.1:7002
slots:12288-16383 (4096 slots) master
1 additional replica(s)
S: 05ac96f9cdee679f98e8f7ce8e97cf1cbea608ca 127.0.0.1:7004
slots: (0 slots) slave
replicates ce06b13387702c3ee63e0118dd10c5f81a1285b5
M: ce06b13387702c3ee63e0118dd10c5f81a1285b5 127.0.0.1:7001
slots:6827-10922 (4096 slots) master
1 additional replica(s)
S: b65f33d97416795226964aa22f3b4a8ac7366a99 127.0.0.1:7005
slots: (0 slots) slave
replicates 947cc4a9e890672cfad4806a5921e9f8bdf05c05
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
7006节点情况如下
M: fe595e7a38c659a6eb6949bb31fd7474881d6422 127.0.0.1:7006
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
0 additional replica(s)
至此,集群中新加入主节点已经完成。
2.让节点作为从节点加入集群。
我们再新建一个节点7007,步骤类似,就先省略了。建好后,启动起来,我们看如何把它加入到集群中的从节点中:
[root@spg 7007]# redis-trib.rb add-node --slave 127.0.0.1:7007 127.0.0.1:7000
add-node的时候加上–slave表示是加入到从节点中,但是这样加,是随机的。这里的命令行完全像我们在添加一个新主服务器时使用的一样,所以我们没有指定要给哪个主服 务器添加副本。这种情况下,redis-trib 会将7007作为一个具有较少副本的随机的主服务器的副本。
那么,你猜,它会作为谁的从节点,应该是7006,因为7006还没有从节点。我们运行下。
>>> Adding node 127.0.0.1:7007 to cluster 127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7006: OK
>>> Performing Cluster Check (using node 127.0.0.1:7000)
S: be26c521481afcd6e739e2bfef69e9dcfb63d0a6 127.0.0.1:7000
slots: (0 slots) slave
replicates 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c
M: 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c 127.0.0.1:7003
slots:1365-5460 (4096 slots) master
1 additional replica(s)
S: b65f33d97416795226964aa22f3b4a8ac7366a99 127.0.0.1:7005
slots: (0 slots) slave
replicates 947cc4a9e890672cfad4806a5921e9f8bdf05c05
S: 05ac96f9cdee679f98e8f7ce8e97cf1cbea608ca 127.0.0.1:7004
slots: (0 slots) slave
replicates ce06b13387702c3ee63e0118dd10c5f81a1285b5
M: 947cc4a9e890672cfad4806a5921e9f8bdf05c05 127.0.0.1:7002
slots:12288-16383 (4096 slots) master
1 additional replica(s)
M: ce06b13387702c3ee63e0118dd10c5f81a1285b5 127.0.0.1:7001
slots:6827-10922 (4096 slots) master
1 additional replica(s)
M: fe595e7a38c659a6eb6949bb31fd7474881d6422 127.0.0.1:7006
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Automatically selected master 127.0.0.1:7006
Connecting to node 127.0.0.1:7007: OK
>>> Send CLUSTER MEET to node 127.0.0.1:7007 to make it join the cluster.
Waiting for the cluster to join.3417:M 29 Feb 21:03:48.490 # IP address for this node updated to 127.0.0.1
>>> Configure node as replica of 127.0.0.1:7006.
3417:S 29 Feb 21:03:49.423 # Cluster state changed: ok
[OK] New node added correctly.
上面提示已经选择了7006作为主节点,将7007成功加入集群,同时你可以检查集群各节点状况。
上面的过程是集群自动分配主节点给新加入的从节点。
但是,是否可以指定主节点呢?当然可以。我们再建一个7008节点。
[root@spg 7008]# redis-trib.rb add-node --slave --master-id fe595e7a38c659a6eb6949bb31fd7474881d6422 127.0.0.1:7008 127.0.0.1:7003
–master-id 表示指定的主节点node id。这里指定的是 7006 这个主节点。
>>> Performing Cluster Check (using node 127.0.0.1:7003)
M: 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c 127.0.0.1:7003
slots:1365-5460 (4096 slots) master
1 additional replica(s)
S: e896e0dfb21716540e091129fbf18cc7d473faa9 127.0.0.1:7007
slots: (0 slots) slave
replicates fe595e7a38c659a6eb6949bb31fd7474881d6422
S: b65f33d97416795226964aa22f3b4a8ac7366a99 127.0.0.1:7005
slots: (0 slots) slave
replicates 947cc4a9e890672cfad4806a5921e9f8bdf05c05
S: 05ac96f9cdee679f98e8f7ce8e97cf1cbea608ca 127.0.0.1:7004
slots: (0 slots) slave
replicates ce06b13387702c3ee63e0118dd10c5f81a1285b5
M: fe595e7a38c659a6eb6949bb31fd7474881d6422 127.0.0.1:7006
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
1 additional replica(s)
M: 947cc4a9e890672cfad4806a5921e9f8bdf05c05 127.0.0.1:7002
slots:12288-16383 (4096 slots) master
1 additional replica(s)
M: ce06b13387702c3ee63e0118dd10c5f81a1285b5 127.0.0.1:7001
slots:6827-10922 (4096 slots) master
1 additional replica(s)
S: be26c521481afcd6e739e2bfef69e9dcfb63d0a6 127.0.0.1:7000
slots: (0 slots) slave
replicates 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Connecting to node 127.0.0.1:7008: OK
>>> Send CLUSTER MEET to node 127.0.0.1:7008 to make it join the cluster.
Waiting for the cluster to join.3571:M 29 Feb 21:15:08.600 # IP address for this node updated to 127.0.0.1
>>> Configure node as replica of 127.0.0.1:7006.
3571:S 29 Feb 21:15:09.497 # Cluster state changed: ok
[OK] New node added correctly.
可以看出7008作为7006的从节点成功加入集群中。你也可以检查集群状态看各节点状态。如下:
[root@spg 7008]# redis-trib.rb check 127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7008: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7007: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7006: OK
>>> Performing Cluster Check (using node 127.0.0.1:7000)
S: be26c521481afcd6e739e2bfef69e9dcfb63d0a6 127.0.0.1:7000
slots: (0 slots) slave
replicates 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c
S: 357c88af6960a11c130e0180038f8d095179b8e7 127.0.0.1:7008
slots: (0 slots) slave
replicates fe595e7a38c659a6eb6949bb31fd7474881d6422
M: 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c 127.0.0.1:7003
slots:1365-5460 (4096 slots) master
1 additional replica(s)
S: 05ac96f9cdee679f98e8f7ce8e97cf1cbea608ca 127.0.0.1:7004
slots: (0 slots) slave
replicates ce06b13387702c3ee63e0118dd10c5f81a1285b5
M: 947cc4a9e890672cfad4806a5921e9f8bdf05c05 127.0.0.1:7002
slots:12288-16383 (4096 slots) master
1 additional replica(s)
M: ce06b13387702c3ee63e0118dd10c5f81a1285b5 127.0.0.1:7001
slots:6827-10922 (4096 slots) master
1 additional replica(s)
S: e896e0dfb21716540e091129fbf18cc7d473faa9 127.0.0.1:7007
slots: (0 slots) slave
replicates fe595e7a38c659a6eb6949bb31fd7474881d6422
S: b65f33d97416795226964aa22f3b4a8ac7366a99 127.0.0.1:7005
slots: (0 slots) slave
replicates 947cc4a9e890672cfad4806a5921e9f8bdf05c05
M: fe595e7a38c659a6eb6949bb31fd7474881d6422 127.0.0.1:7006
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
2 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
redis-trib del-node 127.0.0.1:7000 ``
和新加节点有点不同的是,移除需要节点的node-id。那我们尝试将7006这个主节点移除:
[root@spg 7008]# redis-trib.rb del-node 127.0.0.1:7000 fe595e7a38c659a6eb6949bb31fd7474881d6422
>>> Removing node fe595e7a38c659a6eb6949bb31fd7474881d6422 from cluster 127.0.0.1:7000
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7007: OK
Connecting to node 127.0.0.1:7008: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7002: OK
[ERR] Node 127.0.0.1:7006 is not empty! Reshard data away and try again.
报错了,它提示我们说,由于7006里面已经有数据了,不能被移除,要先将它的数据转移出去。也就是说得重新分片,用上面增加新节点后的分片方式一样,用我们再来一遍:
redis-trib.rb reshard 127.0.0.1:7000
How many slots do you want to move (from 1 to 16384)?
提示,我们要分多少个槽点,由于7007上有4096个槽点,所以这里填写4096
How many slots do you want to move (from 1 to 16384)? 4096
What is the receiving node ID?
提示我们,需要移动到哪个id上,那就填7001的吧:
What is the receiving node ID? ce06b13387702c3ee63e0118dd10c5f81a1285b5
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:
这里就是关键了,它要我们从哪个节点去转移数据到7001,因为我们是要删除7006的,所以,我们就得7006的id了
Source node #1:fe595e7a38c659a6eb6949bb31fd7474881d6422
Source node #2:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes
ok,这样就迁移好了。好,现在再进行移除节点操作:
[root@spg 7007]# redis-trib.rb del-node 127.0.0.1:7003 fe595e7a38c659a6eb6949bb31fd7474881d6422
>>> Removing node fe595e7a38c659a6eb6949bb31fd7474881d6422 from cluster 127.0.0.1:7003
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7008: OK
Connecting to node 127.0.0.1:7000: OK
>>> Sending CLUSTER FORGET messages to the cluster...
>>> 127.0.0.1:7007 as replica of 127.0.0.1:7003
>>> 127.0.0.1:7008 as replica of 127.0.0.1:7003
3571:S 29 Feb 21:59:10.922 # Connection with master lost.
3571:S 29 Feb 21:59:10.922 * Caching the disconnected master state.
3571:S 29 Feb 21:59:10.922 * Discarding previously cached master state.
>>> SHUTDOWN the node.
删除成功,而且还很人性化的将7007和7008这2个没了爹的孩子送给了7003。
此时再尝试连接7006,则提示连接不上了。
[root@spg 7007]# redis-trib.rb check 127.0.0.1:7006
Connecting to node 127.0.0.1:7006: [ERR] Sorry, can't connect to node 127.0.0.1:7006
4.移除一个从节点
移除一个从节点就简单的多了,因为不需要考虑数据的迁移,我们7008给移除:
[root@spg 7007]# redis-trib.rb del-node 127.0.0.1:7003 357c88af6960a11c130e0180038f8d095179b8e7
>>> Removing node 357c88af6960a11c130e0180038f8d095179b8e7 from cluster 127.0.0.1:7003
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7008: OK
Connecting to node 127.0.0.1:7000: OK
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
3571:S 29 Feb 22:03:33.763 # User requested shutdown...
3571:S 29 Feb 22:03:33.763 * Calling fsync() on the AOF file.
3571:S 29 Feb 22:03:33.763 * Saving the final RDB snapshot before exiting.
3571:S 29 Feb 22:03:33.769 * DB saved on disk
3571:S 29 Feb 22:03:33.769 # Redis is now ready to exit, bye bye...
[3]- 完成 redis-server redis.conf(工作目录:/home/shipg/soft/redis/redis-claster/7008)
(当前工作目录:/home/shipg/soft/redis/redis-claster/7007)
至此,redis集群中增删节点部分已经尝试完成,redsi cluster 稳定版本也越来越稳定,相信不久,它肯定会成为主流,所以,还有很多 cluster 命令还没讲到,还有很多维护没讲道,篇幅有限,下一次有时间的话再继续研究。