redis-6.2.5集群部署手册

文章目录

  • 1、部署规划
  • 2、句柄调整
  • 3、内核调整(可选)
  • 4、部署 jdk (可选)
    • 4.1、解压版本
    • 4.2、环境变量
  • 5、上传解压
  • 6、编译安装
  • 7、创建配置
  • 8、启动服务
  • 9、创建集群
  • 10、验证集群
  • 11、停止服务
  • 12、附录
    • 12.1、增加节点
    • 12.2、删除节点
    • 12.3、选举机制
    • 12.4、安装ruby(参考)
    • 12.4、集群修复
    • 12.5、aof损坏
    • 12.6、恢复数据(可选)
    • 12.7、数据迁移
    • 12.8、故障转移
    • 12.9、动态扩缩
      • 12.9.1、新增主机
      • 12.9.2、查看集群
      • 12.9.3、分配槽位
    • 12.10、动态缩容
      • 12.10.1、查看集群
      • 12.10.2、删除槽位
        • 12.10.2.1、分配slot给master1
        • 12.10.2.2、分配slot给master2
        • 12.10.2.3、分配slot给master3
      • 12.10.3、移除主机

1、部署规划

IP host 版本 端口
192.168.179.10 node1 redis-6.2.5 9821,9822,9823
192.168.179.11 node2 redis-6.2.5 9824,9825,9826

2、句柄调整

【所有节点均需操作】

1、检查limits.conf,增加如下2行配置:
# vim /etc/security/limits.conf
*   soft   core  0
*   hard   core  0
*   soft   nofile  131072
*   hard   nofile  131072
*   soft   nproc   131072
*   hard   nproc   131072

3、内核调整(可选)

【所有节点均需操作】

【增加配置】
# vim /etc/sysctl.conf
<追加>
vm.max_map_count=262144
net.core.somaxconn=32768
vm.overcommit_memory=0
vm.max_map_count=262144

【生效修改】
# sysctl -p

4、部署 jdk (可选)

4.1、解压版本

# tar xf jdk-8u301-linux-x64.tar.gz -C /home/
# mv /home/jdk1.8.0_301 /home/java

4.2、环境变量

【追加配置】
# cat << EOF >> /etc/profile
#jdk#
export JAVA_HOME=/home/java
export JRE_HOME=\$JAVA_HOME/jre
export CLASS_PATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar
export PATH=\$JAVA_HOME/bin:\$PATH
EOF

【生效配置】
# source /etc/profile

5、上传解压

# tar zxvf redis-6.2.5.tar.gz -C /home/
# mv /home/redis-6.2.5 /home/redis

6、编译安装

# cd /home/redis
# make MALLOC=libc && make install

【如果报错ld不存在,则执行如下命令】
# cd /usr/bin;ll ld*
	ld -> /etc/alternatives/ld
	ld.gold
# mv ld ld_old
# ln -s  ld.gold ld

7、创建配置

# mkdir -p /home/redis/cluster /home/redis/logs/ /home/redis/data/
# cd cluster/

【配置一个文件后,其它配置文件只需拷贝并修改端口】
# cat << EOF > redis_9821.conf
bind 0.0.0.0
protected-mode yes
port 9821
daemonize yes
tcp-backlog 511
timeout 0
tcp-keepalive 300
supervised no
pidfile /home/redis/run/redis_9821.pid
loglevel notice
logfile "/home/redis/logs/redis_9821.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump_9821.rdb
dir /home/redis/data/
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes
appendfilename "appendonly_9821.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
requirepass Drms@12#$
masterauth Drms@12#$
cluster-enabled yes
cluster-config-file nodes-9821.conf
cluster-node-timeout 5000
EOF

【拷贝文件】
# for i in {2..6};do cp redis_9821.conf redis_982${i}.conf ;sed -i "s/9821/982${i}/g" redis_982${i}.conf;done

8、启动服务

【192.168.179.10】
# /home/redis/src/redis-server /home/redis/cluster/redis_9821.conf \
&& /home/redis/src/redis-server /home/redis/cluster/redis_9822.conf \
&& /home/redis/src/redis-server /home/redis/cluster/redis_9823.conf

【192.168.179.11】
# /home/redis/src/redis-server /home/redis/cluster/redis_9824.conf \
&& /home/redis/src/redis-server /home/redis/cluster/redis_9825.conf \
&& /home/redis/src/redis-server /home/redis/cluster/redis_9826.conf

9、创建集群

