Redis Cluster cluster architecture to achieve

Redis cluster Profile

Introduction to redis clusters can refer to the following excerpt from my Profile redis official website.

Redis is a cluster may be a plurality Redis data sharing between nodes facilities (installation).

Redis Redis cluster does not support commands that need to process a plurality of keys, such as execution commands need to move data between a plurality of nodes Redis, and in the case of high load, which will reduce the performance Redis command cluster, and not cause predictable behavior.

Redis Cluster Partitions ( Partition to provide a degree of) availability (availability): Even if a part of a cluster node fails or is unable to communicate, the cluster can continue processing the command request.

Redis cluster provides the following two benefits:

  • The automatic segmentation data (Split) to a plurality of nodes of capacity.
  • When part of a cluster node fails or can not communicate, you can continue processing capability command request. - Excerpt from the official website redis

All in all, redis clusters to achieve a shared and decentralized data.

 

Redis Cluster to Realize

Achieve redis clusters, now using a server installed six redis example, if explain in detail about the installation of multiple instances please refer to my article on the blog " Redis master-slave replication, multi-instance high availability (three) - Flow Technology Le "

6 many instances, three master node, is three nodes from

surroundings:

  CentOS Linux release 7.5.1804 (Core) 

  ..redis-4.0.11

 

Creating a multi-instance

Step 1: Create multi-instance data directory

root @ the ~] # mkdir / the
[root @ the ~] # cd / the
[root @ the] # mkdir 6379 6380 6381 6382 6383 6384
[root @ the] # ls
6379 6380 6381 6382 6383 6384

 

Step Two: Upload the installation package redis

As used herein, it is redis-4.0.11 version can be downloaded from the official website https://redis.io/ in redis

[root@le ~]# rz

 

The third step: extracting installation package

[Root @ by ~] # cross-xf redis 4.0.11.tar.gz

 

Step four: Copy the configuration file unzip the installation package to the next directory 6379

[Root @ the ~] # cp repeat-4.0.11 / redis.conf / a / 6379 /

 

Fifth step: to move redis extract package under / usr / local / redis

[root@le ~]# mv redis-4.0.11 /usr/local/redis

 

Step Six: compile and install

[root@le ~]# cd /usr/local/redis

[root@le redis]# make && make install

[root@le ~]# ln /usr/local/redis/src/ /bin -s

 

Step Seven: modify the configuration file

 

[root @ Le ~] # grep -E -v "^ # | ^ $" /le/6379/redis.conf
the bind 10.220.5.137 # Bind the local ip address
protected-the MODE yes
Port # 6379 listening port
tcp-backlog 511
timeout 0
tcp-Keepalive 300
daemonize yes # running in the background
Supervised NO
the PidFile /le/6379/redis_6379.pid # PID file location to save
the LogLevel Notice
logfile ""
Databases 16
Always-Show-logo yes
the save 900 1
the save 300 10
the save 60 10000
-Writes-ON-STOP-error bgsave yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir / Le / 6379 / #rdb file location
Slave-serve-STALE the Data yes-
Slave-the Read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
cluster-enabled yes    #开启集群
cluster-config-file nodes-6379.conf  #集群文件名称
cluster-node-timeout 15000           #集群超时时间
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

 

 

Eighth step: copy the modified files above the other below the instance data directory

[root @ the ~] # cp /le/6379/redis.conf / a / 6380 /
[root @ the ~] # cp /le/6379/redis.conf / a / 6381 /
[root @ the ~] # cp /le/6379/redis.conf / a / 6382 /
[root @ the ~] # cp /le/6379/redis.conf / a / 6383 /
[root @ the ~] # cp /le/6379/redis.conf / a / 6384 /

 

Step 9: Modify Profile

Just use sed to be modified

[root @ the ~] # sed -in 's / 6379/6380 / G' /le/6380/redis.conf
[root @ the ~] # sed -in 's / 6379/6381 / g' / a / 6381 /redis.conf
[root @ the ~] # sed -in 's / 6379/6382 / g' /le/6382/redis.conf
[root @ the ~] # sed -in 's / 6379/6383 / g' /le/6383/redis.conf
[root @ the ~] # sed -in 's / 6379/6384 / g' /le/6384/redis.conf

 

