Redis Cluster Configuration and Installation

Introduction to Redis Cluster:

The Redis cluster is a distributed implementation with the following goals, sorted by design importance:
* High performance and linear scalability of up to 1000 nodes.There is no proxy, asynchronous replication is used, and there is no merge when assigning values.
*Acceptable write security: When a client connects to most master nodes, the system strives (in an optimal manner) to maintain write operations from the client.Usually there is a small window in which the confirmed write operation may be lost.When the client is in a small partition, the window loss write operation is greater.
*Availability: Redis clusters support network partitioning - most of the primary nodes are accessible, and each master node that is not accessible corresponds to at least one accessible node.With replica migration, more than one slave master provides a slave to a master that does not.

redis-cluster is divided into master-slave replication, sentry mode
Here we use the master-slave replication mode scheme to install redis three-master-three-slave cluster mode:

Redis Installation Configuration

Redis installation configuration environment (this tutorial uses CentOS 6.9 (final)_x86+Redis-3.2.8)

1) Download (or upload) the installation package (redis-3.2.8)

# cd   /usr/local/src
# wget   http://download.redis.io/releases/redis-3.2.8.tar.gz

2) Decompression

# tar -zxvf  redis-3.2.8.tar.gz
# cd /usr/local/src/redis-3.2.8

3) Download and install packages for compilation

# yum install gcc tcl

4) Installation (use PREFIX to specify installation path)

# make PREFIX=/usr/local/redis-1-M install

5) Start redis, and the following illustration shows that redis is configured correctly (default open port is 6379):

# /usr/local/redis-1-m/bin/redis-server 
5839:C 05 Jul 19:36:59.013 # Warning: no config file specified, using the default config. In order to specify a config file use ./bin/redis-server /path/to/redis.conf
5839:M 05 Jul 19:36:59.014 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.2.8 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 5839
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

5839:M 05 Jul 19:36:59.015 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
5839:M 05 Jul 19:36:59.015 # Server started, Redis version 3.2.8
5839:M 05 Jul 19:36:59.015 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
5839:M 05 Jul 19:36:59.015 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
5839:M 05 Jul 19:36:59.015 * The server is now ready to accept connections on port 6379

Redis cluster installation configuration

You also need to install ruby before installing it to run the official cluster-building tool redis-trib.rb (see the suffix name, you know you can't run it directly!)

1) Toolkit gem for installing Ruby and ruby:

# cp  /usr/local/src/redis-3.2.8/src/redis-trib.rb  /usr/local/redis-1-M/bin/redis-trib
# yum -y install ruby ruby-devel rubygems rpm-build 
# gem install redis 

2) Build clusters
A minimum of three master nodes are required to build a cluster first, and we assign a slave node to each master node.Here we create six redis nodes with the following ip and port numbers:

Cluster Master 1-1 Cluster Master 2-2 Cluster Master 3-Slave 3
172.21.3.105:7000 172.21.3.105:7001 172.21.3.105:7002
172.21.3.105:7003 172.21.3.105:7004 172.21.3.105:7005

ok, once the ports are allocated, we continue to create five cluster configuration directories and copy the redis.conf configuration file to each node configuration directory

# cd /usr/local/src/redis-3.2.8
# mkdir /usr/local/redis-1-M/{conf,data,logs}
# cp redis.conf  /usr/local/redis-1-M/conf/redis-7000.conf
# make PREFIX=/usr/local/redis-1-S install
# mkdir /usr/local/redis-1-S/{conf,data,logs}
# cp redis.conf  /usr/local/redis-1-S/conf/redis-7001.conf
# make PREFIX=/usr/local/redis-2-M install
# mkdir /usr/local/redis-2-M/{conf,data,logs}
# cp redis.conf  /usr/local/redis-2-M/conf/redis-7002.conf
# make PREFIX=/usr/local/redis-2-S install
# mkdir /usr/local/redis-2-S/{conf,data,logs}
# cp redis.conf  /usr/local/redis-2-S/conf/redis-7003.conf
# make PREFIX=/usr/local/redis-3-M install
# mkdir /usr/local/redis-3-M/{conf,data,logs}
# cp redis.conf  /usr/local/redis-3-M/conf/redis-7004.conf
# make PREFIX=/usr/local/redis-3-S install
# mkdir /usr/local/redis-3-S/{conf,data,logs}
# cp redis.conf  /usr/local/redis-3-S/conf/redis-7005.conf

View will show a total of 5 redis directories