【192.168.179.10】
# /home/redis/src/redis-cli -a 'Drms@12#$' --cluster create 192.168.179.10:9821 192.168.179.10:9822 192.168.179.10:9823 192.168.179.11:9824 192.168.179.11:9825 192.168.179.11:9826 --cluster-replicas 1

Can I set the above configuration? (type 'yes' to accept): yes

说明:--cluster-replicas master和slave的比例,此处权重1,则3主3从。

10、验证集群

# /home/redis/src/redis-cli -c -h 192.168.179.10 -p 9821 -a 'Drms@12#$'
@ 测试读写
172.16.12.229:9821> set k1 v1
172.16.12.229:9823> keys *
172.16.12.229:9823> get "k1"
@ 查看集群节点
172.16.12.229:9821> cluster nodes
@ 查看集群信息
172.16.12.229:9821> cluster info
@ 查看槽位信息
172.16.12.229:9821> cluster slots
@ 计算key的槽位
172.16.12.229:9821> cluster keyslot "k1"

11、停止服务

# ps -ef|grep -v grep|grep "/home/redis/src/redis-server.*982.*"|awk '{print $2}'|xargs kill -9

12、附录

12.1、增加节点

【新增配置】【192.168.179.11】
# cp redis_9821.conf redis_7006.conf ;sed -i "s/9821/7006/g" redis_7006.conf

【启动服务】
# /home/redis/src/redis-server /home/redis/cluster/redis_7006.conf

【增加节点】
# /home/redis/src/redis-cli -c -h 192.168.179.10 -p 9821 -a 'Drms@12#$'
192.168.179.10:9822> CLUSTER MEET 192.168.179.11 7006
192.168.179.10:9822> CLUSTER NODES

注意:新增的节点都是以master身份加入集群。

12.2、删除节点

# /home/redis/src/redis-cli -c -h 192.168.179.10 -p 9821 -a 'Drms@12#$'
192.168.179.10:9822> CLUSTER FORGET 6788453ee9a8d7f72b1d45a9093838efd0e501f1
OK              #可以删除master节点(除myself)
192.168.179.10:9822> CLUSTER FORGET b4d3eb411a7355d4767c6c23b4df69fa183ef8bc
OK              #可以删除slave节点(除myself)
192.168.179.10:9822> CLUSTER NODES

12.3、选举机制

注意:master节点如果挂掉,则它的slave节点变为新master节点继续对外提供服务,而原来的master节点如果恢复,则变为新master节点的slave节点。

12.4、安装ruby(参考)

【新版已开始弃用ruby,可使用redis-cli代替redis-trib.rb】

【下载离线rpm】【有网络的linux主机(虚拟机)操作】
# yum install --downloadonly --downloaddir=temp ruby
【强制安装rpm包】
# rpm -ivh --force --nodeps *.rpm

12.4、集群修复

【检查节点】
# /home/redis/src/redis-cli --cluster check 192.168.179.10:9821 -a 'Drms@12#$'

【修复节点】
# /home/redis/src/redis-cli --cluster fix 192.168.179.10:9821 -a 'Drms@12#$'
<选择yes>

12.5、aof损坏

# /home/redis/src/redis-check-aof --fix appendonly.aof
<选择yes>

注意:可能会清空aof文件。

12.6、恢复数据(可选)

【默认无需手动操作,重启会自动恢复】

【检查aof文件】
# /home/redis/src/redis-check-aof /home/redis/data/appendonly.aof
# /home/redis/src/redis-cli -h 192.168.179.10 -p 9821 -a 'Drms@12#$' --pipe < /home/redis/data/appendonly.aof
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 7108

12.7、数据迁移

【方式1】
1、复制源节点的AOF文件到目标主机后
2、清空目标实例所有key:flushall
3、导入AOF文件至目标实例:/home/redis/src/redis-cli -h 192.168.179.10 -p 9821 -a 'Drms@12#$' --pipe < /home/redis/data/appendonly.aof

【方式2】
1、复制源节点的RDB文件到目标主机后
2、重启目标实例的服务,触发自动恢复RDB文件

12.8、故障转移

【master异常后,slave自动切换为master,人工干预启动原实例后,原实例自动变为slave,并加入集群】

【=== 查询集群信息 ===】
# /home/redis/src/redis-cli -h 192.168.179.10 -p 9821 -a 'Drms@12#$' cluster nodes
8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824@19824 slave fb96a9aa70b269936cd266f860e8e36960b90058 0 1661394989000 4 connected
fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821@19821 myself,master - 0 1661394989000 1 connected 0-5460
df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825@19825 slave 6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 0 1661394990000 5 connected
1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823@19823 master - 0 1661394990322 3 connected 10923-16383
6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822@19822 master - 0 1661394990526 2 connected 5461-10922
75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826@19826 slave 1e4432f5bc7fb4ecebf12291eafb987d901872f7 0 1661394989508 6 connected


