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

搭建好集群之后,为了扩容需要再加入一个节点。那就再复制一个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.

好的,假装他删的很顺利~~

 还有需要补充的之后继续补充......

 

你可能感兴趣的:(redis)