# ls /usr/local/
redis-1-M  redis-1-S  redis-2-M  redis-2-S  redis-3-M  redis-3-S 

3) Modify the configuration file in each directory

configuration option Option Value Explain
bind 172.21.3.105 Bind ip for access by other hosts, default to native 127.0.0.1
daemonize yes Whether to run in the background as a daemon
pidfile /var/run/redis-7000.pid If the background process runs, you need to specify a pid, which defaults to/var/run/redis.pid
port 7000 Listening port, default 6379 Note: Cluster communication port value defaults to this port value + 10000, such as 17000
databases 1 Number of databases available, default 16.If there are no special requirements, it is recommended that only one database database 1 be set up
cluster-enabled yes Open redis cluster
cluster-config-file /usr/local/redis-1-M/conf/nodes-7000.conf Cluster profile, start auto-generation, no need to create
cluster-node-timeout 15000 Node interconnection timeout, milliseconds
cluster-migration-barrier 1 The replica critical number for data migration, which indicates that when the number of slave nodes of a primary node is greater than 1, the extra slave nodes will be ceded to the primary node without any slave nodes
cluster-require-full-coverage yes Clusters need to be fully covered, and if some key space s are not covered by the cluster, the cluster will stop writing
appendonly yes Enable aof persistence because redis itself synchronizes data files according to the save criteria above, so some data will only exist in memory for some time.Default value is no
dir /usr/local/redis-1-M/data Node data persistence store directory (recommended configuration)
masterauth password The master auth parameter needs to be configured if the master server has a password set and the cluster passwords need to be consistent
requirepass password To set the requirepass parameter in the server, there is no need to set the master auth parameter from the service

4) Then start six nodes

# /usr/local/redis-1-M/bin/redis-server /usr/local/redis-1-M/conf/redis-7000.conf
# /usr/local/redis-1-S/bin/redis-server /usr/local/redis-1-S/conf/redis-7001.conf
# /usr/local/redis-2-M/bin/redis-server /usr/local/redis-2-M/conf/redis-7002.conf
# /usr/local/redis-2-S/bin/redis-server /usr/local/redis-2-S/conf/redis-7003.conf
# /usr/local/redis-3-M/bin/redis-server /usr/local/redis-3-M/conf/redis-7004.conf
# /usr/local/redis-3-S/bin/redis-server /usr/local/redis-3-S/conf/redis-7005.conf

5) Execute the redis cluster creation command (only once)

# cd /usr/local/redis-1-M/bin/
# ./redis-trib  create --replicas  1 172.21.3.195:7000   172.21.3.195:7001   172.21.3.195:7002  172.21.3.195:7003  172.21.3.195:7004  172.21.3.195:7005

The creation is completed as follows:

>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
172.21.3.195:7000
172.21.3.195:7001
172.21.3.195:7002
Adding replica 172.21.3.195:7003 to 172.21.3.195:7000
Adding replica 172.21.3.195:7004 to 172.21.3.195:7001
Adding replica 172.21.3.195:7005 to 172.21.3.195:7002
M: d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 172.21.3.195:7000
   slots:0-5460 (5461 slots) master
M: 240f431140388ca3bb68b38b219fca48a7434c73 172.21.3.195:7001
   slots:5461-10922 (5462 slots) master
M: c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 172.21.3.195:7002
   slots:10923-16383 (5461 slots) master
S: a8c647829680084f10aa9a6171eb50c7673ce9d2 172.21.3.195:7003
   replicates d60e4770b24cbe08f0bd5812f3089d4b44af0aa3
S: 658055371ba171c249f5ed743bbac67caec95f99 172.21.3.195:7004
   replicates 240f431140388ca3bb68b38b219fca48a7434c73
S: d80c09b437eef4492790f373ed87f3f3233ccd62 172.21.3.195:7005
   replicates c92dd4329e2351fb86553f6fb7b2bd11f338a7f6
Can I set the above configuration? (type 'yes' to accept): yes  #Enter yes after confirmation
>>> 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 172.21.3.195:7000)
M: d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 172.21.3.195:7000
   slots:0-5460 (5461 slots) master      #Notice the slot location for the partition
   1 additional replica(s)
S: d80c09b437eef4492790f373ed87f3f3233ccd62 172.21.3.195:7005
   slots: (0 slots) slave
   replicates c92dd4329e2351fb86553f6fb7b2bd11f338a7f6
M: 240f431140388ca3bb68b38b219fca48a7434c73 172.21.3.195:7001
   slots:5461-10922 (5462 slots) master   #Notice the slot location for the partition
   1 additional replica(s)
