Redis入门到精通-Redis集群的扩展

来源:互联网 发布:半包包括哪些 知乎 编辑:程序博客网 时间:2024/06/06 00:15

Redis集群的扩展

1 redis-trib.rb 命令介绍:

[root@localhost ~]# /usr/local/src/redis3.2/src/redis-trib.rbUsage: redis-trib <command> <options> <arguments ...>  create          host1:port1 ... hostN:portN                  --replicas <arg>  check           host:port  fix             host:port  reshard         host:port                  --from <arg>                  --to <arg>                  --slots <arg>                  --yes  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>  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.[root@localhost ~]#

​ call:执行 redis 命令

​ create:创建一个新的集群(上一节教程有介绍)

​ add-node: 将一个节点添加到集群里面,第一个是新节点 ip:port, 第二个是集群中任意一个正常节点ip:port,--master-id

​ reshard:重新分片check:查看集群信息del-node:移除一个节点

2 节点准备

(1)按照之前的操作,新建两个服务,一主一从。

[root@localhost ~]# mkdir -p /usr/local/rediscluster/7117[root@localhost ~]# mkdir -p /usr/local/rediscluster/7118[root@localhost ~]# cp /usr/local/rediscluster/7111/redis-7111.conf /usr/local/rediscluster/7117/redis-7117.conf[root@localhost ~]# cp /usr/local/rediscluster/7111/redis-7111.conf /usr/local/rediscluster/7118/redis-7118.conf[root@localhost ~]# vim /usr/local/rediscluster/7117/redis-7117.conf[root@localhost ~]# vim /usr/local/rediscluster/7117/redis-7118.conf

​ 修改内容如下:

​ port:7117(7118)

​ dir:/usr/local/rediscluster/7117(7118)

​ cluster:/usr/local/rediscluster/7117/node-7117.conf

(2) 启动这两个实例

[root@localhost ~]# /usr/local/redis/bin/redis-server /usr/local/redis-cluster/7117/redis-7117.conf[root@localhost ~]# /usr/local/redis/bin/redis-server /usr/local/redis-cluster/7118/redis-7118.conf

3 添加新的Mater节点

(1)添加Master节点

[root@localhost ~]# /usr/local/src/redis3.2/src/redis-trib.rb add-node 10.0.31.144:7117 10.0.31.144:7111>>> Adding node 10.0.31.144:7117 to cluster 10.0.31.144:7111Connecting to node 10.0.31.144:7111: OKConnecting to node 10.0.31.144:7112: OKConnecting to node 10.0.31.144:7115: OKConnecting to node 10.0.31.144:7113: OKConnecting to node 10.0.31.144:7116: OKConnecting to node 10.0.31.144:7114: OK>>> Performing Cluster Check (using node 10.0.31.144:7111)M: c639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7111   slots:0-5460 (5461 slots) master   1 additional replica(s)M: 815a0c11695a42cdb46104444f8c29a9ac5ea897 10.0.31.144:7112   slots:5461-10922 (5462 slots) master   1 additional replica(s)S: 4f8dd744609a135777d07d18e8faf18c6833e96d 10.0.31.144:7115   slots: (0 slots) slave   replicates 815a0c11695a42cdb46104444f8c29a9ac5ea897M: 203bc8721443aa8432b9397cfe0daa07f5d603a0 10.0.31.144:7113   slots:10923-16383 (5461 slots) master   1 additional replica(s)S: a350fb4762033ded64d6dbb778004889de673e37 10.0.31.144:7116   slots: (0 slots) slave   replicates 203bc8721443aa8432b9397cfe0daa07f5d603a0S: c639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7114   slots: (0 slots) slave   replicates c639cce2bbe1334d15e7dcba2635f14b7b0ff4af[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.Connecting to node 10.0.31.144:7117: OK>>> Send CLUSTER MEET to node 10.0.31.144:7117 to make it join the cluster.[OK] New node added correctly.[root@localhost ~]#

​ 以上操作结果表示节点添加成功,新增的节点不包含任何数据, 因为它没有分配任何 slot。​ 新加入的节点是一个 master 节点,当集群需要将某个从节点升级为新的主节点时,这个新节点不会被选中。