【=== 停止master 9822来模拟故障 ===】
# kill -9 # ps -ef|grep 9822
root      37467      1  0 08:59 ?        00:00:06 /home/redis/src/redis-server 0.0.0.0:9822 [cluster]
# kill -9 37467

【=== 检查集群 ===】
# /home/redis/src/redis-cli -h 192.168.179.10 -p 9821 -a 'Drms@12#$' cluster nodes
8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824@19824 slave fb96a9aa70b269936cd266f860e8e36960b90058 0 1661395169509 4 connected
fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821@19821 myself,master - 0 1661395166000 1 connected 0-5460
df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825@19825 master - 0 1661395168000 7 connected 5461-10922           # --- 切换为master
1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823@19823 master - 0 1661395168492 3 connected 10923-16383
6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822@19822 master,fail - 1661395063725 1661395063587 2 disconnected  # --- 9822断连
75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826@19826 slave 1e4432f5bc7fb4ecebf12291eafb987d901872f7 0 1661395168000 6 connected

# /home/redis/src/redis-cli --cluster check 192.168.179.10:9821 -a 'Drms@12#$'
Could not connect to Redis at 192.168.179.10:9822: Connection refused
192.168.179.10:9821 (fb96a9aa...) -> 6672 keys | 5461 slots | 1 slaves.
192.168.179.10:9825 (df0a8e45...) -> 6672 keys | 5462 slots | 0 slaves.
192.168.179.10:9823 (1e4432f5...) -> 6656 keys | 5461 slots | 1 slaves.
[OK] 20000 keys in 3 masters.
1.22 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.179.10:9821)
M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824
   slots: (0 slots) slave
   replicates fb96a9aa70b269936cd266f860e8e36960b90058
M: df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825
   slots:[5461-10922] (5462 slots) master
M: 1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826
   slots: (0 slots) slave
   replicates 1e4432f5bc7fb4ecebf12291eafb987d901872f7
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.


【=== 启动9822实例 ===】
# /home/redis/src/redis-server /home/redis/cluster/redis_9822.conf

【=== 检查集群 ===】
# /home/redis/src/redis-cli -h 192.168.179.10 -p 9821 -a 'Drms@12#$' cluster nodes
8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824@19824 slave fb96a9aa70b269936cd266f860e8e36960b90058 0 1661395344000 4 connected
fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821@19821 myself,master - 0 1661395346000 1 connected 0-5460
df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825@19825 master - 0 1661395345571 7 connected 5461-10922
1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823@19823 master - 0 1661395346000 3 connected 10923-16383
6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822@19822 slave df0a8e4503c472be07ed2770ef435e018d07e3cc 0 1661395346077 7 connected  # 启动后变为slave
75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826@19826 slave 1e4432f5bc7fb4ecebf12291eafb987d901872f7 0 1661395345366 6 connected

# /home/redis/src/redis-cli --cluster check 192.168.179.10:9821 -a 'Drms@12#$'
192.168.179.10:9821 (fb96a9aa...) -> 6672 keys | 5461 slots | 1 slaves.
192.168.179.10:9825 (df0a8e45...) -> 6672 keys | 5462 slots | 1 slaves.
192.168.179.10:9823 (1e4432f5...) -> 6656 keys | 5461 slots | 1 slaves.
[OK] 20000 keys in 3 masters.
1.22 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.179.10:9821)
M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824
   slots: (0 slots) slave
   replicates fb96a9aa70b269936cd266f860e8e36960b90058
M: df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822
   slots: (0 slots) slave
   replicates df0a8e4503c472be07ed2770ef435e018d07e3cc
S: 75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826
   slots: (0 slots) slave
   replicates 1e4432f5bc7fb4ecebf12291eafb987d901872f7
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

12.9、动态扩缩

【正常扩容应该是扩主机,此处举例仅为扩实例】

12.9.1、新增主机

【新增9827实例】
# cp redis_9821.conf redis_9827.conf ;sed -i "s/9821/9827/g" redis_9827.conf
# cp redis_9821.conf redis_9828.conf ;sed -i "s/9821/9828/g" redis_9828.conf

【启动服务】
# /home/redis/src/redis-server /home/redis/cluster/redis_9827.conf
# /home/redis/src/redis-server /home/redis/cluster/redis_9828.conf    # --- 后面用作slave加入集群