S: a8c647829680084f10aa9a6171eb50c7673ce9d2 172.21.3.195:7003
   slots: (0 slots) slave
   replicates d60e4770b24cbe08f0bd5812f3089d4b44af0aa3
S: 658055371ba171c249f5ed743bbac67caec95f99 172.21.3.195:7004
   slots: (0 slots) slave
   replicates 240f431140388ca3bb68b38b219fca48a7434c73
M: c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 172.21.3.195:7002
   slots:10923-16383 (5461 slots) master      #Notice the slot location for the partition
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

Redis cluster simple test

Redis cluster run state simple test

1) Test memory value

Client connection to cluster redis-cli requires -c, redis-cli-c-h IP address-p port number

# /usr/local/redis-1-M/bin/redis-cli -c -h 172.21.3.195 -p 7000
172.21.3.195:7000> set hello world
OK
172.21.3.195:7000> get hello
"world"
172.21.3.195:7000> set zhengyuxiang 111
-> Redirected to slot [6471] located at 172.21.3.195:7001
OK
172.21.3.195:7000> exit

You can see that zhengyuxiang is automatically assigned to the second primary redis service based on the redis-cluster key value assignment.

2) Let's test the value below

# /usr/local/redis-3-S/bin/redis-cli -c -h 172.21.3.195 -p 7005
172.21.3.195:7005> get hello
-> Redirected to slot [866] located at 172.21.3.195:7000
"world"
172.21.3.195:7000> get zhengyuxiang
-> Redirected to slot [6471] located at 172.21.3.195:7001
"111"

Get the value of key hello at redis-cluster primary service one and zhengyuxiang at redis-cluster primary service two, respectively.Explain that our cluster service was successfully set up.

Redis cluster node election and node addition and deletion

Next we will simulate a node crash in the Redis cluster to see if the primary node is hung and will be elected from the node as the primary node

1) Let's first look at the node information of the cluster and see the master-slave relationship table

# /usr/local/redis-1-M/bin/redis-cli -c -h 172.21.3.195 -p 7000
172.21.3.195:7000> cluster nodes
d80c09b437eef4492790f373ed87f3f3233ccd62 172.21.3.195:7005 slave c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 0 1499328639644 6 connected
240f431140388ca3bb68b38b219fca48a7434c73 172.21.3.195:7001 master - 0 1499328642648 2 connected 5461-10922
d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 172.21.3.195:7000 myself,master - 0 0 1 connected 0-5460
a8c647829680084f10aa9a6171eb50c7673ce9d2 172.21.3.195:7003 slave d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 0 1499328640644 4 connected
658055371ba171c249f5ed743bbac67caec95f99 172.21.3.195:7004 slave 240f431140388ca3bb68b38b219fca48a7434c73 0 1499328638642 5 connected
c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 172.21.3.195:7002 master - 0 1499328641646 3 connected 10923-16383

The cluster is shown as three master nodes and three slave nodes.

2) Simulate the node hanging up, and then review the node information again.

#  ps -ef | grep redis
root      7773     1  0 11:32 ?        00:00:07 /usr/local/redis-0/bin/redis-server 172.21.3.195:7000 [cluster]            
root      7777     1  0 11:36 ?        00:00:07 /usr/local/redis-1/bin/redis-server 172.21.3.195:7001 [cluster]            
root      7781     1  0 11:36 ?        00:00:07 /usr/local/redis-2/bin/redis-server 172.21.3.195:7002 [cluster]            
root      7785     1  0 11:36 ?        00:00:07 /usr/local/redis-3/bin/redis-server 172.21.3.195:7003 [cluster]            
root      7789     1  0 11:36 ?        00:00:07 /usr/local/redis-4/bin/redis-server 172.21.3.195:7004 [cluster]            
root      7793     1  0 11:36 ?        00:00:07 /usr/local/redis-5/bin/redis-server 172.21.3.195:7005 [cluster]            
root      7991  7379  0 16:15 pts/1    00:00:00 grep redis
# kill -9  7777 
#  /usr/local/redis-1-M/bin/redis-cli -c -h 172.21.3.195 -p 7000
172.21.3.195:7000> get zhengyuxiang
-> Redirected to slot [6471] located at 172.21.3.195:7004
"111"

Data previously stored in the 7001 master node can also be queried, and the service queried is changed to the 7004 slave service node address of the previous 7001 master service.Let's check the nodes again