Step 10: Start each instance

 

[root@le ~]# redis-server /le/6380/redis.conf
[root@le ~]# redis-server /le/6381/redis.conf
[root@le ~]# redis-server /le/6382/redis.conf
[root@le ~]# redis-server /le/6383/redis.conf
[root@le ~]# redis-server /le/6384/redis.conf
[root@le ~]# ss -tnl
State      Recv-Q Send-Q                   Local Address:Port                                  Peer Address:Port             
LISTEN     0      128                       10.220.5.137:16380                                            *:*                 
LISTEN     0      128                       10.220.5.137:16381                                            *:*                 
LISTEN     0      128                       10.220.5.137:16382                                            *:*                 
LISTEN     0      128                       10.220.5.137:16383                                            *:*                 
LISTEN     0      128                       10.220.5.137:16384                                            *:*                 
LISTEN     0      128                                  *:10050                                            *:*                 
LISTEN     0      128                                  *:10051                                            *:*                 
LISTEN     0      128                       10.220.5.137:6379                                             *:*                 
LISTEN     0      128                       10.220.5.137:6380                                             *:*                 
LISTEN     0      128                       10.220.5.137:6381                                             *:*                 
LISTEN     0      128                       10.220.5.137:6382                                             *:*                 
LISTEN     0      128                       10.220.5.137:6383                                             *:*                 
LISTEN     0      128                                  *:111                                              *:*                 
LISTEN     0      128                       10.220.5.137:6384                                             *:*                 
LISTEN     0      128                                  *:22                                               *:*                 
LISTEN     0      128                       10.220.5.137:16379                                            *:*                 
LISTEN     0      128                                 :::10050                                           :::*                 
LISTEN     0      128                                 :::10051                                           :::*                 
LISTEN     0      70                                  :::3306                                            :::*                 
LISTEN     0      128                                 :::111                                             :::*                 
LISTEN     0      128                                 :::80                                              :::*                 
LISTEN     0      128                                 :::22                                              :::*     

 

 

Installation ruby2.3

Achieve redis cluster functions depend redis-trib.rb, and this tool is dependent on a ruby ​​development kit, so you need to install ruby ​​environment, and install dependencies

 

The first step: Upload extracting installation package

[root@le ~]# rz
[root@le ~]# tar xf ruby-2.3.5.tar.gz

 

Step Two: Compile installation

Recommends that at least one virtual machine memory than G

[root@le ~]# cd ruby-2.3.5/
[root@le ruby-2.3.5]# ./configure --prefix=/usr/local/ruby && make && make install

 

The third step: the installation depends redis-trib.rb

 

[root@le ~]# ln -s /usr/local/ruby/bin/gem /bin
[root@le ~]# gem install -l redis-3.3.0.gem
Successfully installed redis-3.3.0
Parsing documentation for redis-3.3.0
Installing ri documentation for redis-3.3.0
Done installing documentation for redis after 0 seconds
1 gem installed

[root@le ~]# ln -s /usr/local/ruby/bin/ruby  /bin

 

 

Help get Cluster

 Just enter redis-trib.rb press Enter

 

[root@le ~]# redis-trib.rb
Usage: redis-trib <command> <options> <arguments ...>

create          host1:port1 ... hostN:portN
                  --replicas <arg>
  check           host:port
  info            host:port
  fix             host:port
                  --timeout <arg>
  reshard         host:port
                  --from <arg>
                  --to <arg>
                  --slots <arg>
                  --yes
                  --timeout <arg>
                  --pipeline <arg>
  rebalance       host:port
                  --weight <arg>
                  --auto-weights
                  --use-empty-masters
                  --timeout <arg>
                  --simulate
                  --pipeline <arg>
                  --threshold <arg>
  add-node        new_host:new_port existing_host:existing_port
                  --slave
                  --master-id <arg>
  del-node        host:port node_id
  set-timeout     host:port milliseconds
  call            host:port command arg arg .. arg
  import          host:port
                  --from <arg>
                  --copy
                  --replace
  help            (show this help)

For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.

 

 