【加入集群】
# /home/redis/src/redis-cli -c -h 192.168.179.10 -p 9821 -a 'Drms@12#$'
192.168.179.10:9826> CLUSTER MEET 192.168.179.10 9827
OK
192.168.179.10:9826> CLUSTER NODES
439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827@19827 master - 0 1661395861093 0 connected  # --- 新增实例,角色为master
6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822@19822 slave df0a8e4503c472be07ed2770ef435e018d07e3cc 0 1661395861502 7 connected
fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821@19821 master - 0 1661395861000 1 connected 0-5460
df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825@19825 master - 0 1661395861502 7 connected 5461-10922
8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824@19824 slave fb96a9aa70b269936cd266f860e8e36960b90058 0 1661395861000 4 connected
75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826@19826 myself,slave 1e4432f5bc7fb4ecebf12291eafb987d901872f7 0 1661395859000 6 connected
1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823@19823 master - 0 1661395862011 3 connected 10923-16383

12.9.2、查看集群

# /home/redis/src/redis-cli --cluster check 192.168.179.10:9821 -a 'Drms@12#$'
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.179.10:9821 (fb96a9aa...) -> 6672 keys | 5461 slots | 1 slaves.
192.168.179.10:9825 (df0a8e45...) -> 6672 keys | 5462 slots | 1 slaves.
192.168.179.10:9827 (439686e1...) -> 0 keys | 0 slots | 0 slaves.         # --- 新增实例此时并没有分配slot槽位,所以现在无法写入数据
192.168.179.10:9823 (1e4432f5...) -> 6656 keys | 5461 slots | 1 slaves.
[OK] 20000 keys in 4 masters.
1.22 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.179.10:9821)
M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824
   slots: (0 slots) slave
   replicates fb96a9aa70b269936cd266f860e8e36960b90058
M: df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827
   slots: (0 slots) master
M: 1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822
   slots: (0 slots) slave
   replicates df0a8e4503c472be07ed2770ef435e018d07e3cc
S: 75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826
   slots: (0 slots) slave
   replicates 1e4432f5bc7fb4ecebf12291eafb987d901872f7
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

12.9.3、分配槽位

【新节点加到集群之后,默认为master节点,且没有slots,需要重新分配,添加主机之后需要对添加至集群种的新主机重新分片,否则其没有分片也就无法写入数据】

【分配槽位】
# /home/redis/src/redis-cli --cluster reshard 192.168.179.10:9821 -a 'Drms@12#$'
>>> Performing Cluster Check (using node 192.168.179.10:9821)
M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824
   slots: (0 slots) slave
   replicates fb96a9aa70b269936cd266f860e8e36960b90058
M: df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827   # ID 从这获取
   slots: (0 slots) master
M: 1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822
   slots: (0 slots) slave
   replicates df0a8e4503c472be07ed2770ef435e018d07e3cc
S: 75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826
   slots: (0 slots) slave
   replicates 1e4432f5bc7fb4ecebf12291eafb987d901872f7
[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)? 4096  #==== 输入需要新分配多少个槽位 16384 (槽总数) / 4(master数) = 4096
What is the receiving node ID? 439686e1130c6ac7a1d8b87f7d485875dc3872a3  #==== 输入新实例master的ID
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots. #==== 从所有节点中划分出4096个哈希槽分配给新节点
  Type 'done' once you entered all the source nodes IDs. #==== 从cluster删除某个主机,并将该主机上的槽位全部移动到新增节点
Source node #1: all   #==== 输入all

Ready to move 4096 slots.
  Source nodes:
    M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
       slots:[0-5460] (5461 slots) master
       1 additional replica(s)
    M: df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825
       slots:[5461-10922] (5462 slots) master
       1 additional replica(s)
    M: 1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823
       slots:[10923-16383] (5461 slots) master
       1 additional replica(s)
  Destination node:
    M: 439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827
       slots: (0 slots) master
  Resharding plan:
    Moving slot 5461 from df0a8e4503c472be07ed2770ef435e018d07e3cc
	......
Do you want to proceed with the proposed reshard plan (yes/no)? yes  #==== 输入yes确认分配
Moving slot 5461 from 192.168.179.10:9825 to 192.168.179.10:9827: ..
......

【确定槽位是否分配成功】
# /home/redis/src/redis-cli --cluster check 192.168.179.10:9821 -a 'Drms@12#$'
192.168.179.10:9821 (fb96a9aa...) -> 4988 keys | 4096 slots | 1 slaves.
192.168.179.10:9825 (df0a8e45...) -> 5011 keys | 4096 slots | 1 slaves.
192.168.179.10:9827 (439686e1...) -> 5000 keys | 4096 slots | 0 slaves.   #==== 槽位分配成功
192.168.179.10:9823 (1e4432f5...) -> 5001 keys | 4096 slots | 1 slaves.
[OK] 20000 keys in 4 masters.
1.22 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.179.10:9821)
M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
S: 8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824
   slots: (0 slots) slave
   replicates fb96a9aa70b269936cd266f860e8e36960b90058