# /usr/local/redis-0-M/bin/redis-trib check 172.21.3.195:7000
>>> Performing Cluster Check (using node 172.21.3.195:7000)
M: d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 172.21.3.195:7000
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: d80c09b437eef4492790f373ed87f3f3233ccd62 172.21.3.195:7005
   slots: (0 slots) slave
   replicates c92dd4329e2351fb86553f6fb7b2bd11f338a7f6
S: a8c647829680084f10aa9a6171eb50c7673ce9d2 172.21.3.195:7003
   slots: (0 slots) slave
   replicates d60e4770b24cbe08f0bd5812f3089d4b44af0aa3
M: 658055371ba171c249f5ed743bbac67caec95f99 172.21.3.195:7004
   slots:5461-10922 (5462 slots) master
   0 additional replica(s)
M: c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 172.21.3.195:7002
   slots:10923-16383 (5461 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.

You can see that 7004 has been replaced as the primary node, and the data slot is the data slot of the previous 7001 primary node.

3) After restarting the 7001 service, we can review the redis-cluster information again.

# /usr/local/redis-1-S/bin/redis-server /usr/local/redis-1-S/conf/redis-7001.conf
# /usr/local/redis-1-M/bin/redis-trib check 172.21.3.195:7000
>>> Performing Cluster Check (using node 172.21.3.195:7000)
M: d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 172.21.3.195:7000
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: d80c09b437eef4492790f373ed87f3f3233ccd62 172.21.3.195:7005
   slots: (0 slots) slave
   replicates c92dd4329e2351fb86553f6fb7b2bd11f338a7f6
S: 240f431140388ca3bb68b38b219fca48a7434c73 172.21.3.195:7001
   slots: (0 slots) slave
   replicates 658055371ba171c249f5ed743bbac67caec95f99
S: a8c647829680084f10aa9a6171eb50c7673ce9d2 172.21.3.195:7003
   slots: (0 slots) slave
   replicates d60e4770b24cbe08f0bd5812f3089d4b44af0aa3
M: 658055371ba171c249f5ed743bbac67caec95f99 172.21.3.195:7004
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
M: c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 172.21.3.195:7002
   slots:10923-16383 (5461 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

You can see that 7001 nodes have rejoined the cluster and become service slave nodes for 7004.

4) Addition of Cluster Nodes
There are two scenarios depending on the type of node added:
*When the primary node is added, we need to add an empty node first, and then move some hash slots into the empty node.
*If we add a slave node, we need to set the empty node we create as the slave node of a node in the cluster.

In either case, the first step is to create a new, empty node.We can continue to create a new node with port number 7006 and start it as we did before with 172.21.3.195:7000 and 7001.

# cd /usr/local/src/redis-3.2.8
# make PREFIX=/usr/local/redis-4-R install
# mkdir /usr/local/redis-4-R/{conf,data,logs}
# cp redis.conf  /usr/local/redis-4-R/conf/redis-7006.conf
...  # Modify the configuration file and start
# /usr/local/redis-4-R/bin/redis-server /usr/local/redis-4-R/conf/redis-7006.conf

Startup complete, we add a new node to the cluster

# /usr/local/redis-1-M/bin/redis-trib add-node 172.21.3.195:7006  172.21.3.195:7000

We check the cluster nodes to see if they have been added to the cluster.

# /usr/local/redis-1-M/bin/redis-cli -c -h 172.21.3.195 -p 7000
172.21.3.195:7000> cluster nodes
d80c09b437eef4492790f373ed87f3f3233ccd62 172.21.3.195:7005 slave c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 0 1499412172471 6 connected
240f431140388ca3bb68b38b219fca48a7434c73 172.21.3.195:7001 slave 658055371ba171c249f5ed743bbac67caec95f99 0 1499412176477 7 connected
d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 172.21.3.195:7000 myself,master - 0 0 1 connected 0-5460
a8c647829680084f10aa9a6171eb50c7673ce9d2 172.21.3.195:7003 slave d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 0 1499412171470 4 connected
658055371ba171c249f5ed743bbac67caec95f99 172.21.3.195:7004 master - 0 1499412175475 7 connected 5461-10922
c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 172.21.3.195:7002 master - 0 1499412174473 3 connected 10923-16383
2ee8bf2821ed718a6991bd957c856ddf720b4201 172.21.3.195:7006 master - 0 1499412173472 0 connected

First add the primary node:

