1、環境準備node
一、部署Redis5集羣(見前一篇文章)redis
二、增長節點bash
masterapp
172.16.254.121:7001ide
slavespa
172.16.254.122:70023d
並啓動redis進程code
2、集羣擴容orm
添加節點 172.16.254.121:7001到集羣進程
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
redis-cli --cluster add-node 172.16.254.121:7001 172.16.254.124:7004
>>> Adding node 172.16.254.121:7001 to cluster 172.16.254.124:7004
>>> Performing Cluster Check (using node 172.16.254.124:7004)
M: dae116bae245c1d9b94643c627243f0122dec6ad 172.16.254.124:7004
slots:[0-1499],[2999-5460] (3962 slots) master
1 additional replica(s)
S: 0600bacf8e9be9572c780090cb242e1e1e0206a2 172.16.254.129:7009
slots: (0 slots) slave
replicates a489464dfd1321cdbe2a0f464856218a38127e19
M: a489464dfd1321cdbe2a0f464856218a38127e19 172.16.254.125:7005
slots:[1500-2998],[5461-11423] (7462 slots) master
1 additional replica(s)
S: 8205aa9f24882516bb8bbe0fb7d2c593271de152 172.16.254.127:7007
slots: (0 slots) slave
replicates 5aa077444a506afad1ff796616124a0b7298c125
S: 804ecd22d3de6dc2080a8de572a320407596b6fb 172.16.254.128:7008
slots: (0 slots) slave
replicates dae116bae245c1d9b94643c627243f0122dec6ad
M: 5aa077444a506afad1ff796616124a0b7298c125 172.16.254.126:7006
slots:[11424-16383] (4960 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 172.16.254.121:7001 to
make
it
join
the cluster.
[OK] New node added correctly.
|
添加 172.16.254.122:7002到集羣
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
redis-cli --cluster add-node 172.16.254.122:7002 172.16.254.124:7004
>>> Adding node 172.16.254.122:7002 to cluster 172.16.254.124:7004
>>> Performing Cluster Check (using node 172.16.254.124:7004)
M: dae116bae245c1d9b94643c627243f0122dec6ad 172.16.254.124:7004
slots:[0-1499],[2999-5460] (3962 slots) master
1 additional replica(s)
S: 0600bacf8e9be9572c780090cb242e1e1e0206a2 172.16.254.129:7009
slots: (0 slots) slave
replicates a489464dfd1321cdbe2a0f464856218a38127e19
M: a489464dfd1321cdbe2a0f464856218a38127e19 172.16.254.125:7005
slots:[1500-2998],[5461-11423] (7462 slots) master
1 additional replica(s)
S: 8205aa9f24882516bb8bbe0fb7d2c593271de152 172.16.254.127:7007
slots: (0 slots) slave
replicates 5aa077444a506afad1ff796616124a0b7298c125
M: 57bfd28d400e95395b10fb62e77a2b9f9a05dddb 172.16.254.121:7001
slots: (0 slots) master
S: 804ecd22d3de6dc2080a8de572a320407596b6fb 172.16.254.128:7008
slots: (0 slots) slave
replicates dae116bae245c1d9b94643c627243f0122dec6ad
M: 5aa077444a506afad1ff796616124a0b7298c125 172.16.254.126:7006
slots:[11424-16383] (4960 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 172.16.254.122:7002 to
make
it
join
the cluster.
[OK] New node added correctly.
|
查看集羣狀態:
1
2
3
4
5
6
7
8
9
|
redis-cli -c -h 172.16.254.124 -p 7004 cluster nodes
01049b46ff785dbc99d26f628893ab6cb24f86a1 172.16.254.122:7002@17002 master - 0 1614780779000 11 connected
0600bacf8e9be9572c780090cb242e1e1e0206a2 172.16.254.129:7009@17009 slave a489464dfd1321cdbe2a0f464856218a38127e19 0 1614780776000 9 connected
a489464dfd1321cdbe2a0f464856218a38127e19 172.16.254.125:7005@17005 master - 0 1614780779056 9 connected 1500-2998 5461-11423
8205aa9f24882516bb8bbe0fb7d2c593271de152 172.16.254.127:7007@17007 slave 5aa077444a506afad1ff796616124a0b7298c125 0 1614780781164 10 connected
57bfd28d400e95395b10fb62e77a2b9f9a05dddb 172.16.254.121:7001@17001 master - 0 1614780779000 0 connected
dae116bae245c1d9b94643c627243f0122dec6ad 172.16.254.124:7004@17004 myself,master - 0 1614780777000 8 connected 0-1499 2999-5460
804ecd22d3de6dc2080a8de572a320407596b6fb 172.16.254.128:7008@17008 slave dae116bae245c1d9b94643c627243f0122dec6ad 0 1614780780104 8 connected
5aa077444a506afad1ff796616124a0b7298c125 172.16.254.126:7006@17006 master - 0 1614780776000 10 connected 11424-16383
|
能夠看到此時 172.16.254.121:7001和 172.16.254.122:7002都認爲本身是master,不要着急,往下作。
咱們將 172.16.254.121:7001做爲master節點,並對其分片。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
redis-cli --cluster reshard 172.16.254.121:7001
>>> Performing Cluster Check (using node 172.16.254.121:7001)
M: 57bfd28d400e95395b10fb62e77a2b9f9a05dddb 172.16.254.121:7001
slots: (0 slots) master
S: 8205aa9f24882516bb8bbe0fb7d2c593271de152 172.16.254.127:7007
slots: (0 slots) slave
replicates 5aa077444a506afad1ff796616124a0b7298c125
M: 01049b46ff785dbc99d26f628893ab6cb24f86a1 172.16.254.122:7002
slots: (0 slots) master
M: a489464dfd1321cdbe2a0f464856218a38127e19 172.16.254.125:7005
slots:[1500-2998],[5461-11423] (7462 slots) master
1 additional replica(s)
M: 5aa077444a506afad1ff796616124a0b7298c125 172.16.254.126:7006
slots:[11424-16383] (4960 slots) master
1 additional replica(s)
S: 0600bacf8e9be9572c780090cb242e1e1e0206a2 172.16.254.129:7009
slots: (0 slots) slave
replicates a489464dfd1321cdbe2a0f464856218a38127e19
S: 804ecd22d3de6dc2080a8de572a320407596b6fb 172.16.254.128:7008
slots: (0 slots) slave
replicates dae116bae245c1d9b94643c627243f0122dec6ad
M: dae116bae245c1d9b94643c627243f0122dec6ad 172.16.254.124:7004
slots:[0-1499],[2999-5460] (3962 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)? 2000
#分配多少個槽給172.16.254.121
What is the receiving node ID? 57bfd28d400e95395b10fb62e77a2b9f9a05dddb
#接受節點的ID,這裏咱們寫172.16.254.121:7001的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: 5aa077444a506afad1ff796616124a0b7298c125
#填寫槽的來源,咱們這裏把172.16.254.126:7006分給172.16.254.121,因此填寫5aa077444a506afad1ff796616124a0b7298c125
|
再次查看集羣各個節點信息:
1
2
3
4
5
6
7
8
9
|
redis-cli -c -h 172.16.254.124 -p 7004 cluster nodes
01049b46ff785dbc99d26f628893ab6cb24f86a1 172.16.254.122:7002@17002 master - 0 1614781289324 11 connected
0600bacf8e9be9572c780090cb242e1e1e0206a2 172.16.254.129:7009@17009 slave a489464dfd1321cdbe2a0f464856218a38127e19 0 1614781292813 9 connected
a489464dfd1321cdbe2a0f464856218a38127e19 172.16.254.125:7005@17005 master - 0 1614781291000 9 connected 1500-2998 5461-11423
8205aa9f24882516bb8bbe0fb7d2c593271de152 172.16.254.127:7007@17007 slave 5aa077444a506afad1ff796616124a0b7298c125 0 1614781293000 10 connected
57bfd28d400e95395b10fb62e77a2b9f9a05dddb 172.16.254.121:7001@17001 master - 0 1614781295447 12 connected 11424-13423
dae116bae245c1d9b94643c627243f0122dec6ad 172.16.254.124:7004@17004 myself,master - 0 1614781294000 8 connected 0-1499 2999-5460
804ecd22d3de6dc2080a8de572a320407596b6fb 172.16.254.128:7008@17008 slave dae116bae245c1d9b94643c627243f0122dec6ad 0 1614781291000 8 connected
5aa077444a506afad1ff796616124a0b7298c125 172.16.254.126:7006@17006 master - 0 1614781294251 10 connected 13424-16383
|
能夠看到172.16.254.121:7001已經分到了一些槽,而172.16.254.122:7002什麼都沒獲得,仍是一臉懵逼。咱們把 172.16.254.122:7002設置爲 172.16.254.121:7001的從節點。
1
2
3
|
redis-cli -c -h 172.16.254.122 -p 7002
172.16.254.122:7002> cluster replicate 57bfd28d400e95395b10fb62e77a2b9f9a05dddb
OK
|
查看集羣狀態:
1
2
3
4
5
6
7
8
9
|
172.16.254.122:7002> cluster nodes
5aa077444a506afad1ff796616124a0b7298c125 172.16.254.126:7006@17006 master - 0 1614781558502 10 connected 13424-16383
a489464dfd1321cdbe2a0f464856218a38127e19 172.16.254.125:7005@17005 master - 0 1614781557238 9 connected 1500-2998 5461-11423
8205aa9f24882516bb8bbe0fb7d2c593271de152 172.16.254.127:7007@17007 slave 5aa077444a506afad1ff796616124a0b7298c125 0 1614781555914 10 connected
dae116bae245c1d9b94643c627243f0122dec6ad 172.16.254.124:7004@17004 master - 0 1614781555000 8 connected 0-1499 2999-5460
804ecd22d3de6dc2080a8de572a320407596b6fb 172.16.254.128:7008@17008 slave dae116bae245c1d9b94643c627243f0122dec6ad 0 1614781556000 8 connected
57bfd28d400e95395b10fb62e77a2b9f9a05dddb 172.16.254.121:7001@17001 master - 0 1614781558641 12 connected 11424-13423
0600bacf8e9be9572c780090cb242e1e1e0206a2 172.16.254.129:7009@17009 slave a489464dfd1321cdbe2a0f464856218a38127e19 0 1614781555570 9 connected
01049b46ff785dbc99d26f628893ab6cb24f86a1 172.16.254.122:7002@17002 myself,slave 57bfd28d400e95395b10fb62e77a2b9f9a05dddb 0 1614781552000 11 connected
|
此時 172.16.254.122:7002終於意識到本身是slave了。
3、集羣驗證
在新加的主節點 172.16.254.121寫入數據
1
2
3
4
|
redis-cli -c -h 172.16.254.121 -p 7001
172.16.254.121:7001>
set
city22 kunming
-> Redirected to slot [7075] located at 172.16.254.125:7005
OK
|
在老節點 172.16.254.124查詢數據:
1
2
3
|
172.16.254.124:7004> get city22
-> Redirected to slot [7075] located at 172.16.254.125:7005
"kunming"
|
能夠看到數據在老節點已經能夠查到。
在老節點 172.16.254.126寫入數據:
1
2
3
|
172.16.254.126:7006>
set
city23 luoyang
-> Redirected to slot [2946] located at 172.16.254.125:7005
OK
|
在新節點 172.16.254.122查詢數據:
1
2
3
|
172.16.254.122:7002> get city23
-> Redirected to slot [2946] located at 172.16.254.125:7005
"luoyang"
|
在老節點插入數據,新節點也能夠查到。