Redis Cluster 部署

1、安装 redis

# yum install gcc gcc-c++  make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel python-devel ncurses-devel glib2 glib2-devel openssl-devel glibc-devel glibc-devel.i686 vim screen git ntp* python-devel mysql-devel -y

# wget http://download.redis.io/releases/redis-3.2.12.tar.gz

# tar xvf redis-3.2.12.tar.gz -C /usr/local/

# make

2、配置 redis cluster,以 redis-6379 为例,其他的 redis-6380、redis-6381、redis-6382、redis-6383、redis-6384 配置类似

# cd /usr/local/redis-3.2.12
# egrep -v "^$|^#" redis-6379.conf 
bind 10.3.20.102
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "redis-6379.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename redis_6379-dump.rdb
dir ./
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "redis_6379-appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
# 开启集群模式
cluster-enabled yes
# 集群内部配置文件
cluster-config-file nodes-6379.conf
# 节点超时时间,单位毫秒
cluster-node-timeout 15000
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
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

3、redis cluster 节点握手

集群架构

10.3.20.102:6379 --> 10.3.20.14:6382
10.3.20.105:6380 --> 10.3.20.51:6383
10.3.20.93:6381  --> 10.3.20.54:6384
# redis-cli -h 10.3.20.102 -p 6379 -c
10.3.20.102:6379> cluster meet 10.3.20.105 6380
OK
10.3.20.102:6379> cluster meet 10.3.20.93 6381
OK
10.3.20.102:6379> cluster meet 10.3.20.14 6382
OK
10.3.20.102:6379> cluster meet 10.3.20.51 6383
OK
10.3.20.102:6379> cluster meet 10.3.20.54 6384
OK

10.3.20.102:6379> cluster nodes
2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383 master - 0 1531207146394 4 connected
6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384 master - 0 1531207144377 0 connected
6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379 myself,master - 0 0 5 connected
4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380 master - 0 1531207143369 1 connected
5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381 master - 0 1531207147400 2 connected
1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382 master - 0 1531207145383 3 connected


10.3.20.102:6379> set hello world
(error) CLUSTERDOWN Hash slot not served


10.3.20.102:6379> cluster info
cluster_state:fail
cluster_slots_assigned:0
cluster_slots_ok:0
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:0
cluster_current_epoch:5
cluster_my_epoch:5
cluster_stats_messages_sent:469
cluster_stats_messages_received:469


被分配的槽(cluster_slots_assigned)是0,由于目前所有的槽没有分配到节点,因此集群无法完成槽到节点的映射。只有当16384个槽全部分配给节点后,集群才进入在线状态。

4、redis cluster 分配槽

# redis-cli -h 10.3.20.102 -p 6379 cluster addslots {0..5461}
OK
# redis-cli -h 10.3.20.105 -p 6380 cluster addslots {5462..10922}
OK
# redis-cli -h 10.3.20.93 -p 6381 cluster addslots {10923..16383}
OK

# redis-cli -h 10.3.20.102 -p 6379 -c
10.3.20.102:6379> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:5
cluster_my_epoch:5
cluster_stats_messages_sent:3978
cluster_stats_messages_received:3978

10.3.20.102:6379> cluster nodes
6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379 myself,master - 0 0 5 connected 0-5461
1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382 master - 0 1531209712249 3 connected
5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381 master - 0 1531209711748 2 connected 10923-16383
4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380 master - 0 1531209710223 1 connected 5462-10922
6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384 master - 0 1531209709215 0 connected
2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383 master - 0 1531209713256 4 connected

5、配置 3 个 节点为从节点,负责故障转移(6379(Master)--> 6382(Slave),6380(Master)--> 6383(Slave),6381(Master)--> 6384(Slave))

# redis-cli -h 10.3.20.14 -p 6382 -c
10.3.20.14:6382> cluster replicate 6f3639bc0ce4c99d487c9e89c57b290496666483
OK

# redis-cli -h 10.3.20.51 -p 6383 -c
10.3.20.51:6383> cluster replicate 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
OK

# redis-cli -h 10.3.20.54 -p 6384 -c
10.3.20.54:6384> cluster replicate 5fb133912a7caaac22bd5bbd75af346aa129a766
OK

