redis叢集部署及常用的操作命令(下)

豬頭強發表於2015-07-27

搭建好叢集之後,為了擴容需要再加入一個節點。那就再複製一個7006,改為相應的redis.conf(複製了改個port就好,如果複製的redis之前屬於叢集,需要把關聯的node.conf之類的去掉)

[root@localhost 7006]# vim redis.conf 
[root@localhost 7006]# src/redis-server redis.conf 
[root@localhost 7006]# ps -ef | grep redis
root      2993  2959  0 15:48 pts/0    00:00:00 src/redis-server *:6379
root      2999     1  0 15:49 ?        00:00:00 src/redis-server *:7000 [cluster]
root      3006     1  0 15:49 ?        00:00:00 src/redis-server *:7001 [cluster]
root      3013     1  0 15:49 ?        00:00:00 src/redis-server *:7002 [cluster]
root      3017     1  0 15:50 ?        00:00:00 src/redis-server *:7003 [cluster]
root      3021     1  0 15:50 ?        00:00:00 src/redis-server *:7004 [cluster]
root      3028     1  0 15:50 ?        00:00:00 src/redis-server *:7005 [cluster]
root      3061     1  0 15:59 ?        00:00:00 src/redis-server *:7006 [cluster]

(1)新增節點

很簡單的一句命令: 前面是地址是新加入的一臺redis,後面是屬於之前叢集的任意一臺。

[root@localhost 7006]# src/redis-trib.rb add-node 127.0.0.1:7006 127.0.0.1:7001
>>> Adding node 127.0.0.1:7006 to cluster 127.0.0.1:7001
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7003: OK
>>> Performing Cluster Check (using node 127.0.0.1:7001)
M: 0bbc46d087d7256fb7b71ca35871446e29926afa 127.0.0.1:7001
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: ec376f305428afde24aa363919a863f01908c140 127.0.0.1:7004
   slots: (0 slots) slave
   replicates 0bbc46d087d7256fb7b71ca35871446e29926afa
M: 0b521aa8664b2e51475470230f3a975bdd4d1909 127.0.0.1:7002
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: d1a7c6485909a119a1c276f3972b8ae3f93e52d7 127.0.0.1:7005
   slots: (0 slots) slave
   replicates 0b521aa8664b2e51475470230f3a975bdd4d1909
M: 9b7b98c4bf2517e4f172a895b5728d13bef62952 127.0.0.1:7000
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: ee95130f0aed20c62881df8070d7690c4608a7cc 127.0.0.1:7003
   slots: (0 slots) slave
   replicates 9b7b98c4bf2517e4f172a895b5728d13bef62952
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Connecting to node 127.0.0.1:7006: OK
>>> Send CLUSTER MEET to node 127.0.0.1:7006 to make it join the cluster.
[OK] New node added correctly.

可以任意進入一臺機器來檢視是否新增了新的節點,會發現剛剛新增的節點並沒有託管任何的雜湊槽,原因是裡面還木有資料了。增加從節點只需要加上--slave引數

[root@localhost 7006]# src/redis-cli -c -p 7001
127.0.0.1:7001> cluster nodes
0bbc46d087d7256fb7b71ca35871446e29926afa 127.0.0.1:7001 myself,master - 0 0 2 connected 5461-10922
32cc36d5deead5d8eb3208120d6f38358c9b6a55 127.0.0.1:7006 master - 0 1437992923735 0 connected
ec376f305428afde24aa363919a863f01908c140 127.0.0.1:7004 slave 0bbc46d087d7256fb7b71ca35871446e29926afa 0 1437992924736 5 connected
0b521aa8664b2e51475470230f3a975bdd4d1909 127.0.0.1:7002 master - 0 1437992924736 3 connected 10923-16383
d1a7c6485909a119a1c276f3972b8ae3f93e52d7 127.0.0.1:7005 slave 0b521aa8664b2e51475470230f3a975bdd4d1909 0 1437992922732 6 connected
9b7b98c4bf2517e4f172a895b5728d13bef62952 127.0.0.1:7000 master - 0 1437992923234 1 connected 0-5460
ee95130f0aed20c62881df8070d7690c4608a7cc 127.0.0.1:7003 slave 9b7b98c4bf2517e4f172a895b5728d13bef62952 0 1437992924236 4 connected

(2)刪除節點

刪除節點之前首先要保證節點中沒有資料,如果有資料需要分片,把資料轉移走。後面跟著的id用cluster nodes 就能檢視到對應的啦~

刪除有資料的我還需要研究研究。。。因為一些很拙計的原因~~, ./redis-trib.rb reshard 127.0.0.1:9003 這句是轉移時講資料分配到那些雜湊槽下的命令。

[root@localhost 7006]# src/redis-trib.rb del-node 127.0.0.1:7001 'c8ed852a52863e941a6e63037e018eb2952b776a'
>>> Removing node c8ed852a52863e941a6e63037e018eb2952b776a from cluster 127.0.0.1:7001
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7005: OK
Connecting to node 127.0.0.1:7006: OK
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7003: OK
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

好的,假裝他刪的很順利~~

 還有需要補充的之後繼續補充......

 

相關文章