Creating redis clusters

Meaning command is as follows:

  • To the command given redis-trib.rb program is to create, which means that we want to create a new cluster.
  • Options --replicas 1 that we want to create a node in the cluster from each primary node.
  • Along with other parameters after the address list is an example, we want the program to use these examples the indicated address to create a new cluster.

In simple terms, the meaning of the above command is to make redis-trib program creates a three master node and three nodes from the cluster contains.

Then, redis-trib will print out a configuration envisioned to you, if you think there is no problem, you can enter yes, redis-trib this configuration will be applied to the cluster of them:

 

[root@le ~]# redis-trib.rb create --replicas 1 10.220.5.137:6379 10.220.5.137:6380 10.220.5.137:6381 10.220.5.137:6382 10.220.5.137:6383 10.220.5.137:6384
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
10.220.5.137:6379
10.220.5.137:6380
10.220.5.137:6381
Adding replica 10.220.5.137:6383 to 10.220.5.137:6379
Adding replica 10.220.5.137:6384 to 10.220.5.137:6380
Adding replica 10.220.5.137:6382 to 10.220.5.137:6381
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 57753754f4c89054ab14e8ec517604c4fc4c8ed5 10.220.5.137:6379
   slots:0-5460 (5461 slots) master
M: 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d 10.220.5.137:6380
   slots:5461-10922 (5462 slots) master
M: ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8 10.220.5.137:6381
   slots:10923-16383 (5461 slots) master
S: 1bc40ffc4c54099f8cf47efdeb82a9f42e717bf6 10.220.5.137:6382
   replicates 57753754f4c89054ab14e8ec517604c4fc4c8ed5
S: 640bb3a62565a0bb74980852fee7e8636cf238bc 10.220.5.137:6383
   replicates 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d
S: b8214c9e4b617c7992e71a2fa07a4a64cfeddf58 10.220.5.137:6384
   replicates ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8
Can I set the above configuration? (type 'yes' to accept): yes   #输入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 10.220.5.137:6379)
M: 57753754f4c89054ab14e8ec517604c4fc4c8ed5 10.220.5.137:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8 10.220.5.137:6381
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
M: 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d 10.220.5.137:6380
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 640bb3a62565a0bb74980852fee7e8636cf238bc 10.220.5.137:6383
   slots: (0 slots) slave
   replicates 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d
S: b8214c9e4b617c7992e71a2fa07a4a64cfeddf58 10.220.5.137:6384
   slots: (0 slots) slave
   replicates ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8
S: 1bc40ffc4c54099f8cf47efdeb82a9f42e717bf6 10.220.5.137:6382
   slots: (0 slots) slave
   replicates 57753754f4c89054ab14e8ec517604c4fc4c8ed5
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

 

 

Redis cluster test

Test Redis cluster relatively simple way is to use redis-rb-cluster or redis-cli, next will use redis-cli example to demonstrate:

 

The first step: Sign cluster

Be sure to add -c, behind which the input port can be, this is the area of ​​the center of the ideological redis

[root@le ~]# redis-cli -c -h 10.220.5.137 -p 6379

 

Step 2: Create key

Can be found to create the key is assigned to a different node

 

10.220.5.137:6379> keys *
(empty list or set)
10.220.5.137:6379> set name le
-> Redirected to slot [5798] located at 10.220.5.137:6380
OK
10.220.5.137:6380> set addr jiangsu
-> Redirected to slot [12790] located at 10.220.5.137:6381
OK
10.220.5.137:6381> set tel 123445
-> Redirected to slot [7485] located at 10.220.5.137:6380
OK
10.220.5.137:6380> set ege 25
OK
10.220.5.137:6380> set gender male
-> Redirected to slot [15355] located at 10.220.5.137:6381
OK
10.220.5.137:6381> keys *
1) "addr"
2) "gender"

 

 

The third step: Get the key

Tel no key on this node port 6381, but we can still be used to get tel acquisition value, which achieved a data sharing cluster redis

10.220.5.137:6381> keys *
1) "addr"
2) "gender"
10.220.5.137:6381> get tel
-> Redirected to slot [7485] located at 10.220.5.137:6380
"123445"

 

