1梆造、加入新master
在上篇基礎上增加
7007.conf,和一個redis_7007啟動腳本
redis-trib.rb add-node 127.0.0.1:7007 127.0.0.1:7001
redis-trib.rb check 127.0.0.1:7001
out:
[root@1b0c5aafc62b init.d]# redis-trib.rb check 127.0.0.1:7001
>>> Performing Cluster Check (using node 127.0.0.1:7001)
M: 5f7f1ff4582dcd1a6cc66a9e636fe18bcacc7d4c 127.0.0.1:7001
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 0e2a60a544a2d4441beb03224a07ad6c437363c6 127.0.0.1:7007
slots: (0 slots) master
0 additional replica(s)
M: be557259c0ea02517557931251df7120c00cd4c2 127.0.0.1:7003
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 65e578ed3fe7d5947a4f9c621c8157ab6c1251b5 127.0.0.1:7006
slots: (0 slots) slave
replicates be557259c0ea02517557931251df7120c00cd4c2
S: 3cb4215cb614950f9e68be6a995bf98ea81d52a6 127.0.0.1:7005
slots: (0 slots) slave
replicates 63035068bbbc1ee1df40a050d5d47b7779f86043
S: 210ae237bb73aa3c876eb9933a9926c575fba0cd 127.0.0.1:7004
slots: (0 slots) slave
replicates 5f7f1ff4582dcd1a6cc66a9e636fe18bcacc7d4c
M: 63035068bbbc1ee1df40a050d5d47b7779f86043 127.0.0.1:7002
slots:5461-10922 (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.
發(fā)現(xiàn) 新加入的 master 沒有槽位
2葬毫、reshard一些數(shù)據(jù)過去
resharding的意思就是把一部分hash slot從一些node上遷移到另外一些node上
之前三個 master 每個 平均大概 5461 槽位
變成四個 每個master 4096 reshard 后輸入 4096
redis-trib.rb reshard 127.0.0.1:7001
[root@1b0c5aafc62b init.d]# redis-trib.rb reshard 127.0.0.1:7001
>>> Performing Cluster Check (using node 127.0.0.1:7001)
M: 5f7f1ff4582dcd1a6cc66a9e636fe18bcacc7d4c 127.0.0.1:7001
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 0e2a60a544a2d4441beb03224a07ad6c437363c6 127.0.0.1:7007
slots: (0 slots) master
0 additional replica(s)
M: be557259c0ea02517557931251df7120c00cd4c2 127.0.0.1:7003
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 65e578ed3fe7d5947a4f9c621c8157ab6c1251b5 127.0.0.1:7006
slots: (0 slots) slave
replicates be557259c0ea02517557931251df7120c00cd4c2
S: 3cb4215cb614950f9e68be6a995bf98ea81d52a6 127.0.0.1:7005
slots: (0 slots) slave
replicates 63035068bbbc1ee1df40a050d5d47b7779f86043
S: 210ae237bb73aa3c876eb9933a9926c575fba0cd 127.0.0.1:7004
slots: (0 slots) slave
replicates 5f7f1ff4582dcd1a6cc66a9e636fe18bcacc7d4c
M: 63035068bbbc1ee1df40a050d5d47b7779f86043 127.0.0.1:7002
slots:5461-10922 (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.
How many slots do you want to move (from 1 to 16384)? 4096
What is the receiving node ID? 0e2a60a544a2d4441beb03224a07ad6c437363c6
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:5f7f1ff4582dcd1a6cc66a9e636fe18bcacc7d4c
Source node #2:be557259c0ea02517557931251df7120c00cd4c2
Source node #3:63035068bbbc1ee1df40a050d5d47b7779f86043
輸入4096 然后輸入目標 的master ID 然后輸入 原始的 master Id (源頭)
輸入 done 結(jié)尾
3镇辉、添加node作為slave
增加 7008.conf,和一個redis_7008啟動腳本
mkdir -p /var/redis/7008
port 7008
cluster-enabled yes
cluster-config-file /etc/redis-cluster/node-7008.conf
cluster-node-timeout 15000
daemonize yes
pidfile /var/run/redis_7008.pid
dir /var/redis/7008
logfile /var/log/redis/7008.log
bind 127.0.0.1
appendonly yes
增加slave
redis-trib.rb add-node --slave --master-id XXXXXXXX 127.0.0.1:7008 127.0.0.1:7001
我掛載到 新加入的master 上
redis-trib.rb add-node --slave --master-id 0e2a60a544a2d4441beb03224a07ad6c437363c6 127.0.0.1:7008 127.0.0.1:7001
4贴捡、刪除node
redis-trib.rb reshard 127.0.0.1:7001
先用resharding將數(shù)據(jù)都移除到其他節(jié)點忽肛,確保node為空之后,才能執(zhí)行remove操作
2個是1365烂斋,1個是1366
當你清空了一個master的hashslot時屹逛,redis cluster就會自動將其slave掛載到其他master上去
這個時候就只要刪除掉master就可以了
redis-trib.rb del-node 127.0.0.1:7001 be557259c0ea02517557931251df7120c00cd4c2
check 發(fā)現(xiàn) slove 自動轉(zhuǎn)移了
[root@1b0c5aafc62b /]# redis-trib.rb check 127.0.0.1:7001
>>> Performing Cluster Check (using node 127.0.0.1:7001)
M: 5f7f1ff4582dcd1a6cc66a9e636fe18bcacc7d4c 127.0.0.1:7001
slots:1365-5460,13653-15017 (5461 slots) master
1 additional replica(s)
M: 0e2a60a544a2d4441beb03224a07ad6c437363c6 127.0.0.1:7007
slots:0-1364,5461-6826,10923-13652 (5461 slots) master
1 additional replica(s)
S: 65e578ed3fe7d5947a4f9c621c8157ab6c1251b5 127.0.0.1:7006
slots: (0 slots) slave
replicates 63035068bbbc1ee1df40a050d5d47b7779f86043
S: 3cb4215cb614950f9e68be6a995bf98ea81d52a6 127.0.0.1:7005
slots: (0 slots) slave
replicates 63035068bbbc1ee1df40a050d5d47b7779f86043
S: f3f6a32fb58b4b734f2c90cfca64ad71c6acb83f 127.0.0.1:7008
slots: (0 slots) slave
replicates 0e2a60a544a2d4441beb03224a07ad6c437363c6
S: 210ae237bb73aa3c876eb9933a9926c575fba0cd 127.0.0.1:7004
slots: (0 slots) slave
replicates 5f7f1ff4582dcd1a6cc66a9e636fe18bcacc7d4c
M: 63035068bbbc1ee1df40a050d5d47b7779f86043 127.0.0.1:7002
slots:6827-10922,15018-16383 (5462 slots) master
2 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
slave的自動遷移
比如現(xiàn)在有10個master,每個有1個slave汛骂,然后新增了3個slave作為冗余罕模,有的master就有2個slave了,有的master出現(xiàn)了salve冗余
如果某個master的slave掛了帘瞭,那么redis cluster會自動遷移一個冗余的slave給那個master
只要多加一些冗余的slave就可以了
為了避免的場景淑掌,就是說,如果你每個master只有一個slave蝶念,萬一說一個slave死了抛腕,然后很快,master也死了媒殉,那可用性還是降低了
但是如果你給整個集群掛載了一些冗余slave担敌,那么某個master的slave死了,冗余的slave會被自動遷移過去廷蓉,作為master的新slave全封,此時即使那個master也死了
還是有一個slave會切換成master的
之前有一個master是有冗余slave的,直接讓其他master其中的一個slave死掉桃犬,然后看有冗余slave會不會自動掛載到那個master