Redis5 集群命令
参考:https://www.jianshu.com/p/6355d0827aea
连接集群:./src/redis-cli -a zzs@888 -c -h 172.16.164.31 -p 8001
-
cluster info 查看集群状态、槽分配、集群大小等
172.16.164.31:8001> cluster info
-
cluster nodes 查看主从节点
172.16.164.31:8001> cluster nodes
-
cluster meet 添加节点进入集群 (添加进集群为master,但没有分配槽)
172.16.164.31:8001> cluster meet 172.16.164.31 8007
-
reshard 为新节点分配slot
[root@iZbp12nyvj1faz8f0boyo1Z redis-5.0.4]# ./src/redis-cli –cluster reshard 172.16.164.31:8007 -a zzs@888
-
info 查看主节点信息
[root@iZbp12nyvj1faz8f0boyo1Z redis-5.0.4]# ./src/redis-cli –cluster info 172.16.164.31:8007 -a zzs@888
-
check 检查集群信息
[root@iZbp12nyvj1faz8f0boyo1Z redis-5.0.4]# ./src/redis-cli –cluster check 172.16.164.31:8007 -a zzs@888
-
添加从节点
[root@iZbp12nyvj1faz8f0boyo1Z redis-5.0.4]# ./src/redis-cli –cluster add-node 172.16.164.31:8008 172.16.164.31:8001 -a zzs@888 新添加8008节点进集群为主节点
连接集群8008节点客户端
[root@iZbp12nyvj1faz8f0boyo1Z redis-5.0.4]# ./src/redis-cli -c -h 172.16.164.31 -p 8008 -a zzs@888
使用集群命令replicate来指定当前节点(从节点)的主节点id为哪个
172.16.164.31:8008> cluster replicate 3505cfea4d97d18d35c8a354cbcac5fe82eb3109 (这个是Master 8007节点ID,把8008变成8007 slave节点)
-
删除8008节点
用del-node删除从节点8008,指定删除节点ip和端口,以及节点id 8008节点是slave 没有分配slot槽,可以直接删
[root@iZbp12nyvj1faz8f0boyo1Z redis-5.0.4]# ./src/redis-cli –cluster del-node 172.16.164.31:8008 4b908cd1bf00f92a9d87d3b3b17c82ec65693b32 -a zzs@888
[root@iZbp12nyvj1faz8f0boyo1Z redis-5.0.4]# ./src/redis-cli –cluster check 172.16.164.31:8007 -a zzs@888 检查集群节点
-
删除节点8007
8007节点因为这个步骤相对比较麻烦一些,因为主节点的里面是有分配了hash槽的,所以我们这里必须先把8007里的hash槽放入到其他的可用主节点中去,然后再进行移除节点操作,不然会出现数据丢失问题(目前只能把master的数据迁移到一个节点上,暂时做不了平均分配功能) 可以把8007节点分配到8001上
[root@iZbp12nyvj1faz8f0boyo1Z redis-5.0.4]# ./src/redis-cli –cluster reshard 172.16.164.31:8007 -a zzs@888
8007节点已经没有slot,全部被转移到8001节点上了
ok,那么删除8007节点
[root@iZbp12nyvj1faz8f0boyo1Z redis-5.0.4]# ./src/redis-cli –cluster del-node 172.16.164.31:8007 3505cfea4d97d18d35c8a354cbcac5fe82eb3109 -a zzs@888
查看集群
10.设置心率连接超时时间
[root@iZbp12nyvj1faz8f0boyo1Z redis-5.0.4]# ./src/redis-cli –cluster set-timeout 172.16.164.31:8001 4000 -a zzs@888
11.平衡集群节点slots
[root@iZbp12nyvj1faz8f0boyo1Z redis-5.0.4]# ./src/redis-cli –cluster rebalance –cluster-simulate –cluster-threshold 1 172.16.164.31:8001 -a zzs@888