Add a new node in the cluster

Step 1: Create a new instance

 

[root@le ~]# mkdir /le/6385
[root@le ~]# cp /le/6379/redis.conf /le/6385/
[root@le ~]# sed -i 's/6379/6385/g' /le/6385/redis.conf
[root@le ~]# redis-server /le/6385/redis.conf
10461:C 15 Nov 21:21:11.646 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
10461:C 15 Nov 21:21:11.646 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=10461, just started
10461:C 15 Nov 21:21:11.646 # Configuration loaded

 

 

Step two: add the node to the cluster

Command add-node redis-trib mean that we want to add a node to the cluster which, along with the add-node after the new node is the IP address and port number, and then after that followed an existing cluster, any node IP address and port number, here we are using 10.220.5.137:6379.

 

[root@le ~]# redis-trib.rb add-node 10.220.5.137:6385 10.220.5.137:6379
>>> Adding node 10.220.5.137:6385 to cluster 10.220.5.137:6379
>>> Performing Cluster Check (using node 10.220.5.137:6379)
M: 57753754f4c89054ab14e8ec517604c4fc4c8ed5 10.220.5.137:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8 10.220.5.137:6381
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
M: 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d 10.220.5.137:6380
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: 640bb3a62565a0bb74980852fee7e8636cf238bc 10.220.5.137:6383
   slots: (0 slots) slave
   replicates 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d
S: b8214c9e4b617c7992e71a2fa07a4a64cfeddf58 10.220.5.137:6384
   slots: (0 slots) slave
   replicates ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8
S: 1bc40ffc4c54099f8cf47efdeb82a9f42e717bf6 10.220.5.137:6382
   slots: (0 slots) slave
   replicates 57753754f4c89054ab14e8ec517604c4fc4c8ed5
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 10.220.5.137:6385 to make it join the cluster.
[OK] New node added correctly.

 

 

Step 3: Check

By cluster nodes command, we can confirm that the new node has been added to the cluster 10.220.5.137:6385 inside

 

10.220.5.137:6379> CLUSTER nodes
57753754f4c89054ab14e8ec517604c4fc4c8ed5 10.220.5.137:6379@16379 myself,master - 0 1542288244000 1 connected 0-5460
daf9464ef45d0c73e1ee18f7cc7ddbc7d9719f2d 10.220.5.137:6385@16385 master - 0 1542288242824 0 connected
ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8 10.220.5.137:6381@16381 master - 0 1542288244000 3 connected 10923-16383
3a9aa9592afc594c7e4206cc82ffb37d46a5b23d 10.220.5.137:6380@16380 master - 0 1542288242000 2 connected 5461-10922
640bb3a62565a0bb74980852fee7e8636cf238bc 10.220.5.137:6383@16383 slave 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d 0 1542288242000 5 connected
b8214c9e4b617c7992e71a2fa07a4a64cfeddf58 10.220.5.137:6384@16384 slave ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8 0 1542288244852 6 connected
1bc40ffc4c54099f8cf47efdeb82a9f42e717bf6 10.220.5.137:6382@16382 slave 57753754f4c89054ab14e8ec517604c4fc4c8ed5 0 1542288243844 4 connected

 

 

Step four: the new node is added from the node

 If we intend to become the new node from the node 10.220.5.137:6379, then we just use the client to connect on the new node, and then execute the following command on it

[root@le ~]# redis-cli -c -h 10.220.5.137 -p 6385
10.220.5.137:6385> CLUSTER REPLICATE 57753754f4c89054ab14e8ec517604c4fc4c8ed5
OK

Wherein 57753754f4c89054ab14e8ec517604c4fc4c8ed5 master node id of 10.220.5.137:6379

 

Of redis data do re-slice

 

[root@le ~]# redis-trib.rb reshard 10.220.5.137:6379

 

You only need to specify the address of one of the nodes in the cluster, redis-trib will automatically find other nodes in the cluster.

 

How many slots do you want to move (from 1 to 16384)? 1000

We intend to move the number of slots is set to 1000.

 

What is the receiving node ID? 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d