M: df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
M: 439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
M: 1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822
   slots: (0 slots) slave
   replicates df0a8e4503c472be07ed2770ef435e018d07e3cc
S: 75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826
   slots: (0 slots) slave
   replicates 1e4432f5bc7fb4ecebf12291eafb987d901872f7
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

【确认新master是否有数据】
# /home/redis/src/redis-cli -h 192.168.179.10 -p 9827 -a 'Drms@12#$' dbsize
(integer) 5000

【给新增的master分配slave节点】
# /home/redis/src/redis-cli -c -h 192.168.179.10 -p 9821 -a 'Drms@12#$' --cluster add-node 192.168.179.10:9828 192.168.179.10:9827 --cluster-slave --cluster-master-id 439686e1130c6ac7a1d8b87f7d485875dc3872a3
>>> Adding node 192.168.179.10:9828 to cluster 192.168.179.10:9827   #==== 添加9828为9827的slave
>>> Performing Cluster Check (using node 192.168.179.10:9827)
M: 439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
S: 75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826
   slots: (0 slots) slave
   replicates 1e4432f5bc7fb4ecebf12291eafb987d901872f7
M: df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
M: 1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822
   slots: (0 slots) slave
   replicates df0a8e4503c472be07ed2770ef435e018d07e3cc
S: 8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824
   slots: (0 slots) slave
   replicates fb96a9aa70b269936cd266f860e8e36960b90058
M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.179.10:9828 to make it join the cluster.
Waiting for the cluster to join
..
>>> Configure node as replica of 192.168.179.10:9827.
[OK] New node added correctly.


【检查9828是否已添加,并作为9827的slave】
# /home/redis/src/redis-cli -h 192.168.179.10 -p 9821 -a 'Drms@12#$' cluster nodes
8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824@19824 slave fb96a9aa70b269936cd266f860e8e36960b90058 0 1661398788143 4 connected
fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821@19821 myself,master - 0 1661398788000 1 connected 1365-5460
df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825@19825 master - 0 1661398788000 7 connected 6827-10922
439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827@19827 master - 0 1661398789594 8 connected 0-1364 5461-6826 10923-12287
1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823@19823 master - 0 1661398788000 3 connected 12288-16383
6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822@19822 slave df0a8e4503c472be07ed2770ef435e018d07e3cc 0 1661398789187 7 connected
75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826@19826 slave 1e4432f5bc7fb4ecebf12291eafb987d901872f7 0 1661398789594 6 connected
fc983b60f3d81199da82871cf937c9053ce8c7a2 192.168.179.10:9828@19828 slave 439686e1130c6ac7a1d8b87f7d485875dc3872a3 0 1661398789086 8 connected  #====9827的slave

12.10、动态缩容

【删除节点需先将槽位迁移到集群中的其他节点上,然后再将其删除】

12.10.1、查看集群

# /home/redis/src/redis-cli --cluster check 192.168.179.10:9821 -a 'Drms@12#$'
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.179.10:9821 (fb96a9aa...) -> 4988 keys | 4096 slots | 1 slaves.
192.168.179.10:9825 (df0a8e45...) -> 5011 keys | 4096 slots | 1 slaves.
192.168.179.10:9827 (439686e1...) -> 5000 keys | 4096 slots | 1 slaves.      #==== 将4096个槽位迁移到其他3个节点
192.168.179.10:9823 (1e4432f5...) -> 5001 keys | 4096 slots | 1 slaves.
[OK] 20000 keys in 4 masters.
1.22 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.179.10:9821)
M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
S: 8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824
   slots: (0 slots) slave
   replicates fb96a9aa70b269936cd266f860e8e36960b90058
M: df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
M: 439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
   1 additional replica(s)
M: 1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822
   slots: (0 slots) slave
   replicates df0a8e4503c472be07ed2770ef435e018d07e3cc
S: 75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826
   slots: (0 slots) slave
   replicates 1e4432f5bc7fb4ecebf12291eafb987d901872f7
S: fc983b60f3d81199da82871cf937c9053ce8c7a2 192.168.179.10:9828
   slots: (0 slots) slave
   replicates 439686e1130c6ac7a1d8b87f7d485875dc3872a3
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

12.10.2、删除槽位