(2)为新的Master节点分配哈希槽(slot):

​ 你只需要指定集群中其中一个节点的地址,redis-trib 就会自动找到集群中的其他节点。目前 redis-trib

只能在管理员的协助下完成重新分片的工作,命令如下:

[root@localhost ~]# /usr/local/src/redis3.2/src/redis-trib.rb reshard 10.0.31.144:7111Connecting to node 10.0.31.144:7111: OKConnecting to node 10.0.31.144:7112: OKConnecting to node 10.0.31.144:7115: OKConnecting to node 10.0.31.144:7113: OKConnecting to node 10.0.31.144:7117: OKConnecting to node 10.0.31.144:7116: OKConnecting to node 10.0.31.144:7114: OK>>> Performing Cluster Check (using node 10.0.31.144:7111)M: c639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7111   slots:0-5460 (5461 slots) master   1 additional replica(s)M: 815a0c11695a42cdb46104444f8c29a9ac5ea897 10.0.31.144:7112   slots:5461-10922 (5462 slots) master   1 additional replica(s)S: 4f8dd744609a135777d07d18e8faf18c6833e96d 10.0.31.144:7115   slots: (0 slots) slave   replicates 815a0c11695a42cdb46104444f8c29a9ac5ea897M: 203bc8721443aa8432b9397cfe0daa07f5d603a0 10.0.31.144:7113   slots:10923-16383 (5461 slots) master   1 additional replica(s)M: 12de059b89c35063540d4fb2f5b6ee4afe811391 10.0.31.144:7117   slots: (0 slots) master   0 additional replica(s)S: a350fb4762033ded64d6dbb778004889de673e37 10.0.31.144:7116   slots: (0 slots) slave   replicates 203bc8721443aa8432b9397cfe0daa07f5d603a0S: c639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7114   slots: (0 slots) slave   replicates c639cce2bbe1334d15e7dcba2635f14b7b0ff4af[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)? 500

​ 上面的提示是确认你打算移动的哈希槽 slots 的数量(这里槽数量设置为 500)

​ 除了移动的哈希槽数量之外, redis-trib 还需要知道重新分片的目标(target node), 也就是负责接收这 500 个哈希槽的节点。指定目标需要使用节点的 ID , 而不是 IP 地址和端口。我们打算向上面新增的主节点来作为目标, 它的 IP 地址和端口是 10.0.31.144:7117,而节点 ID 则是12de059b89c35063540d4fb2f5b6ee4afe811391 , 那么我们应该向 redis-trib 提供节点的 ID :

What is the receiving node ID? 12de059b89c35063540d4fb2f5b6ee4afe811391

​ 接下来 redis-trib 会向你询问重新分片的源节点(source node), 也就是要从哪个节点中取出 500 个哈希槽,并将这些槽移动到目标节点上面。如果我们不打算从特定的节点上取出指定数量的哈希槽, 那么可以向 redis-trib 输入 all , 这样的话, 集群中的所有主节点都会成为源节点, redis-trib 将从各个源节点中各取出一部分哈希槽, 凑够 500 个, 然后移动到目标节点上面:

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

​ 输入 all 并按下回车之后, redis-trib 将打印出哈希槽的移动计划:

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

​ 如果你觉得没问题的话, 就可以输入 yes 并再次按回车确认, redis-trib 就会正式开始执行重新分片操作, 将指定的哈希槽从源节点一个个地移动到目标节点上面。​ 这样就完成了从7111、7112、7113上总共移动500个slot到7117上,观察:

[root@localhost ~]# /usr/local/redis/bin/redis-cli -c -h 10.0.31.144 -p 711110.0.31.144:7111> cluster nodes815a0c11695a42cdb46104444f8c29a9ac5ea897 10.0.31.144:7112 master - 0 1508664510079 2 connected 5628-109224f8dd744609a135777d07d18e8faf18c6833e96d 10.0.31.144:7115 slave 815a0c11695a42cdb46104444f8c29a9ac5ea897 0 1508664509072 5 connected203bc8721443aa8432b9397cfe0daa07f5d603a0 10.0.31.144:7113 master - 0 1508664508067 3 connected 11089-1638312de059b89c35063540d4fb2f5b6ee4afe811391 10.0.31.144:7117 master - 0 1508664507062 7 connected 0-165 5461-5627 10923-11088a350fb4762033ded64d6dbb778004889de673e37 10.0.31.144:7116 slave 203bc8721443aa8432b9397cfe0daa07f5d603a0 0 1508664507062 6 connectedc639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7111 myself,master - 0 0 1 connected 166-5460c639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7114 slave c639cce2bbe1334d15e7dcba2635f14b7b0ff4af 0 1508664511087 4 connected10.0.31.144:7111>

(3)检查集群是否正常:

[root@localhost ~]# /usr/local/src/redis3.2/src/redis-trib.rb check 10.0.31.144:7111Connecting to node 10.0.31.144:7111: OKConnecting to node 10.0.31.144:7112: OKConnecting to node 10.0.31.144:7115: OKConnecting to node 10.0.31.144:7113: OKConnecting to node 10.0.31.144:7117: OKConnecting to node 10.0.31.144:7116: OKConnecting to node 10.0.31.144:7114: OK>>> Performing Cluster Check (using node 10.0.31.144:7111)M: c639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7111   slots:166-5460 (5295 slots) master   1 additional replica(s)M: 815a0c11695a42cdb46104444f8c29a9ac5ea897 10.0.31.144:7112   slots:5628-10922 (5295 slots) master   1 additional replica(s)S: 4f8dd744609a135777d07d18e8faf18c6833e96d 10.0.31.144:7115   slots: (0 slots) slave   replicates 815a0c11695a42cdb46104444f8c29a9ac5ea897M: 203bc8721443aa8432b9397cfe0daa07f5d603a0 10.0.31.144:7113   slots:11089-16383 (5295 slots) master   1 additional replica(s)M: 12de059b89c35063540d4fb2f5b6ee4afe811391 10.0.31.144:7117   slots:0-165,5461-5627,10923-11088 (499 slots) master   0 additional replica(s)S: a350fb4762033ded64d6dbb778004889de673e37 10.0.31.144:7116   slots: (0 slots) slave   replicates 203bc8721443aa8432b9397cfe0daa07f5d603a0S: c639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7114   slots: (0 slots) slave   replicates c639cce2bbe1334d15e7dcba2635f14b7b0ff4af[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.[root@localhost ~]#

4 添加新的Slave节点

​ 将准备好的7118添加为7117的slave

​ (1) 新增节点

[root@localhost ~]# /usr/local/src/redis3.2/src/redis-trib.rb add-node 10.0.31.144:7118 10.0.31.144:7117>>> Adding node 10.0.31.144:7118 to cluster 10.0.31.144:7117Connecting to node 10.0.31.144:7117: OKConnecting to node 10.0.31.144:7115: OKConnecting to node 10.0.31.144:7111: OKConnecting to node 10.0.31.144:7114: OKConnecting to node 10.0.31.144:7113: OKConnecting to node 10.0.31.144:7116: OKConnecting to node 10.0.31.144:7112: OK>>> Performing Cluster Check (using node 10.0.31.144:7117)M: 12de059b89c35063540d4fb2f5b6ee4afe811391 10.0.31.144:7117   slots:0-165,5461-5627,10923-11088 (499 slots) master   0 additional replica(s)S: 4f8dd744609a135777d07d18e8faf18c6833e96d 10.0.31.144:7115   slots: (0 slots) slave   replicates 815a0c11695a42cdb46104444f8c29a9ac5ea897M: c639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7111   slots:166-5460 (5295 slots) master   1 additional replica(s)S: c639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7114   slots: (0 slots) slave   replicates c639cce2bbe1334d15e7dcba2635f14b7b0ff4afM: 203bc8721443aa8432b9397cfe0daa07f5d603a0 10.0.31.144:7113   slots:11089-16383 (5295 slots) master   1 additional replica(s)S: a350fb4762033ded64d6dbb778004889de673e37 10.0.31.144:7116   slots: (0 slots) slave   replicates 203bc8721443aa8432b9397cfe0daa07f5d603a0M: 815a0c11695a42cdb46104444f8c29a9ac5ea897 10.0.31.144:7112   slots:5628-10922 (5295 slots) master   1 additional replica(s)[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.Connecting to node 10.0.31.144:7118: OK>>> Send CLUSTER MEET to node 10.0.31.144:7118 to make it join the cluster.[OK] New node added correctly.[root@localhost ~}#