Set the target node ID is required, rather than the IP address and port. For example, we are going to use the first primary node of the cluster as a target, its IP address and port are 10.220.5.137:6380, and the node ID is 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d, then we should provide the node ID to redis-trib 

 

Source node #1:ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8

Next, redis-trib will ask you to re-slice the source node (source node), i.e., the grooves 1000 from which node hash removed, and moved to the slots above the target node.

 

Source node #2:done

Do you want to proceed with the proposed reshard plan (yes/no)? yes

After entering yes and press Enter to use, redis-trib will perform the re-started slicing the specified hash moving one groove from the source node to the target node above

 

 

Moving slot 12905 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12906 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12907 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12908 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12909 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12910 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12911 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12912 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12913 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12914 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12915 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12916 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12917 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12918 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12919 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12920 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12921 from 10.220.5.137:6381 to 10.220.5.137:6380:
Moving slot 12922 from 10.220.5.137:6381 to 10.220.5.137:6380:

 

After the completion of re-slicing operation is performed, the following command can be used to check whether normal clusters

 

[root@le ~]# redis-trib.rb check 10.220.5.137:6379
>>> Performing Cluster Check (using node 10.220.5.137:6379)
M: 57753754f4c89054ab14e8ec517604c4fc4c8ed5 10.220.5.137:6379
   slots:0-5460 (5461 slots) master
   2 additional replica(s)
S: daf9464ef45d0c73e1ee18f7cc7ddbc7d9719f2d 10.220.5.137:6385
   slots: (0 slots) slave
   replicates 57753754f4c89054ab14e8ec517604c4fc4c8ed5
M: ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8 10.220.5.137:6381
   slots:12923-16383 (3461 slots) master
   1 additional replica(s)
M: 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d 10.220.5.137:6380
   slots:5461-12922 (7462 slots) master
   1 additional replica(s)
S: 640bb3a62565a0bb74980852fee7e8636cf238bc 10.220.5.137:6383
   slots: (0 slots) slave
   replicates 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d
S: b8214c9e4b617c7992e71a2fa07a4a64cfeddf58 10.220.5.137:6384
   slots: (0 slots) slave
   replicates ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8
S: 1bc40ffc4c54099f8cf47efdeb82a9f42e717bf6 10.220.5.137:6382
   slots: (0 slots) slave
   replicates 57753754f4c89054ab14e8ec517604c4fc4c8ed5
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

 

 

Delete Node

If there is slot node, then you need to first perform reshard slot to another node before you can delete operation

1. Remove the empty slot

Delete 10.220.5.137:6385

 

[root@le ~]# redis-trib.rb check 10.220.5.137:6379
>>> Performing Cluster Check (using node 10.220.5.137:6379)
M: 57753754f4c89054ab14e8ec517604c4fc4c8ed5 10.220.5.137:6379
   slots:0-5460 (5461 slots) master
   2 additional replica(s)
S: daf9464ef45d0c73e1ee18f7cc7ddbc7d9719f2d 10.220.5.137:6385
   slots: (0 slots) slave
   replicates 57753754f4c89054ab14e8ec517604c4fc4c8ed5
M: ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8 10.220.5.137:6381
   slots:12923-16383 (3461 slots) master
   1 additional replica(s)
...

 

Run the following command

[root@le ~]# redis-trib.rb del-node 10.220.5.137:6379 daf9464ef45d0c73e1ee18f7cc7ddbc7d9719f2d
>>> Removing node daf9464ef45d0c73e1ee18f7cc7ddbc7d9719f2d from cluster 10.220.5.137:6379
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

View 6385 found node has been removed

 

[root@le ~]# redis-trib.rb check 10.220.5.137:6379
>>> Performing Cluster Check (using node 10.220.5.137:6379)
M: 57753754f4c89054ab14e8ec517604c4fc4c8ed5 10.220.5.137:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8 10.220.5.137:6381
   slots:12923-16383 (3461 slots) master
   1 additional replica(s)
M: 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d 10.220.5.137:6380
   slots:5461-12922 (7462 slots) master
   1 additional replica(s)
S: 640bb3a62565a0bb74980852fee7e8636cf238bc 10.220.5.137:6383
   slots: (0 slots) slave
   replicates 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d