12.10.2.1、分配slot给master1
【删除槽位】
# /home/redis/src/redis-cli --cluster reshard 192.168.179.10:9821 -a 'Drms@12#$'
>>> Performing Cluster Check (using node 192.168.179.10:9821)
M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821   # 迁入节点ID
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824
   slots: (0 slots) slave
   replicates fb96a9aa70b269936cd266f860e8e36960b90058
M: df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827   # 迁出节点ID
   slots: (0 slots) master
M: 1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822
   slots: (0 slots) slave
   replicates df0a8e4503c472be07ed2770ef435e018d07e3cc
S: 75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826
   slots: (0 slots) slave
   replicates 1e4432f5bc7fb4ecebf12291eafb987d901872f7
[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)? 1366     #==== 输入4096 中的 1366 (大致均分)
What is the receiving node ID? fb96a9aa70b269936cd266f860e8e36960b90058    #==== 输入迁入节点ID
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.   #==== 从所有节点中划分出4096个哈希槽分配给新节点
  Type 'done' once you entered all the source nodes IDs.    #==== 从cluster删除某个主机,并将该主机上的槽位全部移动到该节点
Source node #1: 439686e1130c6ac7a1d8b87f7d485875dc3872a3          #==== 输入迁出节点ID
Source node #1: done      #==== 输入done

Ready to move 1366 slots.
  Source nodes:
    M: 439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827
       slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
       1 additional replica(s)
  Destination node:
    M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
       slots:[1365-5460] (4096 slots) master
       1 additional replica(s)
  Resharding plan:
    Moving slot 0 from 439686e1130c6ac7a1d8b87f7d485875dc3872a3
	......
Do you want to proceed with the proposed reshard plan (yes/no)? yes  #==== 输入yes确认分配
Moving slot 5461 from 192.168.179.10:9827 to 192.168.179.10:9821: ..
......

【确定槽位是否分配成功】
# /home/redis/src/redis-cli --cluster check 192.168.179.10:9821 -a 'Drms@12#$'
192.168.179.10:9821 (fb96a9aa...) -> 6674 keys | 5462 slots | 1 slaves.
192.168.179.10:9825 (df0a8e45...) -> 5011 keys | 4096 slots | 1 slaves.
192.168.179.10:9827 (439686e1...) -> 3314 keys | 2730 slots | 1 slaves.   #==== 部分槽位已迁移至master1
192.168.179.10:9823 (1e4432f5...) -> 5001 keys | 4096 slots | 1 slaves.
[OK] 20000 keys in 4 masters.
1.22 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.179.10:9821)
M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
   slots:[0-5461] (5462 slots) master
   1 additional replica(s)
S: 8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824
   slots: (0 slots) slave
   replicates fb96a9aa70b269936cd266f860e8e36960b90058
M: df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
M: 439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827
   slots:[5462-6826],[10923-12287] (2730 slots) master
   1 additional replica(s)
M: 1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822
   slots: (0 slots) slave
   replicates df0a8e4503c472be07ed2770ef435e018d07e3cc
S: 75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826
   slots: (0 slots) slave
   replicates 1e4432f5bc7fb4ecebf12291eafb987d901872f7
S: fc983b60f3d81199da82871cf937c9053ce8c7a2 192.168.179.10:9828
   slots: (0 slots) slave
   replicates 439686e1130c6ac7a1d8b87f7d485875dc3872a3
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
12.10.2.2、分配slot给master2
【删除槽位】
# /home/redis/src/redis-cli --cluster reshard 192.168.179.10:9821 -a 'Drms@12#$'
>>> Performing Cluster Check (using node 192.168.179.10:9821)
M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824
   slots: (0 slots) slave
   replicates fb96a9aa70b269936cd266f860e8e36960b90058
M: df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827   # 迁出节点ID
   slots: (0 slots) master
M: 1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823   # 迁入节点ID
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822
   slots: (0 slots) slave
   replicates df0a8e4503c472be07ed2770ef435e018d07e3cc
S: 75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826
   slots: (0 slots) slave
   replicates 1e4432f5bc7fb4ecebf12291eafb987d901872f7
[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)? 1366     #==== 输入4096 中的 1366 (大致均分)
What is the receiving node ID? 1e4432f5bc7fb4ecebf12291eafb987d901872f7    #==== 输入迁入节点ID
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.   #==== 从所有节点中划分出4096个哈希槽分配给新节点
  Type 'done' once you entered all the source nodes IDs.    #==== 从cluster删除某个主机,并将该主机上的槽位全部移动到该节点
Source node #1: 439686e1130c6ac7a1d8b87f7d485875dc3872a3          #==== 输入迁出节点ID
Source node #1: done      #==== 输入done