​ (2)检查节点信息:我们发现新增的7118是master。

[root@localhost ~]# /usr/local/redis/bin/redis-cli -c -h 10.0.31.144 -p 711110.0.31.144:7111> cluster nodes815a0c11695a42cdb46104444f8c29a9ac5ea897 10.0.31.144:7112 master - 0 1508665125230 2 connected 5628-109224f8dd744609a135777d07d18e8faf18c6833e96d 10.0.31.144:7115 slave 815a0c11695a42cdb46104444f8c29a9ac5ea897 0 1508665126237 5 connected203bc8721443aa8432b9397cfe0daa07f5d603a0 10.0.31.144:7113 master - 0 1508665123214 3 connected 11089-1638312de059b89c35063540d4fb2f5b6ee4afe811391 10.0.31.144:7117 master - 0 1508665122209 7 connected 0-165 5461-5627 10923-11088a350fb4762033ded64d6dbb778004889de673e37 10.0.31.144:7116 slave 203bc8721443aa8432b9397cfe0daa07f5d603a0 0 1508665120195 6 connectedc639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7111 myself,master - 0 0 1 connected 166-546097b47c985d3b0f3e20e77a57f18f7c8457d45e55 10.0.31.144:7118 master - 0 1508665125733 0 connectedc639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7114 slave c639cce2bbe1334d15e7dcba2635f14b7b0ff4af 0 1508665124221 4 connected10.0.31.144:7111>

​ (3)redis-cli 连接上7118新节点 shell,输入命令:cluster replicate 对应 master7117 的 node-id

[root@localhost ~]# /usr/local/redis/bin/redis-cli -c -h 10.0.31.144 -p 711810.0.31.144:7118> cluster replicate 12de059b89c35063540d4fb2f5b6ee4afe811391OK10.0.31.144:7118>

​ (4)检查节点信息:7118变成了7117的slave。

10.0.31.144:7118> cluster nodesa350fb4762033ded64d6dbb778004889de673e37 10.0.31.144:7116 slave 203bc8721443aa8432b9397cfe0daa07f5d603a0 0 1508665356571 3 connected97b47c985d3b0f3e20e77a57f18f7c8457d45e55 10.0.31.144:7118 myself,slave 12de059b89c35063540d4fb2f5b6ee4afe811391 0 0 0 connectedc639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7114 slave c639cce2bbe1334d15e7dcba2635f14b7b0ff4af 0 1508665359086 1 connected12de059b89c35063540d4fb2f5b6ee4afe811391 10.0.31.144:7117 master - 0 1508665357577 7 connected 0-165 5461-5627 10923-11088815a0c11695a42cdb46104444f8c29a9ac5ea897 10.0.31.144:7112 master - 0 1508665361603 2 connected 5628-10922203bc8721443aa8432b9397cfe0daa07f5d603a0 10.0.31.144:7113 master - 0 1508665360597 3 connected 11089-163834f8dd744609a135777d07d18e8faf18c6833e96d 10.0.31.144:7115 slave 815a0c11695a42cdb46104444f8c29a9ac5ea897 0 1508665359589 2 connectedc639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7111 master - 0 1508665358583 1 connected 166-546010.0.31.144:7118>

5 在线reshared数据

​ 对于负载/数据不均匀的情况,可以在线reshard slot来解决,方法与添加新master的reshard一样,只是需要 reshard 的 master 节点是老节点。

6 移除Slave节点

​ 输入del-node命令,指定移除节点IP:端口 id(节点的id)