S: b8214c9e4b617c7992e71a2fa07a4a64cfeddf58 10.220.5.137:6384
   slots: (0 slots) slave
   replicates ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8
S: 1bc40ffc4c54099f8cf47efdeb82a9f42e717bf6 10.220.5.137:6382
   slots: (0 slots) slave
   replicates 57753754f4c89054ab14e8ec517604c4fc4c8ed5
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

 

 

2. Delete the node with slot

There are data suggesting an error

[root@le ~]# redis-trib.rb del-node 10.220.5.137:6379 ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8
>>> Removing node ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8 from cluster 10.220.5.137:6379
[ERR] Node 10.220.5.137:6381 is not empty! Reshard data away and try again.

We need to re-slice

 

[root@le ~]# redis-trib.rb reshard 10.220.5.137:6379
>>> Performing Cluster Check (using node 10.220.5.137:6379)
M: 57753754f4c89054ab14e8ec517604c4fc4c8ed5 10.220.5.137:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8 10.220.5.137:6381
   slots:12923-16383 (3461 slots) master
   1 additional replica(s)
M: 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d 10.220.5.137:6380
   slots:5461-12922 (7462 slots) master
   1 additional replica(s)
S: 640bb3a62565a0bb74980852fee7e8636cf238bc 10.220.5.137:6383
   slots: (0 slots) slave
   replicates 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d
S: b8214c9e4b617c7992e71a2fa07a4a64cfeddf58 10.220.5.137:6384
   slots: (0 slots) slave
   replicates ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8
S: 1bc40ffc4c54099f8cf47efdeb82a9f42e717bf6 10.220.5.137:6382
   slots: (0 slots) slave
   replicates 57753754f4c89054ab14e8ec517604c4fc4c8ed5
[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)? 3461
What is the receiving node ID? 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d
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:ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8
Source node #2:done

 

Then check the slot is already empty

 

>>> Performing Cluster Check (using node 10.220.5.137:6379)
M: 57753754f4c89054ab14e8ec517604c4fc4c8ed5 10.220.5.137:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8 10.220.5.137:6381  #已经为空
   slots: (0 slots) master
   0 additional replica(s)
M: 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d 10.220.5.137:6380
   slots:5461-16383 (10923 slots) master
   2 additional replica(s)
S: 640bb3a62565a0bb74980852fee7e8636cf238bc 10.220.5.137:6383
   slots: (0 slots) slave
   replicates 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d
S: b8214c9e4b617c7992e71a2fa07a4a64cfeddf58 10.220.5.137:6384
   slots: (0 slots) slave
   replicates 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d
S: 1bc40ffc4c54099f8cf47efdeb82a9f42e717bf6 10.220.5.137:6382
   slots: (0 slots) slave
   replicates 57753754f4c89054ab14e8ec517604c4fc4c8ed5
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

 

And then delete operation

[root@le ~]# redis-trib.rb del-node 10.220.5.137:6379 ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8
>>> Removing node ffadc66b51b6c87ad3c5a33dc9ec39f984bb80e8 from cluster 10.220.5.137:6379
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

Check again. 6381 node has been deleted

 

[root@le ~]# redis-trib.rb check 10.220.5.137:6379
>>> Performing Cluster Check (using node 10.220.5.137:6379)
M: 57753754f4c89054ab14e8ec517604c4fc4c8ed5 10.220.5.137:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d 10.220.5.137:6380
   slots:5461-16383 (10923 slots) master
   2 additional replica(s)
S: 640bb3a62565a0bb74980852fee7e8636cf238bc 10.220.5.137:6383
   slots: (0 slots) slave
   replicates 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d
S: b8214c9e4b617c7992e71a2fa07a4a64cfeddf58 10.220.5.137:6384
   slots: (0 slots) slave
   replicates 3a9aa9592afc594c7e4206cc82ffb37d46a5b23d
S: 1bc40ffc4c54099f8cf47efdeb82a9f42e717bf6 10.220.5.137:6382
   slots: (0 slots) slave
   replicates 57753754f4c89054ab14e8ec517604c4fc4c8ed5
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/kesz/p/10960657.html