Ready to move 1366 slots.
  Source nodes:
    M: 439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827
       slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
       1 additional replica(s)
  Destination node:
    M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
       slots:[1365-5460] (4096 slots) master
       1 additional replica(s)
  Resharding plan:
    Moving slot 0 from 439686e1130c6ac7a1d8b87f7d485875dc3872a3
	......
Do you want to proceed with the proposed reshard plan (yes/no)? yes  #==== 输入yes确认分配
Moving slot 5461 from 192.168.179.10:9827 to 192.168.179.10:9821: ..
......

【确定槽位是否分配成功】
# /home/redis/src/redis-cli --cluster check 192.168.179.10:9821 -a 'Drms@12#$'
192.168.179.10:9821 (fb96a9aa...) -> 6674 keys | 5462 slots | 1 slaves.
192.168.179.10:9825 (df0a8e45...) -> 5011 keys | 4096 slots | 1 slaves.
192.168.179.10:9827 (439686e1...) -> 2716 keys | 1364 slots | 1 slaves.   #==== 部分槽位已迁移至master2
192.168.179.10:9823 (1e4432f5...) -> 6669 keys | 5462 slots | 1 slaves.
[OK] 20000 keys in 4 masters.
1.22 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.179.10:9821)
M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
   slots:[0-5461] (5462 slots) master
   1 additional replica(s)
S: 8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824
   slots: (0 slots) slave
   replicates fb96a9aa70b269936cd266f860e8e36960b90058
M: df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
M: 439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827
   slots:[5462-6826],[10923-12287] (2730 slots) master
   1 additional replica(s)
M: 1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822
   slots: (0 slots) slave
   replicates df0a8e4503c472be07ed2770ef435e018d07e3cc
S: 75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826
   slots: (0 slots) slave
   replicates 1e4432f5bc7fb4ecebf12291eafb987d901872f7
S: fc983b60f3d81199da82871cf937c9053ce8c7a2 192.168.179.10:9828
   slots: (0 slots) slave
   replicates 439686e1130c6ac7a1d8b87f7d485875dc3872a3
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
12.10.2.3、分配slot给master3
【删除槽位】
# /home/redis/src/redis-cli --cluster reshard 192.168.179.10:9821 -a 'Drms@12#$'
>>> Performing Cluster Check (using node 192.168.179.10:9821)
M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824
   slots: (0 slots) slave
   replicates fb96a9aa70b269936cd266f860e8e36960b90058
M: df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825   # 迁入节点ID
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827   # 迁出节点ID
   slots: (0 slots) master
M: 1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822
   slots: (0 slots) slave
   replicates df0a8e4503c472be07ed2770ef435e018d07e3cc
S: 75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826
   slots: (0 slots) slave
   replicates 1e4432f5bc7fb4ecebf12291eafb987d901872f7
[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)? 1364     #==== 输入4096 中剩余的 1364 (大致均分)
What is the receiving node ID? df0a8e4503c472be07ed2770ef435e018d07e3cc    #==== 输入迁入节点ID
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.   #==== 从所有节点中划分出4096个哈希槽分配给新节点
  Type 'done' once you entered all the source nodes IDs.    #==== 从cluster删除某个主机,并将该主机上的槽位全部移动到该节点
Source node #1: 439686e1130c6ac7a1d8b87f7d485875dc3872a3          #==== 输入迁出节点ID
Source node #1: done      #==== 输入done

Ready to move 1366 slots.
  Source nodes:
    M: 439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827
       slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
       1 additional replica(s)
  Destination node:
    M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
       slots:[1365-5460] (4096 slots) master
       1 additional replica(s)
  Resharding plan:
    Moving slot 0 from 439686e1130c6ac7a1d8b87f7d485875dc3872a3
	......
Do you want to proceed with the proposed reshard plan (yes/no)? yes  #==== 输入yes确认分配
Moving slot 5461 from 192.168.179.10:9827 to 192.168.179.10:9821: ..
......

【确定槽位是否分配成功】
# /home/redis/src/redis-cli --cluster check 192.168.179.10:9821 -a 'Drms@12#$'
192.168.179.10:9821 (fb96a9aa...) -> 6674 keys | 5462 slots | 1 slaves.
192.168.179.10:9825 (df0a8e45...) -> 6666 keys | 5460 slots | 2 slaves. #====  slave自动切换至此master下(需要删除)
192.168.179.10:9827 (439686e1...) -> 0 keys | 0 slots | 0 slaves.     #==== 剩余槽位已迁移至master3
192.168.179.10:9823 (1e4432f5...) -> 6660 keys | 5462 slots | 1 slaves.
[OK] 20000 keys in 4 masters.
1.22 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.179.10:9821)
M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
   slots:[0-5461] (5462 slots) master
   1 additional replica(s)