# /usr/local/redis-1-M/bin/redis-trib reshard 172.21.3.195:7006
#  /usr/local/redis-1-M/bin/redis-trib reshard 172.21.3.195:7006
>>> Performing Cluster Check (using node 172.21.3.195:7006)
M: 2ee8bf2821ed718a6991bd957c856ddf720b4201 172.21.3.195:7006
   (0 slots) master
   0 additional replica(s)
M: d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 172.21.3.195:7000
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: 658055371ba171c249f5ed743bbac67caec95f99 172.21.3.195:7004
   slots:5461-10922 (5461 slots) master
   1 additional replica(s)
S: 240f431140388ca3bb68b38b219fca48a7434c73 172.21.3.195:7001
   slots: (0 slots) slave
   replicates 658055371ba171c249f5ed743bbac67caec95f99
M: c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 172.21.3.195:7002
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: d80c09b437eef4492790f373ed87f3f3233ccd62 172.21.3.195:7005
   slots: (0 slots) slave
   replicates c92dd4329e2351fb86553f6fb7b2bd11f338a7f6
S: a8c647829680084f10aa9a6171eb50c7673ce9d2 172.21.3.195:7003
   slots: (0 slots) slave
   replicates d60e4770b24cbe08f0bd5812f3089d4b44af0aa3
[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)? 1000
What is the receiving node ID? 2ee8bf2821ed718a6991bd957c856ddf720b4201  #Enter the node ID where the hash slot needs to be added
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:all  #All assigns hash slots in all sources, done assigns hash slots in nodes
...
Do you want to proceed with the proposed reshard plan (yes/no)? yes   # Enter yes after confirmation
...

ok, the added primary node is complete, let's look at the node information below.

# /usr/local/redis-1-M/bin/redis-cli -c -h 172.21.3.195 -p 7000
172.21.3.195:7000> cluster nodes
d80c09b437eef4492790f373ed87f3f3233ccd62 172.21.3.195:7005 slave c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 0 1499414758946 6 connected
240f431140388ca3bb68b38b219fca48a7434c73 172.21.3.195:7001 slave 658055371ba171c249f5ed743bbac67caec95f99 0 1499414755943 7 connected
d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 172.21.3.195:7000 myself,master - 0 0 1 connected 333-5460
a8c647829680084f10aa9a6171eb50c7673ce9d2 172.21.3.195:7003 slave d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 0 1499414757945 4 connected
658055371ba171c249f5ed743bbac67caec95f99 172.21.3.195:7004 master - 0 1499414759948 7 connected 5795-10922
c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 172.21.3.195:7002 master - 0 1499414761951 3 connected 11256-16383
2ee8bf2821ed718a6991bd957c856ddf720b4201 172.21.3.195:7006 master - 0 1499414760950 8 connected 0-332 5461-5794 10923-11255     #Followed by the node hash slot information

Add the slave node again.It is important to note that when a primary node is deleted or changed to a secondary node, the hash slot inside the primary node should be emptied before operation, otherwise an error will occur (emptying the hash slot is to redistribute the hash slot within the node, as detailed in the deletion of the cluster node below).

# /usr/local/redis-0/bin/redis-trib add-node 172.21.3.195:7006 172.21.3.195:7000
# /usr/local/redis-1-M/bin/redis-cli -c -h 172.21.3.195 -p 7006 cluster replicate  d60e4770b24cbe08f0bd5812f3089d4b44af0aa3
OK

View node information

# /usr/local/redis-0/bin/redis-cli -c -h 172.21.3.195 -p 7000
172.21.3.195:7000> cluster nodes
d80c09b437eef4492790f373ed87f3f3233ccd62 172.21.3.195:7005 slave c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 0 1499418168548 6 connected
240f431140388ca3bb68b38b219fca48a7434c73 172.21.3.195:7001 slave 658055371ba171c249f5ed743bbac67caec95f99 0 1499418164538 7 connected
d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 172.21.3.195:7000 myself,master - 0 0 9 connected 0-5794 10923-11255
a8c647829680084f10aa9a6171eb50c7673ce9d2 172.21.3.195:7003 slave d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 0 1499418167546 9 connected
658055371ba171c249f5ed743bbac67caec95f99 172.21.3.195:7004 master - 0 1499418165542 7 connected 5795-10922
c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 172.21.3.195:7002 master - 0 1499418169550 3 connected 11256-16383
bc8c9edfba76cefc1c72c9b8897ec8b1f33848f8 172.21.3.195:7006 slave d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 0 1499418166544 9 connected

The addition of nodes is complete or relatively simple.

5) Delete Cluster Nodes
Before deleting the primary node, the first step is to assign a hash slot in the primary node to another primary node.