[root@localhost ~]# /usr/local/src/redis3.2/src/redis-trib.rb del-node 10.0.31.144:7118 97b47c985d3b0f3e20e77a57f18f7c8457d45e55>>> Removing node 97b47c985d3b0f3e20e77a57f18f7c8457d45e55 from cluster 10.0.31.144:7118Connecting to node 10.0.31.144:7118: OKConnecting to node 10.0.31.144:7116: OKConnecting to node 10.0.31.144:7114: OKConnecting to node 10.0.31.144:7117: OKConnecting to node 10.0.31.144:7112: OKConnecting to node 10.0.31.144:7113: OKConnecting to node 10.0.31.144:7115: OKConnecting to node 10.0.31.144:7111: OK>>> Sending CLUSTER FORGET messages to the cluster...>>> SHUTDOWN the node.[root@localhost ~]#

​ 查看节点状态:

[root@localhost ~]# /usr/local/redis/bin/redis-cli -c -h 10.0.31.144 -p 7111 cluster nodes815a0c11695a42cdb46104444f8c29a9ac5ea897 10.0.31.144:7112 master - 0 1508666165068 2 connected 5628-109224f8dd744609a135777d07d18e8faf18c6833e96d 10.0.31.144:7115 slave 815a0c11695a42cdb46104444f8c29a9ac5ea897 0 1508666164063 5 connected203bc8721443aa8432b9397cfe0daa07f5d603a0 10.0.31.144:7113 master - 0 1508666165572 3 connected 11089-1638312de059b89c35063540d4fb2f5b6ee4afe811391 10.0.31.144:7117 master - 0 1508666167081 7 connected 0-165 5461-5627 10923-11088a350fb4762033ded64d6dbb778004889de673e37 10.0.31.144:7116 slave 203bc8721443aa8432b9397cfe0daa07f5d603a0 0 1508666166075 6 connectedc639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7111 myself,master - 0 0 1 connected 166-5460c639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7114 slave c639cce2bbe1334d15e7dcba2635f14b7b0ff4af 0 1508666162048 4 connected[root@localhost ~]#

7 移除Master节点

​ 删除 master 节点之前首先要使用 reshard 移除该 master 的全部 slot,然后再删除当前节点(目前只能把被删除 master 的 slot 迁移到一个节点上),操作和分配 slot 类似,指定具体的 Source node 即可。

/usr/local/src/redis3.2/src/redis-trib.rb reshard 10.0.31.144:7117Connecting to node 192.168.1.117:7117: OKConnecting to node 192.168.1.112:7112: OKConnecting to node 192.168.1.115:7115: OKConnecting to node 192.168.1.114:7114: OKConnecting to node 192.168.1.111:7111: OKConnecting to node 192.168.1.116:7116: OKConnecting to node 192.168.1.113:7113: OK>>> Performing Cluster Check (using node 192.168.1.117:7117)M: 12de059b89c35063540d4fb2f5b6ee4afe811391 192.168.1.117:7117   slots:0-165,5461-5627,10923-11088 (499 slots) master0 additional replica(s)M:815a0c11695a42cdb46104444f8c29a9ac5ea897 192.168.1.112:7112   slots:5628-10922 (5295 slots) master   1 additional replica(s)S: f34b28f1483f0c0d9543e93938fc12b8818050cb 192.168.1.115:7115   slots: (0 slots) slave   replicates815a0c11695a42cdb46104444f8c29a9ac5ea897M: c639cce2bbe1334d15e7dcba2635f14b7b0ff4af 192.168.1.114:7114   slots:11089-16383 (5295 slots) master   1 additional replica(s)S: 8dd55e9b4da9f62b9b15232e86553f1337864179 192.168.1.111:7111   slots: (0 slots) slave   replicates c639cce2bbe1334d15e7dcba2635f14b7b0ff4afS: 1fd90d54090925afb4087d4ef94a1710a25160d6 192.168.1.116:7116   slots: (0 slots) slave   replicates 203bc8721443aa8432b9397cfe0daa07f5d603a0M: 203bc8721443aa8432b9397cfe0daa07f5d603a0 192.168.1.113:7113   slots:166-5460 (5295 slots) master1 additional replica(s)[OK] All nodes agree about slots configuration. >>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.//输入被删除 master 的所有 slot 数量How many slots do you want to move (from 1 to 16384)? 499//接收 slot 的 master 节点 IDWhat is the receiving node ID? c639cce2bbe1334d15e7dcba2635f14b7b0ff4afPlease 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.//准备被删除 master 节点的 node-idSource node #1:12de059b89c35063540d4fb2f5b6ee4afe811391Source node #2:doneReady to move 499 slots.  ......//省略移除日志[root@localhost ~]#