# redis-cli -h 10.3.20.102 -p 6379 -c
10.3.20.102:6379> cluster nodes
6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379 myself,master - 0 0 5 connected 0-5461
1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382 slave 6f3639bc0ce4c99d487c9e89c57b290496666483 0 1531209918639 5 connected
5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381 master - 0 1531209917228 2 connected 10923-16383
4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380 master - 0 1531209919245 1 connected 5462-10922
6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384 slave 5fb133912a7caaac22bd5bbd75af346aa129a766 0 1531209914202 2 connected
2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383 slave 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 0 1531209918235 4 connected

6、测试 redis cluster

# redis-cli -c -h 10.3.20.102 -p 6379
10.3.20.102:6379> set name foo
-> Redirected to slot [5798] located at 10.3.20.105:6380
OK
# redis-cli -h 10.3.20.105 -p 6380 -c
10.3.20.105:6380> set age 21
-> Redirected to slot [741] located at 10.3.20.102:6379
OK
# redis-cli -h 10.3.20.93 -p 6381 -c
10.3.20.93:6381> get name
-> Redirected to slot [5798] located at 10.3.20.105:6380
"foo"
10.3.20.105:6380> get age
-> Redirected to slot [741] located at 10.3.20.102:6379
"21"

7、错误处理

# redis-cli -h 10.3.20.102 -p 6379 -c
10.3.20.102:6379> set name kine
(error) CLUSTERDOWN The cluster is down
10.3.20.102:6379> 

// Also do cluster reset soft on each server after the flushall
10.3.20.102:6379> flushall
OK
10.3.20.102:6379> cluster reset soft
OK

8、利用 redis-trib.rb 快速部署 redis cluster

# yum install ruby -y
# wget http://rubygems.org/downloads/redis-3.3.0.gem
# gem install -l redis-3.3.0.gem 
Successfully installed redis-3.3.0
Parsing documentation for redis-3.3.0
Installing ri documentation for redis-3.3.0
1 gem installed
# gem list 

*** LOCAL GEMS ***

bigdecimal (1.2.0)
io-console (0.4.2)
json (1.7.7)
psych (2.0.0)
rdoc (4.0.0)
redis (3.3.0)

# redis-trib.rb create --replicas 1 10.3.20.102:6379 10.3.20.105:6380 10.3.20.93:6381 10.3.20.14:6382 10.3.20.51:6383 10.3.20.54:6384
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
10.3.20.102:6379
10.3.20.105:6380
10.3.20.93:6381
Adding replica 10.3.20.14:6382 to 10.3.20.102:6379
Adding replica 10.3.20.51:6383 to 10.3.20.105:6380
Adding replica 10.3.20.54:6384 to 10.3.20.93:6381
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:0-5460 (5461 slots) master
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:5461-10922 (5462 slots) master
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:10923-16383 (5461 slots) master
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
S: 6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384
   replicates 5fb133912a7caaac22bd5bbd75af346aa129a766
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join.....
>>> Performing Cluster Check (using node 10.3.20.102:6379)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384
   slots: (0 slots) slave
   replicates 5fb133912a7caaac22bd5bbd75af346aa129a766
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

# redis-trib.rb check 10.3.20.102:6379
>>> Performing Cluster Check (using node 10.3.20.102:6379)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384
   slots: (0 slots) slave
   replicates 5fb133912a7caaac22bd5bbd75af346aa129a766
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

# redis-trib.rb info 10.3.20.102:6379
10.3.20.102:6379 (6f3639bc...) -> 0 keys | 5461 slots | 1 slaves.
10.3.20.93:6381 (5fb13391...) -> 0 keys | 5461 slots | 1 slaves.
10.3.20.105:6380 (4dacd43c...) -> 0 keys | 5462 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.