S: 8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824
   slots: (0 slots) slave
   replicates fb96a9aa70b269936cd266f860e8e36960b90058
M: df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825
   slots:[6827-10922],[10924-12287] (5460 slots) master
   2 additional replica(s)
M: 439686e1130c6ac7a1d8b87f7d485875dc3872a3 192.168.179.10:9827
   slots: (0 slots) master
M: 1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823
   slots:[5462-6826],[10923],[12288-16383] (5462 slots) master
   1 additional replica(s)
S: 6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822
   slots: (0 slots) slave
   replicates df0a8e4503c472be07ed2770ef435e018d07e3cc
S: 75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826
   slots: (0 slots) slave
   replicates 1e4432f5bc7fb4ecebf12291eafb987d901872f7
S: fc983b60f3d81199da82871cf937c9053ce8c7a2 192.168.179.10:9828
   slots: (0 slots) slave
   replicates df0a8e4503c472be07ed2770ef435e018d07e3cc
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

12.10.3、移除主机

【删除master 9827节点】
# /home/redis/src/redis-cli --cluster del-node 192.168.179.10:9821 439686e1130c6ac7a1d8b87f7d485875dc3872a3 -a 'Drms@12#$'
>>> Removing node 439686e1130c6ac7a1d8b87f7d485875dc3872a3 from cluster 192.168.179.10:9821
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

【删除slave 9828节点】
# /home/redis/src/redis-cli --cluster del-node 192.168.179.10:9821 fc983b60f3d81199da82871cf937c9053ce8c7a2 -a 'Drms@12#$'
>>> Removing node fc983b60f3d81199da82871cf937c9053ce8c7a2 from cluster 192.168.179.10:9821
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

【检查集群状态,9827、9828是否移除】
# /home/redis/src/redis-cli -h 192.168.179.10 -p 9821 -a 'Drms@12#$' cluster nodes
8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824@19824 slave fb96a9aa70b269936cd266f860e8e36960b90058 0 1661404424407 9 connected
fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821@19821 myself,master - 0 1661404424000 9 connected 0-5461
df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825@19825 master - 0 1661404424000 11 connected 6827-10922 10924-12287
1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823@19823 master - 0 1661404425434 10 connected 5462-6826 10923 12288-16383
6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822@19822 slave df0a8e4503c472be07ed2770ef435e018d07e3cc 0 1661404424926 11 connected
75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826@19826 slave 1e4432f5bc7fb4ecebf12291eafb987d901872f7 0 1661404424000 10 connected

【检查数据、slots是否正常】
# /home/redis/src/redis-cli --cluster check 192.168.179.10:9821 -a 'Drms@12#$'
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.179.10:9821 (fb96a9aa...) -> 6674 keys | 5462 slots | 1 slaves.
192.168.179.10:9825 (df0a8e45...) -> 6666 keys | 5460 slots | 1 slaves.
192.168.179.10:9823 (1e4432f5...) -> 6660 keys | 5462 slots | 1 slaves.
[OK] 20000 keys in 3 masters.
1.22 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.179.10:9821)
M: fb96a9aa70b269936cd266f860e8e36960b90058 192.168.179.10:9821
   slots:[0-5461] (5462 slots) master
   1 additional replica(s)
S: 8b97a9866d154781b8ca3a1e29232823ea2c106b 192.168.179.10:9824
   slots: (0 slots) slave
   replicates fb96a9aa70b269936cd266f860e8e36960b90058
M: df0a8e4503c472be07ed2770ef435e018d07e3cc 192.168.179.10:9825
   slots:[6827-10922],[10924-12287] (5460 slots) master
   1 additional replica(s)
M: 1e4432f5bc7fb4ecebf12291eafb987d901872f7 192.168.179.10:9823
   slots:[5462-6826],[10923],[12288-16383] (5462 slots) master
   1 additional replica(s)
S: 6b70a0ebceafeaa0f804e1414f95dc17a26a81c1 192.168.179.10:9822
   slots: (0 slots) slave
   replicates df0a8e4503c472be07ed2770ef435e018d07e3cc
S: 75dc98c54fa983e7dcf57b9e670f496e09278a85 192.168.179.10:9826
   slots: (0 slots) slave
   replicates 1e4432f5bc7fb4ecebf12291eafb987d901872f7
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

你可能感兴趣的:(redis)