起始配置6台 redis,3台 master

起始配置

配置文件

bind 0.0.0.0
daemonize yes
protected-mode no
port 6381
logfile "/myredis/cluster/cluster6381.log"
pidfile /myredis/cluster6381.pid
dir /myredis/cluster
dbfilename dump6381.rdb
appendonly yes
appendfilename "appendonly6381.aof"
requirepass 12345678
masterauth 12345678

cluster-enabled yes
cluster-config-file nodes-6381.conf
cluster-node-timeout 5000

服务器配置

3台服务器,每台启动两个

image-20230815142619236

启动

redis-server /path
redis-cli -a 12345678 --cluster create --cluster-replicas 1 192.168.10.3:6381 192.168.10.3:6382 192.168.10.6:6383 192.168.10.6:6384 192.168.10.7:6385 192.168.10.7:6386

image-20230815142809649

image-20230815142943326

image-20230815145247018

下线

image-20230815145334908

slave 替代下线 master

重新上线原 master 变成 slave

image-20230815145648031

恢复原从属关系

cluster failover

image-20230815145940819

扩容节点

配置说明

192.168.10.6 服务器上线两个,端口 687768786877master

这里配置写错了,原本是 63776378

查看还未加入集群前状态

image-20230815152637740

加入集群

redis-cli -a 12345678 --cluster add-node 192.168.10.6:6877 192.168.10.3:6381

image-20230815153510814

image-20230815153532522

0 分配 slot

image-20230815154019992

分配 slot

redis-cli -a 12345678 --cluster reshard 192.168.10.3:6381

image-20230815154747675

image-20230815154817178

新节点配置为 slave

redis-cli -a 12345678 --cluster add-node 192.168.16.6:6878 192.168.10.3:6381 --cluster-slave --cluster-master-id c6cd80a80cbb43edb0cc9bdc74537b8a1f79abd1
redis-cli -a 12345678 --cluster add-node addedIP:Port clusterIP:port --cluster-slave --cluster-master-id 跟随的master的ID

image-20230815155839031

image-20230815160154898

缩容节点

删除 slave

下线 192.168.10.6:6878

redis-cli -a 12345678 --cluster del-node 192.168.10.3:6381 29260c9eb3bb3f6645d0168f2b1bf5c60bcc605a

image-20230815160344401

重新分配 slot

192.168.10.6:6877 全部分配给 192.168.10.3:6381

redis-cli -a 12345678 --cluster reshard 192.168.10.3:6381

image-20230815161242160

图里写错了,192.168.10.6:6877 分配

image-20230815161328413

删除 master

redis-cli -a 12345678 --cluster del-node 192.168.10.3:6381 c6cd80a80cbb43edb0cc9bdc74537b8a1f79abd1

大致流程

image-20230815162536007

文章目录