# /usr/local/redis-1-M/bin/redis-trib reshard 172.21.3.195:7000
>>> Performing Cluster Check (using node 172.21.3.195:7000)
M: d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 172.21.3.195:7000
   slots:333-5460 (5128 slots) master
   1 additional replica(s)
S: d80c09b437eef4492790f373ed87f3f3233ccd62 172.21.3.195:7005
   slots: (0 slots) slave
   replicates c92dd4329e2351fb86553f6fb7b2bd11f338a7f6
S: 240f431140388ca3bb68b38b219fca48a7434c73 172.21.3.195:7001
   slots: (0 slots) slave
   replicates 658055371ba171c249f5ed743bbac67caec95f99
S: a8c647829680084f10aa9a6171eb50c7673ce9d2 172.21.3.195:7003
   slots: (0 slots) slave
   replicates d60e4770b24cbe08f0bd5812f3089d4b44af0aa3
M: 658055371ba171c249f5ed743bbac67caec95f99 172.21.3.195:7004
   slots:5795-10922 (5128 slots) master
   1 additional replica(s)
M: c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 172.21.3.195:7002
   slots:11256-16383 (5128 slots) master
   1 additional replica(s)
M: 2ee8bf2821ed718a6991bd957c856ddf720b4201 172.21.3.195:7006
   slots:0-332,5461-5794,10923-11255 (1000 slots) master
   0 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)? 1000
What is the receiving node ID? d60e4770b24cbe08f0bd5812f3089d4b44af0aa3
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:2ee8bf2821ed718a6991bd957c856ddf720b4201
Source node #2:done
...
Do you want to proceed with the proposed reshard plan (yes/no)? yes
...

Confirm node information:

#  /usr/local/redis-0/bin/redis-cli -c -h 172.21.3.195 -p 7000
172.21.3.195:7000> cluster nodes
d80c09b437eef4492790f373ed87f3f3233ccd62 172.21.3.195:7005 slave c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 0 1499416523333 6 connected
240f431140388ca3bb68b38b219fca48a7434c73 172.21.3.195:7001 slave 658055371ba171c249f5ed743bbac67caec95f99 0 1499416524835 7 connected
d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 172.21.3.195:7000 myself,master - 0 0 9 connected 0-5794 10923-11255
a8c647829680084f10aa9a6171eb50c7673ce9d2 172.21.3.195:7003 slave d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 0 1499416522331 9 connected
658055371ba171c249f5ed743bbac67caec95f99 172.21.3.195:7004 master - 0 1499416521330 7 connected 5795-10922
c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 172.21.3.195:7002 master - 0 1499416520328 3 connected 11256-16383
2ee8bf2821ed718a6991bd957c856ddf720b4201 172.21.3.195:7006 master - 0 1499416524334 8 connected    #No hash slot information available

Deleting nodes is easy.The empty primary node is deleted as from the node by using the following command.

# /usr/local/redis-1-M/bin/redis-trib del-node  172.21.3.195:7006 2ee8bf2821ed718a6991bd957c856ddf720b4201 #The latter parameter is the id of the node
>>> Removing node 2ee8bf2821ed718a6991bd957c856ddf720b4201 from cluster 172.21.3.195:7006
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

View Confirmation Information

#  /usr/local/redis-1-M/bin/redis-cli -c -h 172.21.3.195 -p 7000
172.21.3.195:7000> cluster nodes
d80c09b437eef4492790f373ed87f3f3233ccd62 172.21.3.195:7005 slave c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 0 1499416718602 6 connected
240f431140388ca3bb68b38b219fca48a7434c73 172.21.3.195:7001 slave 658055371ba171c249f5ed743bbac67caec95f99 0 1499416718102 7 connected
d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 172.21.3.195:7000 myself,master - 0 0 9 connected 0-5794 10923-11255
a8c647829680084f10aa9a6171eb50c7673ce9d2 172.21.3.195:7003 slave d60e4770b24cbe08f0bd5812f3089d4b44af0aa3 0 1499416719603 9 connected
658055371ba171c249f5ed743bbac67caec95f99 172.21.3.195:7004 master - 0 1499416720605 7 connected 5795-10922
c92dd4329e2351fb86553f6fb7b2bd11f338a7f6 172.21.3.195:7002 master - 0 1499416721606 3 connected 11256-16383

The node has been deleted.

Keywords: Redis Ruby yum Database

Added by smilley654 on Sat, 15 Jun 2019 21:12:27 +0300