​ 检查节点信息: 7117不在占用slot

[root@localhost ~]# /usr/local/redis/bin/redis-cli -c -h 10.0.31.144 -p 7111 cluster nodes815a0c11695a42cdb46104444f8c29a9ac5ea897 10.0.31.144:7112 master - 0 1508666678128 2 connected 5628-109224f8dd744609a135777d07d18e8faf18c6833e96d 10.0.31.144:7115 slave 815a0c11695a42cdb46104444f8c29a9ac5ea897 0 1508666679134 5 connected203bc8721443aa8432b9397cfe0daa07f5d603a0 10.0.31.144:7113 master - 0 1508666680139 3 connected 11089-1638312de059b89c35063540d4fb2f5b6ee4afe811391 10.0.31.144:7117 master - 0 1508666681147 7 connecteda350fb4762033ded64d6dbb778004889de673e37 10.0.31.144:7116 slave 203bc8721443aa8432b9397cfe0daa07f5d603a0 0 1508666677122 6 connected88da0083291b0a732ec9ca502b2cfccfc296dcbb 10.0.31.144:7111 myself,master - 0 0 8 connected 0-5627 10923-11088c639cce2bbe1334d15e7dcba2635f14b7b0ff4af 10.0.31.144:7114 slave 88da0083291b0a732ec9ca502b2cfccfc296dcbb 0 1508666675111 8 connected[root@localhost ~]#

​ 确认已清空该 Master 节点的所有 slot 后就可以删除该节点了(命令与删除 slave 节点一样):

[root@localhost ~]# /usr/local/src/redis3.2/src/redis-trib.rb del-node 10.0.31.144:7117 12de059b89c35063540d4fb2f5b6ee4afe811391>>> Removing node 12de059b89c35063540d4fb2f5b6ee4afe811391 from cluster 10.0.31.144:7117Connecting to node 10.0.31.144:7117: OKConnecting to node 10.0.31.144:7115: OKConnecting to node 10.0.31.144:7111: OKConnecting to node 10.0.31.144:7114: OKConnecting to node 10.0.31.144:7113: OKConnecting to node 10.0.31.144:7116: OKConnecting to node 10.0.31.144:7112: OK>>> Sending CLUSTER FORGET messages to the cluster...>>> SHUTDOWN the node.[root@localhost ~]#

​ 最后检查服务状态:发现被移除的节点,服务也关闭了。

[root@localhost ~]# ps -ef|grep redisroot      1908     1  0 16:43 ?        00:00:05 /usr/local/redis/bin/redis-server 10.0.31.144:7111 [cluster]root      1912     1  0 16:43 ?        00:00:05 /usr/local/redis/bin/redis-server 10.0.31.144:7112 [cluster]root      1917     1  0 16:43 ?        00:00:05 /usr/local/redis/bin/redis-server 10.0.31.144:7113 [cluster]root      1921     1  0 16:43 ?        00:00:04 /usr/local/redis/bin/redis-server 10.0.31.144:7114 [cluster]root      1928     1  0 16:43 ?        00:00:05 /usr/local/redis/bin/redis-server 10.0.31.144:7115 [cluster]root      1934     1  0 16:43 ?        00:00:04 /usr/local/redis/bin/redis-server 10.0.31.144:7116 [cluster]root      5148  1718  0 18:18 pts/0    00:00:00 grep redis[root@localhost ~]#