1.初始化集群
echo "yes"|redis-cli --cluster create 10.0.0.51:6380 10.0.0.52:6380 10.0.0.53:6380 10.0.0.51:6381 10.0.0.52:6381 10.0.0.53:6381 --cluster-replicas 1
2.扩容节点
添加主节点:
redis-cli --cluster add-node 10.0.0.51:6390 10.0.0.51:6380
添加从节点:
redis-cli --cluster add-node 10.0.0.51:6391 10.0.0.51:6390 --cluster-slave --cluster-master-id $(redis-cli -h 10.0.0.51 -p 6380 cluster nodes|awk '/51:6390/{print $1}')
迁移槽位
redis-cli --cluster reshard 10.0.0.51:6390 --cluster-from all --cluster-to $(redis-cli -h 10.0.0.51 -p 6380 cluster nodes|awk '/51:6390/{print $1}') --cluster-slots 4096 --cluster-yes
3.收缩节点
迁移槽位
redis-cli --cluster rebalance 10.0.0.51:6380 --cluster-weight $(redis-cli -h 10.0.0.51 -p 6380 cluster nodes|awk '/51:6390/{print $1}')=0 $(redis-cli -h 10.0.0.51 -p 6380 cluster nodes|awk '/51:6380/{print $1}')=1 $(redis-cli -h 10.0.0.51 -p 6380 cluster nodes|awk '/52:6380/{print $1}')=1 $(redis-cli -h 10.0.0.51 -p 6380 cluster nodes|awk '/53:6380/{print $1}')=1
下线节点
redis-cli --cluster del-node 10.0.0.51:6380 $(redis-cli -h 10.0.0.51 -p 6380 cluster nodes|awk '/51:6390/{print $1}')