# Redis集群缩容
###1、迁移槽到其他节点
槽点信息:
7979884fe3020a77decb542b5f841dce99fa555e 127.0.0.1:8007@18007 slave f8b5360af3341fc0f87b9492b4a3d69689ef1072 0 1535035117200 9 connected
f8b5360af3341fc0f87b9492b4a3d69689ef1072 127.0.0.1:8006@18006 myself,master - 0 1535035113000 9 connected 0-1363 5461-6826 10923-12286
a2d034b74c9cec4cd8398e8b23ae2d2ab124d49d 127.0.0.1:8000@18000 slave 9d1cb9fea95f1b205fc7a5ecb20125259765d6ca 0 1535035116193 7 connected
fd17cbac4a5ca1942490d3734a73387341e80fb7 127.0.0.1:8005@18005 slave f5960002d40cf3711eca7146719c4f568115f76c 0 1535035114000 3 connected
1f0d813205ea17d9b254488215bd48612c0ff2b5 127.0.0.1:8001@18001 master - 0 1535035114000 2 connected 6827-10922
9d1cb9fea95f1b205fc7a5ecb20125259765d6ca 127.0.0.1:8003@18003 master - 0 1535035114000 7 connected 1364-5460
f5960002d40cf3711eca7146719c4f568115f76c 127.0.0.1:8002@18002 master - 0 1535035115000 3 connected 12287-16383
93ae6d9a42bf485a955d2387b0a0d659e2c12902 127.0.0.1:8004@18004 slave 1f0d813205ea17d9b254488215bd48612c0ff2b5 0 1535035115189 2 connected
将8006的1365迁移到8001节点上:
./redis-trib.rb reshard --slots 1365 --to 1f0d813205ea17d9b254488215bd48612c0ff2b5 --from f8b5360af3341fc0f87b9492b4a3d69689ef1072 --yes 127.0.0.1:8000
将8006的1365迁移到8002节点上:
./redis-trib.rb reshard --slots 1365 --to f5960002d40cf3711eca7146719c4f568115f76c --from f8b5360af3341fc0f87b9492b4a3d69689ef1072 --yes 127.0.0.1:8000
将8006的1365迁移到8003节点上:
./redis-trib.rb reshard --slots 1365 --to 9d1cb9fea95f1b205fc7a5ecb20125259765d6ca --from f8b5360af3341fc0f87b9492b4a3d69689ef1072 --yes 127.0.0.1:8000
###2、集群忘记节点(del-node从集群中删除节点)
del-node可以把某个节点从集群中删除。del-node只能删除没有分配slot的节点。删除命令传递两个参数:
host:port:从该节点获取集群信息。
node_id:需要删除的节点id。
先删除8007从节点:
./redis-trib.rb del-node 127.0.0.1:8000 7979884fe3020a77decb542b5f841dce99fa555e
删除8006节点:
./redis-trib.rb del-node 127.0.0.1:8000 f8b5360af3341fc0f87b9492b4a3d69689ef1072
结果:
[root@redis src]# ./redis-trib.rb del-node 127.0.0.1:8000 7979884fe3020a77decb542b5f841dce99fa555e
>>> Removing node 7979884fe3020a77decb542b5f841dce99fa555e from cluster 127.0.0.1:8000
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
[root@redis src]#
[root@redis src]#
[root@redis src]# ./redis-trib.rb del-node 127.0.0.1:8000 f8b5360af3341fc0f87b9492b4a3d69689ef1072
>>> Removing node f8b5360af3341fc0f87b9492b4a3d69689ef1072 from cluster 127.0.0.1:8000
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
1f0d813205ea17d9b254488215bd48612c0ff2b5 127.0.0.1:8001@18001 master - 0 1535037041000 10 connected 0-1363 6827-10922
f5960002d40cf3711eca7146719c4f568115f76c 127.0.0.1:8002@18002 master - 0 1535037043283 11 connected 5461-6824 12287-16383
93ae6d9a42bf485a955d2387b0a0d659e2c12902 127.0.0.1:8004@18004 slave 1f0d813205ea17d9b254488215bd48612c0ff2b5 0 1535037041000 10 connected
a2d034b74c9cec4cd8398e8b23ae2d2ab124d49d 127.0.0.1:8000@18000 myself,slave 9d1cb9fea95f1b205fc7a5ecb20125259765d6ca 0 1535037038000 1 connected
fd17cbac4a5ca1942490d3734a73387341e80fb7 127.0.0.1:8005@18005 slave f5960002d40cf3711eca7146719c4f568115f76c 0 1535037042278 11 connected
9d1cb9fea95f1b205fc7a5ecb20125259765d6ca 127.0.0.1:8003@18003 master - 0 1535037042000 12 connected 1364-5460 6825-6826 10923-12286
![](https://i-blog.csdnimg.cn/blog_migrate/07df64cf5f8739d9e4ee18585da0bd9c.jpeg#pic_center)