Redis Cluster 分散式叢集(下)
阿新 • • 發佈:2020-08-09
Redis Cluster 搭建(工具)
環境準備
節點 | IP | 埠 |
---|---|---|
節點① | 172.16.1.121 | 6379,6380 |
節點② | 172.16.1.122 | 6379,6380 |
節點③ | 172.16.1.123 | 6379,6380 |
搭建 Redis 多例項
# 刪除以前的 Redis 資料 [root@dbtest01 ~]# rm -rf /service/redis/* # 建立多例項目錄 [root@dbtest01 ~]# mkdir /service/redis/{6379,6380} [root@dbtest02 ~]# mkdir /service/redis/{6379,6380} [root@dbtest03 ~]# mkdir /service/redis/{6379,6380} # 配置所有 Redis [root@dbtest01 ~]# vim /service/redis/6379/redis.conf bind 172.16.1.121 127.0.0.1 port 6379 daemonize yes pidfile /service/redis/6379/redis.pid loglevel notice logfile /service/redis/6379/redis.log dbfilename dump.rdb dir /service/redis/6379 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 [root@dbtest01 ~]# vim /service/redis/6380/redis.conf bind 172.16.1.121 127.0.0.1 port 6380 daemonize yes pidfile /service/redis/6380/redis.pid loglevel notice logfile /service/redis/6380/redis.log dbfilename dump.rdb dir /service/redis/6380 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000
啟動 Redis 多例項
[root@dbtest01 ~]# redis-server /service/redis/6379/redis.conf [root@dbtest01 ~]# redis-server /service/redis/6380/redis.conf [root@dbtest02 ~]# redis-server /service/redis/6379/redis.conf [root@dbtest02 ~]# redis-server /service/redis/6380/redis.conf [root@dbtest03 ~]# redis-server /service/redis/6379/redis.conf [root@dbtest03 ~]# redis-server /service/redis/6380/redis.conf
安裝外掛
# 配置 EPEL 源,安裝 ruby 支援 [root@dbtest01 ~]# yum install ruby rubygems -y # 檢視 gem 源 [root@dbtest01 ~]# gem sources -l *** CURRENT SOURCES *** http://rubygems.org/ # 新增阿里雲 gem 源 [root@dbtest01 ~]# gem sources -a http://mirrors.aliyun.com/rubygems/ http://mirrors.aliyun.com/rubygems/ added to sources # 刪除國外 gem 源 [root@dbtest01 ~]# gem sources --remove https://rubygems.org/ http://rubygems.org/ removed from sources # 再次檢視 gem 源 [root@dbtest01 ~]# gem sources -l # 使用 gem 安裝 redis 的 ruby 外掛 [root@dbtest01 ~]# gem install redis -v 3.3.3 Successfully installed redis-3.3.3 1 gem installed Installing ri documentation for redis-3.3.3... Installing RDoc documentation for redis-3.3.3...
命令工具
# redis-trib.rb 是做分散式叢集的命令工具,是 Redis 自帶的,但需要 Ruby 外掛支援才能使用
[root@dbtest01 ~]# redis-trib.rb
create # 建立一個叢集
check # 檢查叢集
info # 叢集狀態
fix # 修復叢集
reshard # 重新分配槽位
rebalance # 平衡槽位數量
add-node # 新增節點
del-node # 刪除節點
set-timeout # 設定超時時間
call # 向叢集所有機器輸入命令
import # 匯入資料
help # 幫助
關聯所有節點
# 選項–replicas 1 表示我們希望為叢集中的每個主節點建立一個從節點
[root@dbtest01 6380]# redis-trib.rb create --replicas 1 172.16.1.121:6379 172.16.1.122:6379 172.16.1.123:6379 172.16.1.122:6380 172.16.1.123:6380 172.16.1.121:6380
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
172.16.1.121:6379
172.16.1.122:6379
172.16.1.123:6379
Adding replica 172.16.1.122:6380 to 172.16.1.121:6379
Adding replica 172.16.1.121:6380 to 172.16.1.122:6379
Adding replica 172.16.1.123:6380 to 172.16.1.123:6379
M: 85622647ecc43b13ea10083aa59e73399a30b75f 172.16.1.121:6379
slots:0-5460 (5461 slots) master
M: 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 172.16.1.122:6379
slots:5461-10922 (5462 slots) master
M: 98f828cce3188a3f670dbbd9f77b5723df6cf53b 172.16.1.123:6379
slots:10923-16383 (5461 slots) master
S: 92bf59c43755c92953e50dda2c7d806bbb9d5f7b 172.16.1.122:6380
replicates 85622647ecc43b13ea10083aa59e73399a30b75f
S: cd7afafbf822fb17c26e0e45c921dfa94d8526b9 172.16.1.123:6380
replicates 98f828cce3188a3f670dbbd9f77b5723df6cf53b
S: ed5d625d41f5c3621bdd068dbd0c2c30bc4c0649 172.16.1.121:6380
replicates 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9
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 172.16.1.121:6379)
M: 85622647ecc43b13ea10083aa59e73399a30b75f 172.16.1.121:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 98f828cce3188a3f670dbbd9f77b5723df6cf53b 172.16.1.123:6379
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: cd7afafbf822fb17c26e0e45c921dfa94d8526b9 172.16.1.123:6380
slots: (0 slots) slave
replicates 98f828cce3188a3f670dbbd9f77b5723df6cf53b
M: 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 172.16.1.122:6379
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: ed5d625d41f5c3621bdd068dbd0c2c30bc4c0649 172.16.1.121:6380
slots: (0 slots) slave
replicates 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9
S: 92bf59c43755c92953e50dda2c7d806bbb9d5f7b 172.16.1.122:6380
slots: (0 slots) slave
replicates 85622647ecc43b13ea10083aa59e73399a30b75f
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
檢視叢集狀態
[root@dbtest01 6380]# redis-cli -h 172.16.1.121 -p 6379 CLUSTER NODES
98f828cce3188a3f670dbbd9f77b5723df6cf53b 172.16.1.123:6379 master - 0 1596788944243 3 connected 10923-16383
cd7afafbf822fb17c26e0e45c921dfa94d8526b9 172.16.1.123:6380 slave 98f828cce3188a3f670dbbd9f77b5723df6cf53b 0 1596788945754 5 connected
0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 172.16.1.122:6379 master - 0 1596788943739 2 connected 5461-10922
85622647ecc43b13ea10083aa59e73399a30b75f 172.16.1.121:6379 myself,master - 0 0 1 connected 0-5460
ed5d625d41f5c3621bdd068dbd0c2c30bc4c0649 172.16.1.121:6380 slave 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 0 1596788945250 6 connected
92bf59c43755c92953e50dda2c7d806bbb9d5f7b 172.16.1.122:6380 slave 85622647ecc43b13ea10083aa59e73399a30b75f 0 1596788944745 4 connected
重新配置主從
由於使用工具,始終有一臺機器從庫本機的從庫,所以要重新分配主從 ~ ~ ~
# 由於使用工具,始終有一臺機器從庫本機的從庫,所以要重新分配主從
172.16.1.122:6380> CLUSTER REPLICATE 98f828cce3188a3f670dbbd9f77b5723df6cf53b
OK
172.16.1.123:6380> CLUSTER REPLICATE 85622647ecc43b13ea10083aa59e73399a30b75f
OK
插入資料測試
# 執行指令碼
[root@dbtest01 ~]# cat data.sh
#!/bin/bash
for i in {1..1000};do
redis-cli -c -h 172.16.1.121 -p 6379 SET k${i} v${i}
done
# 檢視槽位分佈,資料(keys)分佈
[root@dbtest01 ~]# redis-trib.rb info 172.16.1.121:6379
172.16.1.121:6379 (85622647...) -> 341 keys | 5461 slots | 1 slaves.
172.16.1.123:6379 (98f828cc...) -> 327 keys | 5461 slots | 1 slaves.
172.16.1.122:6379 (0f0232ee...) -> 332 keys | 5462 slots | 1 slaves.
[OK] 1000 keys in 3 masters.
0.06 keys per slot on average.
Redis 叢集節點修改
①. — 新節點新增槽位
②. — 源節點中的資料進行遷移
③. — 源節點資料遷移完畢
④. — 遷移下一個槽位的資料,依次迴圈
新增節點
準備新機器
# 此處沒有另外準備新的虛擬機器,暫時在 dbtest03 上新增 2 個例項,即一對主從節點
[root@dbtest03 ~]# mkdir /service/redis/{6381,6382}
[root@dbtest03 ~]# vim /service/redis/6381/redis.conf
[root@dbtest03 ~]# vim /service/redis/6382/redis.conf
# 啟動新節點
[root@dbtest03 ~]# redis-server /service/redis/6381/redis.conf
[root@dbtest03 ~]# redis-server /service/redis/6382/redis.conf
關聯新節點
# 關聯新的節點到 Redis 分散式叢集中
[root@dbtest03 ~]# redis-trib.rb add-node 172.16.1.123:6381 172.16.1.121:6379
[root@dbtest03 ~]# redis-trib.rb add-node 172.16.1.123:6382 172.16.1.121:6379
# 或者
[root@dbtest03 ~]# redis-cli -p 6379 -h 172.16.1.121 cluster meet 172.16.1.123 6381
[root@dbtest03 ~]# redis-cli -p 6379 -h 172.16.1.121 cluster meet 172.16.1.123 6382
# 檢視節點資訊
[root@dbtest03 ~]# redis-trib.rb info 172.16.1.121:6379
172.16.1.121:6379 (85622647...) -> 341 keys | 5461 slots | 1 slaves.
172.16.1.123:6379 (98f828cc...) -> 327 keys | 5461 slots | 1 slaves.
172.16.1.122:6379 (0f0232ee...) -> 332 keys | 5462 slots | 1 slaves.
172.16.1.123:6381 (ac2a7383...) -> 0 keys | 0 slots | 0 slaves.
[OK] 1000 keys in 4 masters.
0.06 keys per slot on average.
# 或者
[root@dbtest03 ~]# redis-cli -p 6379 -h 172.16.1.121 cluster nodes
98f828cce3188a3f670dbbd9f77b5723df6cf53b 172.16.1.123:6379 master - 0 1596791728636 3 connected 10923-16383
cd7afafbf822fb17c26e0e45c921dfa94d8526b9 172.16.1.123:6380 slave 85622647ecc43b13ea10083aa59e73399a30b75f 0 1596791730146 5 connected
0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 172.16.1.122:6379 master - 0 1596791730649 2 connected 5461-10922
85622647ecc43b13ea10083aa59e73399a30b75f 172.16.1.121:6379 myself,master - 0 0 1 connected 0-5460
ed5d625d41f5c3621bdd068dbd0c2c30bc4c0649 172.16.1.121:6380 slave 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 0 1596791729138 6 connected
ac2a738356e56952a792fc36c51290675bcc7ed9 172.16.1.123:6381 master - 0 1596791729139 0 connected
92bf59c43755c92953e50dda2c7d806bbb9d5f7b 172.16.1.122:6380 slave 98f828cce3188a3f670dbbd9f77b5723df6cf53b 0 1596791729139 4 connected
重新分配槽位
[root@dbtest03 ~]# redis-trib.rb reshard 172.16.1.121:6379
# 你想移動多少個槽位到新節點
How many slots do you want to move (from 1 to 16384)? 4096
# 新節點的 ID 是什麼
What is the receiving node ID? ac2a738356e56952a792fc36c51290675bcc7ed9
# 輸入源節點的ID,如果是所有節點直接使用 all
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:all
# 你確定要這麼分配?
Do you want to proceed with the proposed reshard plan (yes/no)? yes
# 分配完畢,檢視分配結果
[root@dbtest03 ~]# redis-cli -p 6379 -h 172.16.1.121 cluster nodes
98f828cce3188a3f670dbbd9f77b5723df6cf53b 172.16.1.123:6379 master - 0 1596792078142 3 connected 12288-16383
cd7afafbf822fb17c26e0e45c921dfa94d8526b9 172.16.1.123:6380 slave 85622647ecc43b13ea10083aa59e73399a30b75f 0 1596792079652 5 connected
0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 172.16.1.122:6379 master - 0 1596792080155 2 connected 6827-10922
85622647ecc43b13ea10083aa59e73399a30b75f 172.16.1.121:6379 myself,master - 0 0 1 connected 1365-5460
ed5d625d41f5c3621bdd068dbd0c2c30bc4c0649 172.16.1.121:6380 slave 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 0 1596792078645 6 connected
ac2a738356e56952a792fc36c51290675bcc7ed9 172.16.1.123:6381 master - 0 1596792078645 7 connected 0-1364 5461-6826 10923-12287
92bf59c43755c92953e50dda2c7d806bbb9d5f7b 172.16.1.122:6380 slave 98f828cce3188a3f670dbbd9f77b5723df6cf53b 0 1596792079652 4 connected
# 或者
[root@dbtest03 ~]# redis-trib.rb info 172.16.1.121:6379
172.16.1.121:6379 (85622647...) -> 249 keys | 4096 slots | 1 slaves.
172.16.1.123:6379 (98f828cc...) -> 251 keys | 4096 slots | 1 slaves.
172.16.1.122:6379 (0f0232ee...) -> 254 keys | 4096 slots | 1 slaves.
172.16.1.123:6381 (ac2a7383...) -> 246 keys | 4096 slots | 0 slaves.
[OK] 1000 keys in 4 masters.
0.06 keys per slot on average.
新增新節點副本
# 新增新節點的副本
[root@dbtest02 ~]# redis-cli -h 172.16.1.123 -p 6382 cluster replicate ac2a738356e56952a792fc36c51290675bcc7ed9
# 或者
[root@dbtest01 ~]# redis-trib.rb add-node --slave --master-id ac2a738356e56952a792fc36c51290675bcc7ed9 172.16.1.122:6382 172.16.1.121:6379
# 上面的命令中最後的 172.16.1.121:6379 ,可以換成叢集中任意一臺 Redis 例項節點
# 檢視 Redis 叢集狀態,叢集每個節點都有一個從庫
[root@dbtest03 ~]# redis-trib.rb info 172.16.1.121:6379
172.16.1.121:6379 (85622647...) -> 249 keys | 4096 slots | 1 slaves.
172.16.1.123:6379 (98f828cc...) -> 251 keys | 4096 slots | 1 slaves.
172.16.1.122:6379 (0f0232ee...) -> 254 keys | 4096 slots | 1 slaves.
172.16.1.123:6381 (ac2a7383...) -> 246 keys | 4096 slots | 1 slaves.
[OK] 1000 keys in 4 masters.
0.06 keys per slot on average.
# 或者
[root@dbtest03 ~]# redis-cli -p 6379 -h 172.16.1.121 cluster nodes
98f828cce3188a3f670dbbd9f77b5723df6cf53b 172.16.1.123:6379 master - 0 1596795522020 3 connected 12288-16383
591fab958ffe8695ea83287b6576cd3ba720b385 172.16.1.123:6382 slave ac2a738356e56952a792fc36c51290675bcc7ed9 0 1596795521515 7 connected
0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 172.16.1.122:6379 master - 0 1596795521515 2 connected 6827-10922
85622647ecc43b13ea10083aa59e73399a30b75f 172.16.1.121:6379 myself,master - 0 0 1 connected 1365-5460
92bf59c43755c92953e50dda2c7d806bbb9d5f7b 172.16.1.122:6380 slave 98f828cce3188a3f670dbbd9f77b5723df6cf53b 0 1596795520508 4 connected
cd7afafbf822fb17c26e0e45c921dfa94d8526b9 172.16.1.123:6380 slave 85622647ecc43b13ea10083aa59e73399a30b75f 0 1596795522523 5 connected
ed5d625d41f5c3621bdd068dbd0c2c30bc4c0649 172.16.1.121:6380 slave 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 0 1596795521011 6 connected
ac2a738356e56952a792fc36c51290675bcc7ed9 172.16.1.123:6381 master - 0 1596795521515 7 connected 0-1364 5461-6826 10923-12287
# 調整主從,儘量保證每一臺機器的副本都不於主節點在一臺機器
模擬故障(不作不會死)
# 分配槽位的過程中
[root@dbtest01 ~]# redis-trib.rb reshard 172.16.1.121:6379
# 執行 Ctrl+c
# 檢視叢集狀態一些命令看不出來有錯
[root@dbtest01 ~]# redis-cli -p 6379 -h 172.16.1.121 cluster info
[root@dbtest01 ~]# redis-cli -p 6379 -h 172.16.1.121 cluster nodes
[root@dbtest01 ~]# redis-trib.rb info 172.16.1.121:6379
# 必須使用工具檢查叢集
[root@dbtest01 ~]# redis-trib.rb check 172.16.1.121:6379
# 錯誤一:172.16.1.122:6379 節點正在匯出槽位,172.16.1.122:6381 節點正在匯入槽位
>>> Check for open slots...
[WARNING] Node 172.16.1.122:6381 has slots in importing state (6885).
[WARNING] Node 172.16.1.122:6379 has slots in migrating state (6885).
[WARNING] The following slots are open: 6885
>>> Check slots coverage...
#錯誤二:172.16.1.122:6379 節點正在匯出槽位
>>> Check for open slots...
[WARNING] Node 172.16.1.122:6379 has slots in migrating state (6975).
[WARNING] The following slots are open: 6975
>>> Check slots coverage...
#錯誤三:
>>> Check for open slots...
[WARNING] Node 172.16.1.122:6381 has slots in importing state (7093).
[WARNING] The following slots are open: 7093
>>> Check slots coverage...
修復故障(不作不會死)
#使用fix修復叢集
[root@dbtest01 ~]# redis-trib.rb fix 172.16.1.122:6379
#將槽位平均分配
1.平均之前
[root@dbtest01 ~]# redis-trib.rb info 172.16.1.121:6379
172.16.1.121:6379 (5ad7bd95...) -> 499 keys | 4096 slots | 1 slaves.
172.16.1.123:6379 (d2755303...) -> 501 keys | 4096 slots | 1 slaves.
172.16.1.122:6381 (a298dbd2...) -> 648 keys | 5320 slots | 1 slaves.
172.16.1.122:6379 (7c79559b...) -> 352 keys | 2872 slots | 1 slaves.
[OK] 2000 keys in 4 masters.
0.12 keys per slot on average.
2.平均分配(如果節點之間槽位數量相差較小,不會平均分配)
[root@dbtest01 ~]# redis-trib.rb rebalance 172.16.1.121:6379
>>> Performing Cluster Check (using node 172.16.1.121:6379)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Rebalancing across 4 nodes. Total weight = 4
Moving 1224 slots from 172.16.1.122:6381 to 172.16.1.122:6379
#####################################################################################################
3平均分配之後
[root@dbtest01 ~]# redis-trib.rb info 172.16.1.121:6379
172.16.1.121:6379 (5ad7bd95...) -> 499 keys | 4096 slots | 1 slaves.
172.16.1.123:6379 (d2755303...) -> 501 keys | 4096 slots | 1 slaves.
172.16.1.122:6381 (a298dbd2...) -> 492 keys | 4096 slots | 1 slaves.
172.16.1.122:6379 (7c79559b...) -> 508 keys | 4096 slots | 1 slaves.
[OK] 2000 keys in 4 masters.
0.12 keys per slot on average.
刪除節點
重新分配槽位
# 重新分配
[root@dbtest01 ~]#redis-trib.rb reshard 172.16.1.121:6379
...
How many slots do you want to move (from 1 to 16384)? 1365 # 要分配的槽位數量
What is the receiving node ID? 85622647ecc43b13ea10083aa59e73399a30b75f # 接收槽位的節點 id
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:ac2a738356e56952a792fc36c51290675bcc7ed9 # 要刪除的節點 id
Source node #2:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes
...
# 第二次重新分配
[root@dbtest03 ~]# redis-trib.rb reshard 172.16.1.121:6379
>>> Performing Cluster Check (using node 172.16.1.121:6379)
M: 85622647ecc43b13ea10083aa59e73399a30b75f 172.16.1.121:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 98f828cce3188a3f670dbbd9f77b5723df6cf53b 172.16.1.123:6379
slots:12288-16383 (4096 slots) master
1 additional replica(s)
S: 591fab958ffe8695ea83287b6576cd3ba720b385 172.16.1.123:6382
slots: (0 slots) slave
replicates ac2a738356e56952a792fc36c51290675bcc7ed9
M: 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 172.16.1.122:6379
slots:6827-10922 (4096 slots) master
1 additional replica(s)
S: 92bf59c43755c92953e50dda2c7d806bbb9d5f7b 172.16.1.122:6380
slots: (0 slots) slave
replicates 98f828cce3188a3f670dbbd9f77b5723df6cf53b
S: cd7afafbf822fb17c26e0e45c921dfa94d8526b9 172.16.1.123:6380
slots: (0 slots) slave
replicates 85622647ecc43b13ea10083aa59e73399a30b75f
S: ed5d625d41f5c3621bdd068dbd0c2c30bc4c0649 172.16.1.121:6380
slots: (0 slots) slave
replicates 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9
M: ac2a738356e56952a792fc36c51290675bcc7ed9 172.16.1.123:6381
slots:5461-6826,10923-12287 (2731 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? 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9
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:ac2a738356e56952a792fc36c51290675bcc7ed9
Source node #2:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes
# 第三次重新分配
[root@dbtest03 ~]# redis-trib.rb reshard 172.16.1.121:6379
>>> Performing Cluster Check (using node 172.16.1.121:6379)
M: 85622647ecc43b13ea10083aa59e73399a30b75f 172.16.1.121:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 98f828cce3188a3f670dbbd9f77b5723df6cf53b 172.16.1.123:6379
slots:12288-16383 (4096 slots) master
1 additional replica(s)
S: 591fab958ffe8695ea83287b6576cd3ba720b385 172.16.1.123:6382
slots: (0 slots) slave
replicates ac2a738356e56952a792fc36c51290675bcc7ed9
M: 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 172.16.1.122:6379
slots:5461-6825,6827-10922 (5461 slots) master
1 additional replica(s)
S: 92bf59c43755c92953e50dda2c7d806bbb9d5f7b 172.16.1.122:6380
slots: (0 slots) slave
replicates 98f828cce3188a3f670dbbd9f77b5723df6cf53b
S: cd7afafbf822fb17c26e0e45c921dfa94d8526b9 172.16.1.123:6380
slots: (0 slots) slave
replicates 85622647ecc43b13ea10083aa59e73399a30b75f
S: ed5d625d41f5c3621bdd068dbd0c2c30bc4c0649 172.16.1.121:6380
slots: (0 slots) slave
replicates 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9
M: ac2a738356e56952a792fc36c51290675bcc7ed9 172.16.1.123:6381
slots:6826,10923-12287 (1366 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)? 1
What is the receiving node ID? 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9
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:ac2a738356e56952a792fc36c51290675bcc7ed9
Source node #2:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes
檢視節點資訊
[root@dbtest03 ~]# redis-trib.rb info 172.16.1.121:6379
172.16.1.121:6379 (85622647...) -> 341 keys | 5461 slots | 1 slaves.
172.16.1.123:6379 (98f828cc...) -> 327 keys | 5461 slots | 2 slaves.
172.16.1.122:6379 (0f0232ee...) -> 332 keys | 5462 slots | 1 slaves.
172.16.1.123:6381 (ac2a7383...) -> 0 keys | 0 slots | 0 slaves.
[OK] 1000 keys in 4 masters.
0.06 keys per slot on average.
刪除節點(無資料)
# 刪除沒有資料的主節點
[root@dbtest03 ~]# redis-trib.rb del-node 172.16.1.123:6381 ac2a738356e56952a792fc36c51290675bcc7ed9
>>> Removing node ac2a738356e56952a792fc36c51290675bcc7ed9 from cluster 172.16.1.123:6381
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
# 刪除從節點
[root@dbtest03 ~]# redis-trib.rb del-node 172.16.1.123:6382 591fab958ffe8695ea83287b6576cd3ba720b385
>>> Removing node 591fab958ffe8695ea83287b6576cd3ba720b385 from cluster 172.16.1.123:6382
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
# 刪除時不能刪除有資料的主節點,從節點可以隨便刪除
[root@dbtest03 ~]# redis-trib.rb del-node 172.16.1.121:6379 85622647ecc43b13ea10083aa59e73399a30b75f
>>> Removing node 85622647ecc43b13ea10083aa59e73399a30b75f from cluster 172.16.1.121:6379
[ERR] Node 172.16.1.121:6379 is not empty! Reshard data away and try again.