# redis-cli -h 10.3.20.102 -p 6379 -c
10.3.20.102:6379> set name kine
-> Redirected to slot [5798] located at 10.3.20.105:6380
OK
10.3.20.105:6380> set age 10
-> Redirected to slot [741] located at 10.3.20.102:6379
OK
10.3.20.102:6379> set weight 100
-> Redirected to slot [16280] located at 10.3.20.93:6381
OK
10.3.20.93:6381> 
[root@docker-01 redis-3.2.12]# redis-trib.rb info 10.3.20.102:6379
10.3.20.102:6379 (6f3639bc...) -> 1 keys | 5461 slots | 1 slaves.
10.3.20.93:6381 (5fb13391...) -> 1 keys | 5461 slots | 1 slaves.
10.3.20.105:6380 (4dacd43c...) -> 1 keys | 5462 slots | 1 slaves.
[OK] 3 keys in 3 masters.
0.00 keys per slot on average.

9、扩容集群(10.3.20.132:6385(Master)-->(10.3.20.132 6386(Slave)

集群架构

10.3.20.102:6379 --> 10.3.20.14:6382
10.3.20.105:6380 --> 10.3.20.51:6383
10.3.20.93:6381  --> 10.3.20.54:6384
10.3.20.132:6385 --> 10.3.20.132:6386
// 准备新节点 10.3.20.132:6385(Master)
# redis-server redis-6385.conf

// 原生命令 cluster meet 实现 10.3.20.132:6385(Master) 加入集群
# redis-cli -h 10.3.20.102 -p 6379 -c
10.3.20.102:6379> cluster meet 10.3.20.132 6385
OK
10.3.20.102:6379> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:7
cluster_size:3
cluster_current_epoch:8
cluster_my_epoch:5
cluster_stats_messages_sent:210273
cluster_stats_messages_received:179187
10.3.20.102:6379> cluster nodes
2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383 slave 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 0 1531360499646 8 connected
5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381 master - 0 1531360500653 2 connected 10923-16383
6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379 myself,master - 0 0 5 connected 0-5460
4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380 master - 0 1531360497636 8 connected 5461-10922
1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382 slave 6f3639bc0ce4c99d487c9e89c57b290496666483 0 1531360498639 5 connected
8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385 master - 0 1531360501661 0 connected
6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384 slave 5fb133912a7caaac22bd5bbd75af346aa129a766 0 1531360495615 6 connected

# redis-trib.rb check 10.3.20.102:6379
>>> Performing Cluster Check (using node 10.3.20.102:6379)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots: (0 slots) master
   0 additional replica(s)
S: 6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384
   slots: (0 slots) slave
   replicates 5fb133912a7caaac22bd5bbd75af346aa129a766
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

// redis-trib.rb add-node 实现 10.3.20.132:6385(Master) 加入集群
# redis-trib.rb add-node 10.3.20.132:6385 10.3.20.102:6379
>>> Adding node 10.3.20.132:6385 to cluster 10.3.20.102:6379
>>> Performing Cluster Check (using node 10.3.20.102:6379)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots: (0 slots) master
   0 additional replica(s)
S: 6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384
   slots: (0 slots) slave
   replicates 5fb133912a7caaac22bd5bbd75af346aa129a766
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[ERR] Node 10.3.20.132:6385 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.

// 迁移槽和数据(16384/4=4096)
# redis-trib.rb reshard 10.3.20.102:6379
>>> Performing Cluster Check (using node 10.3.20.102:6379)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots: (0 slots) master
   0 additional replica(s)
S: 6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384
   slots: (0 slots) slave
   replicates 5fb133912a7caaac22bd5bbd75af346aa129a766
[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
What is the receiving node ID? 8e197d1add3838be26744dde6422b6ccfd205ede
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:6f3639bc0ce4c99d487c9e89c57b290496666483
Source node #2:4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
Source node #3:5fb133912a7caaac22bd5bbd75af346aa129a766
Source node #4:done

Ready to move 4096 slots.
  Source nodes:
    M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
    M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
    M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
  Destination node:
    M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots: (0 slots) master
   0 additional replica(s)
  Resharding plan:
    Moving slot 5461 from 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
    ……
    Moving slot 12287 from 5fb133912a7caaac22bd5bbd75af346aa129a766
Do you want to proceed with the proposed reshard plan (yes/no)? yes
Moving slot 5461 from 10.3.20.105:6380 to 10.3.20.132:6385: 
……
Moving slot 12287 from 10.3.20.93:6381 to 10.3.20.132:6385: 

10.3.20.102:6379> cluster nodes
2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383 slave 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 0 1531362985537 8 connected
5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381 master - 0 1531362984026 2 connected 12288-16383
6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379 myself,master - 0 0 5 connected 1365-5460
4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380 master - 0 1531362979488 8 connected 6827-10922
1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382 slave 6f3639bc0ce4c99d487c9e89c57b290496666483 0 1531362982512 5 connected
8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385 master - 0 1531362986545 9 connected 0-1364 5461-6826 10923-12287
6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384 slave 5fb133912a7caaac22bd5bbd75af346aa129a766 0 1531362984532 6 connected

# redis-trib.rb rebalance 10.3.20.102:6379
>>> Performing Cluster Check (using node 10.3.20.102:6379)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
*** No rebalancing needed! All nodes are within the 2.0% threshold.

# redis-trib.rb info 10.3.20.102:6379
10.3.20.102:6379 (6f3639bc...) -> 0 keys | 4096 slots | 1 slaves.
10.3.20.93:6381 (5fb13391...) -> 1 keys | 4096 slots | 1 slaves.
10.3.20.105:6380 (4dacd43c...) -> 0 keys | 4096 slots | 1 slaves.
10.3.20.132:6385 (8e197d1a...) -> 3 keys | 4096 slots | 0 slaves.
[OK] 4 keys in 4 masters.
0.00 keys per slot on average.

# redis-trib.rb check 10.3.20.102:6379
>>> Performing Cluster Check (using node 10.3.20.102:6379)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:12288-16383 (4096 slots) master
   1 additional replica(s)
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   0 additional replica(s)
S: 6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384
   slots: (0 slots) slave
   replicates 5fb133912a7caaac22bd5bbd75af346aa129a766
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

// 准备 10.3.20.132 6386(Slave) 节点
# redis-server redis-6386.conf

// 10.3.20.132:6386(Slave) 加入集群
# redis-trib.rb add-node 10.3.20.132:6386 10.3.20.102:6379
>>> Adding node 10.3.20.132:6386 to cluster 10.3.20.102:6379
>>> Performing Cluster Check (using node 10.3.20.102:6379)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:12288-16383 (4096 slots) master
   1 additional replica(s)
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   0 additional replica(s)
S: 6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384
   slots: (0 slots) slave
   replicates 5fb133912a7caaac22bd5bbd75af346aa129a766
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 10.3.20.132:6386 to make it join the cluster.
[OK] New node added correctly.

# redis-trib.rb info 10.3.20.102:6379
10.3.20.102:6379 (6f3639bc...) -> 0 keys | 4096 slots | 1 slaves.
10.3.20.93:6381 (5fb13391...) -> 1 keys | 4096 slots | 1 slaves.
10.3.20.132:6386 (34585de8...) -> 0 keys | 0 slots | 0 slaves.
10.3.20.105:6380 (4dacd43c...) -> 0 keys | 4096 slots | 1 slaves.
10.3.20.132:6385 (8e197d1a...) -> 3 keys | 4096 slots | 0 slaves.
[OK] 4 keys in 5 masters.
0.00 keys per slot on average.

# redis-trib.rb check 10.3.20.102:6379
>>> Performing Cluster Check (using node 10.3.20.102:6379)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:12288-16383 (4096 slots) master
   1 additional replica(s)
M: 34585de8b5731f8690a418cc7d84851fedb52f6b 10.3.20.132:6386
   slots: (0 slots) master
   0 additional replica(s)
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   0 additional replica(s)
S: 6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384
   slots: (0 slots) slave
   replicates 5fb133912a7caaac22bd5bbd75af346aa129a766
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

# redis-cli -h 10.3.20.132 -p 6386 -c
10.3.20.132:6386> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:8
cluster_size:4
cluster_current_epoch:9
cluster_my_epoch:0
cluster_stats_messages_sent:481
cluster_stats_messages_received:481
10.3.20.132:6386> cluster nodes
8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385 master - 0 1531392646476 9 connected 0-1364 5461-6826 10923-12287
5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381 master - 0 1531392642446 2 connected 12288-16383
4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380 master - 0 1531392643957 8 connected 6827-10922
2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383 slave 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 0 1531392645470 8 connected
6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379 master - 0 1531392646981 5 connected 1365-5460
1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382 slave 6f3639bc0ce4c99d487c9e89c57b290496666483 0 1531392648491 5 connected
34585de8b5731f8690a418cc7d84851fedb52f6b 10.3.20.132:6386 myself,master - 0 0 0 connected
6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384 slave 5fb133912a7caaac22bd5bbd75af346aa129a766 0 1531392647483 2 connected

// 10.3.20.132:6386(Slave) 配置为 10.3.20.132:6385(Master) 从节点
10.3.20.132:6386> cluster replicate 8e197d1add3838be26744dde6422b6ccfd205ede
OK
10.3.20.132:6386> cluster nodes
8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385 master - 0 1531392707947 9 connected 0-1364 5461-6826 10923-12287
5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381 master - 0 1531392706941 2 connected 12288-16383
4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380 master - 0 1531392703902 8 connected 6827-10922
2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383 slave 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 0 1531392708959 8 connected
6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379 master - 0 1531392704917 5 connected 1365-5460
1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382 slave 6f3639bc0ce4c99d487c9e89c57b290496666483 0 1531392708971 5 connected
34585de8b5731f8690a418cc7d84851fedb52f6b 10.3.20.132:6386 myself,slave 8e197d1add3838be26744dde6422b6ccfd205ede 0 0 0 connected
6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384 slave 5fb133912a7caaac22bd5bbd75af346aa129a766 0 1531392705923 2 connected

10、收缩集群

集群架构

10.3.20.102:6379 --> 10.3.20.14:6382
10.3.20.105:6380 --> 10.3.20.51:6383
10.3.20.132:6385 --> 10.3.20.132:6386
// 先下线 10.3.20.93:6381(Master) 的从节点 10.3.20.54:6384(Slave)
# redis-trib.rb info 10.3.20.102:6379
10.3.20.102:6379 (6f3639bc...) -> 0 keys | 4096 slots | 1 slaves.
10.3.20.93:6381 (5fb13391...) -> 1 keys | 4096 slots | 1 slaves.
10.3.20.105:6380 (4dacd43c...) -> 0 keys | 4096 slots | 1 slaves.
10.3.20.132:6385 (8e197d1a...) -> 3 keys | 4096 slots | 1 slaves.
[OK] 4 keys in 4 masters.
0.00 keys per slot on average.

# redis-trib.rb check 10.3.20.102:6379
>>> Performing Cluster Check (using node 10.3.20.102:6379)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:12288-16383 (4096 slots) master
   1 additional replica(s)
S: 34585de8b5731f8690a418cc7d84851fedb52f6b 10.3.20.132:6386
   slots: (0 slots) slave
   replicates 8e197d1add3838be26744dde6422b6ccfd205ede
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   1 additional replica(s)
S: 6ffe8ec154ade4c27532383af3ddad51c3d43373 10.3.20.54:6384
   slots: (0 slots) slave
   replicates 5fb133912a7caaac22bd5bbd75af346aa129a766
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

先下线从节点 10.3.20.54:6384(Slave)
# redis-trib.rb del-node 10.3.20.102:6379 6ffe8ec154ade4c27532383af3ddad51c3d43373
>>> Removing node 6ffe8ec154ade4c27532383af3ddad51c3d43373 from cluster 10.3.20.102:6379
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

# redis-trib.rb info 10.3.20.102:6379
10.3.20.102:6379 (6f3639bc...) -> 0 keys | 4096 slots | 1 slaves.
10.3.20.93:6381 (5fb13391...) -> 1 keys | 4096 slots | 0 slaves.
10.3.20.105:6380 (4dacd43c...) -> 0 keys | 4096 slots | 1 slaves.
10.3.20.132:6385 (8e197d1a...) -> 3 keys | 4096 slots | 1 slaves.
[OK] 4 keys in 4 masters.
0.00 keys per slot on average.

# redis-trib.rb check 10.3.20.102:6379
>>> Performing Cluster Check (using node 10.3.20.102:6379)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:12288-16383 (4096 slots) master
   0 additional replica(s)
S: 34585de8b5731f8690a418cc7d84851fedb52f6b 10.3.20.132:6386
   slots: (0 slots) slave
   replicates 8e197d1add3838be26744dde6422b6ccfd205ede
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots:0-1364,5461-6826,10923-12287 (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.

// 再下线 10.3.20.93:6381(Master)(4096/3=1365,10.3.20.93:6381 的槽分 3 部分,分别迁移到 10.3.20.102:6379、10.3.20.105:6380 和 10.3.20.132:6385)
// 迁移 10.3.20.93:6381 的 1365 个槽到 10.3.20.102:6379
# redis-trib.rb reshard 10.3.20.93:6381
>>> Performing Cluster Check (using node 10.3.20.93:6381)
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:12288-16383 (4096 slots) master
   0 additional replica(s)
M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   1 additional replica(s)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
S: 34585de8b5731f8690a418cc7d84851fedb52f6b 10.3.20.132:6386
   slots: (0 slots) slave
   replicates 8e197d1add3838be26744dde6422b6ccfd205ede
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:6827-10922 (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.
How many slots do you want to move (from 1 to 16384)? 1365
What is the receiving node ID? 6f3639bc0ce4c99d487c9e89c57b290496666483
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:5fb133912a7caaac22bd5bbd75af346aa129a766
Source node #2:done

Ready to move 1365 slots.
  Source nodes:
    M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:12288-16383 (4096 slots) master
   0 additional replica(s)
  Destination node:
    M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
  Resharding plan:
    Moving slot 12288 from 5fb133912a7caaac22bd5bbd75af346aa129a766
    ……
    Moving slot 13652 from 5fb133912a7caaac22bd5bbd75af346aa129a766
Do you want to proceed with the proposed reshard plan (yes/no)? yes
Moving slot 12288 from 10.3.20.93:6381 to 10.3.20.102:6379: 
……
Moving slot 13652 from 10.3.20.93:6381 to 10.3.20.102:6379:

# redis-trib.rb check 10.3.20.102:6379
>>> Performing Cluster Check (using node 10.3.20.102:6379)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:1365-5460,12288-13652 (5461 slots) master
   1 additional replica(s)
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:13653-16383 (2731 slots) master
   0 additional replica(s)
S: 34585de8b5731f8690a418cc7d84851fedb52f6b 10.3.20.132:6386
   slots: (0 slots) slave
   replicates 8e197d1add3838be26744dde6422b6ccfd205ede
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots:0-1364,5461-6826,10923-12287 (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.

// 迁移 10.3.20.93:6381 的 1365 个槽到 10.3.20.105:6380
# redis-trib.rb reshard 10.3.20.93:6381
>>> Performing Cluster Check (using node 10.3.20.93:6381)
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:13653-16383 (2731 slots) master
   0 additional replica(s)
M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   1 additional replica(s)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:1365-5460,12288-13652 (5461 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
S: 34585de8b5731f8690a418cc7d84851fedb52f6b 10.3.20.132:6386
   slots: (0 slots) slave
   replicates 8e197d1add3838be26744dde6422b6ccfd205ede
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:6827-10922 (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.
How many slots do you want to move (from 1 to 16384)? 1365
What is the receiving node ID? 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
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:5fb133912a7caaac22bd5bbd75af346aa129a766
Source node #2:done

Ready to move 1365 slots.
  Source nodes:
    M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:13653-16383 (2731 slots) master
   0 additional replica(s)
  Destination node:
    M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
  Resharding plan:
    Moving slot 13653 from 5fb133912a7caaac22bd5bbd75af346aa129a766
    ……
    Moving slot 15017 from 5fb133912a7caaac22bd5bbd75af346aa129a766
Do you want to proceed with the proposed reshard plan (yes/no)? yes
Moving slot 13653 from 10.3.20.93:6381 to 10.3.20.105:6380: 
……
Moving slot 15017 from 10.3.20.93:6381 to 10.3.20.105:6380: 

# redis-trib.rb check 10.3.20.102:6379
>>> Performing Cluster Check (using node 10.3.20.102:6379)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:1365-5460,12288-13652 (5461 slots) master
   1 additional replica(s)
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:15018-16383 (1366 slots) master
   0 additional replica(s)
S: 34585de8b5731f8690a418cc7d84851fedb52f6b 10.3.20.132:6386
   slots: (0 slots) slave
   replicates 8e197d1add3838be26744dde6422b6ccfd205ede
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:6827-10922,13653-15017 (5461 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots:0-1364,5461-6826,10923-12287 (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.

// 迁移 10.3.20.93:6381 剩下的 1366 个槽到 10.3.20.132:6385
# redis-trib.rb reshard 10.3.20.93:6381
>>> Performing Cluster Check (using node 10.3.20.93:6381)
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:15018-16383 (1366 slots) master
   0 additional replica(s)
M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   1 additional replica(s)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:1365-5460,12288-13652 (5461 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
S: 34585de8b5731f8690a418cc7d84851fedb52f6b 10.3.20.132:6386
   slots: (0 slots) slave
   replicates 8e197d1add3838be26744dde6422b6ccfd205ede
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:6827-10922,13653-15017 (5461 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.
How many slots do you want to move (from 1 to 16384)? 1366
What is the receiving node ID? 8e197d1add3838be26744dde6422b6ccfd205ede
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:5fb133912a7caaac22bd5bbd75af346aa129a766
Source node #2:done

Ready to move 1366 slots.
  Source nodes:
    M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots:15018-16383 (1366 slots) master
   0 additional replica(s)
  Destination node:
    M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   1 additional replica(s)
  Resharding plan:
    Moving slot 15018 from 5fb133912a7caaac22bd5bbd75af346aa129a766
    ……
    Moving slot 16383 from 5fb133912a7caaac22bd5bbd75af346aa129a766
Do you want to proceed with the proposed reshard plan (yes/no)? yes
Moving slot 15018 from 10.3.20.93:6381 to 10.3.20.132:6385: 
……
Moving slot 16383 from 10.3.20.93:6381 to 10.3.20.132:6385: 

# redis-trib.rb check 10.3.20.102:6379
>>> Performing Cluster Check (using node 10.3.20.102:6379)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:1365-5460,12288-13652 (5461 slots) master
   1 additional replica(s)
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
M: 5fb133912a7caaac22bd5bbd75af346aa129a766 10.3.20.93:6381
   slots: (0 slots) master
   0 additional replica(s)
S: 34585de8b5731f8690a418cc7d84851fedb52f6b 10.3.20.132:6386
   slots: (0 slots) slave
   replicates 8e197d1add3838be26744dde6422b6ccfd205ede
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:6827-10922,13653-15017 (5461 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots:0-1364,5461-6826,10923-12287,15018-16383 (5462 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.

// 删除 10.3.20.93:6381 节点信息
# redis-trib.rb del-node 10.3.20.102:6379 5fb133912a7caaac22bd5bbd75af346aa129a766
>>> Removing node 5fb133912a7caaac22bd5bbd75af346aa129a766 from cluster 10.3.20.102:6379
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

# redis-trib.rb check 10.3.20.102:6379
>>> Performing Cluster Check (using node 10.3.20.102:6379)
M: 6f3639bc0ce4c99d487c9e89c57b290496666483 10.3.20.102:6379
   slots:1365-5460,12288-13652 (5461 slots) master
   1 additional replica(s)
S: 2e3c0b2c184640fcfae8af3aed622942b25d16dd 10.3.20.51:6383
   slots: (0 slots) slave
   replicates 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b
S: 34585de8b5731f8690a418cc7d84851fedb52f6b 10.3.20.132:6386
   slots: (0 slots) slave
   replicates 8e197d1add3838be26744dde6422b6ccfd205ede
M: 4dacd43c0a5a20d0e2676342107f3e4b125a2b2b 10.3.20.105:6380
   slots:6827-10922,13653-15017 (5461 slots) master
   1 additional replica(s)
S: 1cb93aa1c9e6e5097d321077de16f4d053ee3e05 10.3.20.14:6382
   slots: (0 slots) slave
   replicates 6f3639bc0ce4c99d487c9e89c57b290496666483
M: 8e197d1add3838be26744dde6422b6ccfd205ede 10.3.20.132:6385
   slots:0-1364,5461-6826,10923-12287,15018-16383 (5462 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.

你可能感兴趣的:(Redis Cluster 部署)