Redis——对集群cluster的操作命令
删除一个节点 90b34bf34f7061dc5f9d61f3561086f2ba180bab 是 6323 的id
docker exec -it redis1 redis-cli -h 172.31.140.161 -p 6321 --cluster del-node 172.31.140.161:6321 90b34bf34f7061dc5f9d61f3561086f2ba180bab
查看集群节点状态
docker exec -it redis1 redis-cli -h 172.31.140.161 -p 6321 cluster nodes
查看集群中的所有key
docker exec -it redis1 redis-cli -h 172.31.140.161 -p 6321 --cluster call 172.31.140.161:6321 keys "*"
查看节点的主从状态
docker exec -it redis3 redis-cli -h 172.31.140.161 -p 6323 info replication
清除所有数据
docker exec -it redis3 redis-cli -h 172.31.140.161 -p 6323 flushdb
节点slave 变 master, 需要删除文件后,重启节点
removed ‘dump.rdb’
removed ‘redis3_cluster.conf’
把 172.31.140.161:6323 节点加入集群,最后一个参数是集群中的一个已有健康节点
docker exec -it redis1 redis-cli -h 172.31.140.161 -p 6321 --cluster add-node 172.31.140.161:6323 172.31.140.161:6321
把192.168.1.20:6301 节点从集群中移除,
前提条件是该节点的slots已迁走,可先添加一个新节点再迁走slots,
去除命令: ./redis-cli --cluster del-node [节点ip]:[端口] [节点ID]
docker exec -it redisnode1 redis-cli -h 192.168.1.21 -p 6301 --cluster del-node 192.168.1.20:6301 26628db2d0e62996f61a41e9fa0d2f80cf7e6d41
手动重新分配 16384 个 slots
docker exec -it redis1 redis-cli -h 172.31.140.161 -p 6321 --cluster reshard 172.31.140.161:6321
按提示输入slots个数,接受节点,源节点
docker exec -it redis1 redis-cli -h 172.31.140.161 -p 6321 \
--cluster reshard 172.31.140.161:6321 >>> Performing Cluster Check (using node 172.31.140.161:6321) M: 60988515df740ac95be96140f8eb8e7f4e51cf2c 172.31.140.161:6321 slots:[2833-5460] (2628 slots) master M: 7d85093d8ce9e410f2b0829de2b44a6040a39d7b 172.31.140.161:6326 slots: (0 slots) master M: 7f28ba6811dd3d958a5f6c85af852563ff12949c 172.31.140.161:6324 slots:[833-2832] (2000 slots) master M: 430d3250d575ec138cdd15a9d9cd65f0b96ae668 172.31.140.161:6322 slots:[6295-10922] (4628 slots) master M: 824a62be2ca3f9a1614e8fd73813b5a304ccba18 172.31.140.161:6325 slots:[11756-16383] (4628 slots) master M: 416bb1b4254eb49af6c95acd66905dedd152b219 172.31.140.161:6323 slots:[0-832],[5461-6294],[10923-11755] (2500 slots) master [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)? 3000 What is the receiving node ID? 7d85093d8ce9e410f2b0829de2b44a6040a39d7b 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: 430d3250d575ec138cdd15a9d9cd65f0b96ae668 Source node #2: 824a62be2ca3f9a1614e8fd73813b5a304ccba18 Source node #3: done