Establishment of redis cluster + redis replication

Posted by NikLP on Tue, 22 Oct 2019 09:31:21 +0200

Environmental Science

Deployment and construction

192.168.255.250
[root@vt-manager 3010]# grep -vE "^#|^$" redis.conf
bind 192.168.255.250  ##Be sure to write the local ip and use this ip to set up the cluster.
port 3010
daemonize yes  #Daemons mode (background start)
pidfile /etc/redis-cluster/3010/redis_3010.pid  #pid file
logfile "/etc/redis-cluster/3010/redis.log"   #log file
dir "/etc/redis-cluster/3010/data"   #File / data path
appendonly yes  #Enable persistence
cluster-enabled yes    #Start cluster
cluster-config-file nodes-3010.conf   #Node information, automatic generation
cluster-node-timeout 5000   #Timeout in milliseconds
## If you set the password before setting up the cluster, you may not be able to add nodes, so you can set it after the cluster is set up.
# masterauth "1234qwe!@#"  #Host password
# requirepass "1234qwe!@#"  #Access password

The configurations of 255.250:3011, 255.100:3010-3011, and 255.101:3010-3011 are the same, just modify the bind, port and path.

#After writing the configuration file, start six nodes respectively
redis-server   /etc/redis-cluster/3010/redis.conf

Add a master node to the cluster (an additional port is required, here a 6379 port is directly opened on 255.250 to control the addition and deletion of the cluster, etc.)
Add port 3010 of 255.250, 100 and 101 to the cluster as the master
--Cluster replicas means that there is a master and several slave

[root@vt-manager redis-cluster]# redis-cli --cluster  create 192.168.255.250:3010  192.168.255.100:3010  192.168.255.101:3010 --cluster-replicas 0
>>> Performing hash slots allocation on 3 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
M: 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010
   slots:[0-5460] (5461 slots) master
M: 278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010
   slots:[5461-10922] (5462 slots) master
M: 0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010
   slots:[10923-16383] (5461 slots) master
Can I set the above configuration? (type 'yes' to accept): 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 192.168.255.250:3010)
M: 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010
   slots:[0-5460] (5461 slots) master
M: 278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010
   slots:[5461-10922] (5462 slots) master
M: 0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010
   slots:[10923-16383] (5461 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

#Check the cluster status. You can see that there are only three masters without slave. The master has its own uuid. This cluster information will be recorded in the nodes-**.conf file.
[root@vt-manager redis-cluster]# redis-cli  --cluster check 192.168.255.250:3010
192.168.255.250:3010 (75b5a3a5...) -> 0 keys | 5461 slots | 0 slaves.
192.168.255.100:3010 (278944c8...) -> 0 keys | 5462 slots | 0 slaves.
192.168.255.101:3010 (0b7abd55...) -> 0 keys | 5461 slots | 0 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.255.250:3010)
M: 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010
   slots:[0-5460] (5461 slots) master
M: 278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010
   slots:[5461-10922] (5462 slots) master
M: 0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010
   slots:[10923-16383] (5461 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

[root@vt-manager redis-cluster]# redis-cli  --cluster check 192.168.255.100:3010
192.168.255.100:3010 (278944c8...) -> 0 keys | 5462 slots | 0 slaves.
192.168.255.101:3010 (0b7abd55...) -> 0 keys | 5461 slots | 0 slaves.
192.168.255.250:3010 (75b5a3a5...) -> 0 keys | 5461 slots | 0 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.255.100:3010)
M: 278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010
   slots:[5461-10922] (5462 slots) master
M: 0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010
   slots:[10923-16383] (5461 slots) master
M: 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010
   slots:[0-5460] (5461 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

[root@vt-manager redis-cluster]# redis-cli  --cluster check 192.168.255.101:3010
192.168.255.101:3010 (0b7abd55...) -> 0 keys | 5461 slots | 0 slaves.
192.168.255.100:3010 (278944c8...) -> 0 keys | 5462 slots | 0 slaves.
192.168.255.250:3010 (75b5a3a5...) -> 0 keys | 5461 slots | 0 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.255.101:3010)
M: 0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010
   slots:[10923-16383] (5461 slots) master
M: 278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010
   slots:[5461-10922] (5462 slots) master
M: 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010
   slots:[0-5460] (5461 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

Add cluster slave node

Add nodes for the cluster, and add slave nodes for each master (Format: redis cli -- cluster add node slave nodes ip: port control node ip: port (any node in the cluster can) - cluster slave -- cluster master ID master UUID)

[root@vt-manager redis-cluster]# redis-cli  --cluster add-node 192.168.255.100:3011 192.168.255.250:3010 --cluster-slave --cluster-master-id  75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5
>>> Adding node 192.168.255.100:3011 to cluster 192.168.255.250:3010
>>> Performing Cluster Check (using node 192.168.255.250:3010)
M: 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010
   slots:[0-5460] (5461 slots) master
M: 278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010
   slots:[5461-10922] (5462 slots) master
M: 0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010
   slots:[10923-16383] (5461 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.255.100:3011 to make it join the cluster.
Waiting for the cluster to join
>>> Configure node as replica of 192.168.255.250:3010.
[OK] New node added correctly.

[root@vt-manager redis-cluster]# redis-cli  --cluster add-node 192.168.255.101:3011 192.168.255.250:3010 --cluster-slave --cluster-master-id  278944c80cd36651809de466e9e9dd3fc243cc8b
>>> Adding node 192.168.255.101:3011 to cluster 192.168.255.250:3010
>>> Performing Cluster Check (using node 192.168.255.250:3010)
M: 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982 192.168.255.100:3011
   slots: (0 slots) slave
   replicates 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5
M: 278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010
   slots:[5461-10922] (5462 slots) master
M: 0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010
   slots:[10923-16383] (5461 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.255.101:3011 to make it join the cluster.
Waiting for the cluster to join
>>> Configure node as replica of 192.168.255.100:3010.
[OK] New node added correctly.

[root@vt-manager redis-cluster]# redis-cli  --cluster add-node 192.168.255.250:3011 192.168.255.250:3010 --cluster-slave --cluster-master-id 0b7abd55faf62a007468eccc9a0fa30354df5adf
>>> Adding node 192.168.255.250:3011 to cluster 192.168.255.250:3010
>>> Performing Cluster Check (using node 192.168.255.250:3010)
M: 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: adf58df6918571490eb51a0ea3a52df6812419fc 192.168.255.101:3011
   slots: (0 slots) slave
   replicates 278944c80cd36651809de466e9e9dd3fc243cc8b
M: 0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010
   slots:[10923-16383] (5461 slots) master
M: 278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982 192.168.255.100:3011
   slots: (0 slots) slave
   replicates 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.255.250:3011 to make it join the cluster.
Waiting for the cluster to join
>>> Configure node as replica of 192.168.255.101:3010.
[OK] New node added correctly.

[root@vt-manager redis-cluster]# redis-cli  --cluster check 192.168.255.250:3010
192.168.255.250:3010 (75b5a3a5...) -> 0 keys | 5461 slots | 1 slaves.
192.168.255.101:3010 (0b7abd55...) -> 0 keys | 5461 slots | 1 slaves.
192.168.255.100:3010 (278944c8...) -> 0 keys | 5462 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.255.250:3010)
M: 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 143ccae6e432af1c530e2a7d6fbfc2320e735316 192.168.255.250:3011
   slots: (0 slots) slave
   replicates 0b7abd55faf62a007468eccc9a0fa30354df5adf
S: adf58df6918571490eb51a0ea3a52df6812419fc 192.168.255.101:3011
   slots: (0 slots) slave
   replicates 278944c80cd36651809de466e9e9dd3fc243cc8b
M: 0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: 278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982 192.168.255.100:3011
   slots: (0 slots) slave
   replicates 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

View node status

192.168.255.250:3010> cluster nodes
143ccae6e432af1c530e2a7d6fbfc2320e735316 192.168.255.250:3011@13011 slave 0b7abd55faf62a007468eccc9a0fa30354df5adf 0 1564373272729 3 connected
75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010@13010 myself,master - 0 1564373268000 1 connected 0-5460
adf58df6918571490eb51a0ea3a52df6812419fc 192.168.255.101:3011@13011 slave 278944c80cd36651809de466e9e9dd3fc243cc8b 0 1564373273234 2 connected
0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010@13010 master - 0 1564373272228 3 connected 10923-16383
278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010@13010 master - 0 1564373272000 2 connected 5461-10922
5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982 192.168.255.100:3011@13011 slave 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 0 1564373271718 1 connected
192.168.255.250:3010> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:5
cluster_my_epoch:4
cluster_stats_messages_ping_sent:15951
cluster_stats_messages_pong_sent:14146
cluster_stats_messages_sent:30097
cluster_stats_messages_ping_received:14146
cluster_stats_messages_pong_received:14929
cluster_stats_messages_fail_received:2
cluster_stats_messages_auth-req_received:1
cluster_stats_messages_received:29078

Set cluster nodes password (each node needs to be set)

192.168.255.250:3010> config set masterauth 1234qwe!@#
OK
192.168.255.250:3010> config set requirepass 1234qwe!@#
OK
192.168.255.250:3010> auth 1234qwe!@#
OK
192.168.255.250:3010> config rewrite
OK

Expand cluster node

[root@vt-manager app]# redis-cli --cluster add-node 192.168.255.253:3010  192.168.255.250:3010  -a 1234qwe!@#   #In this case, the node is added to the cluster, but the slot is not allocated, so this node does not really start to share the cluster work.
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 192.168.255.253:3010 to cluster 192.168.255.250:3010
>>> Performing Cluster Check (using node 192.168.255.250:3010)
S: 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010
   slots: (0 slots) slave
   replicates 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982
S: 278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010
   slots: (0 slots) slave
   replicates adf58df6918571490eb51a0ea3a52df6812419fc
M: adf58df6918571490eb51a0ea3a52df6812419fc 192.168.255.101:3011
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982 192.168.255.100:3011
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 143ccae6e432af1c530e2a7d6fbfc2320e735316 192.168.255.250:3011
   slots: (0 slots) slave
   replicates 0b7abd55faf62a007468eccc9a0fa30354df5adf
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.255.253:3010 to make it join the cluster.
[OK] New node added correctly.

[root@vt-manager app]# redis-cli  --cluster check 192.168.255.250:3010 -a 1234qwe!@#
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.255.101:3011 (adf58df6...) -> 4 keys | 5462 slots | 1 slaves.
192.168.255.253:3010 (d700cfa9...) -> 0 keys | 0 slots | 0 slaves.
192.168.255.101:3010 (0b7abd55...) -> 4 keys | 5461 slots | 1 slaves.
192.168.255.100:3011 (5c4ac88c...) -> 4 keys | 5461 slots | 1 slaves.
[OK] 12 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.255.250:3010)
S: 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010
   slots: (0 slots) slave
   replicates 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982
S: 278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010
   slots: (0 slots) slave
   replicates adf58df6918571490eb51a0ea3a52df6812419fc
M: adf58df6918571490eb51a0ea3a52df6812419fc 192.168.255.101:3011
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: d700cfa9b25a44cee8805783cf9548ce525b337a 192.168.255.253:3010
   slots: (0 slots) master
M: 0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982 192.168.255.100:3011
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 143ccae6e432af1c530e2a7d6fbfc2320e735316 192.168.255.250:3011
   slots: (0 slots) slave
   replicates 0b7abd55faf62a007468eccc9a0fa30354df5adf
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

Allocate slot s for new nodes to share the work of the cluster

--Cluster from: indicates the node ID of the node where the slot is currently located. Multiple IDs are separated by commas
--Cluster to: indicates the node ID of the node to be newly allocated (it seems that only one node can be allocated at a time)
--Cluster slots: number of slots allocated

[root@vt-manager app]# redis-cli --cluster reshard 192.168.255.253:3010 --cluster-from  5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982,adf58df6918571490eb51a0ea3a52df6812419fc,0b7abd55faf62a007468eccc9a0fa30354df5adf --cluster-to d700cfa9b25a44cee8805783cf9548ce525b337a --cluster-slots 5461 -a 1234qwe!@#
[root@vt-manager app]# redis-cli  --cluster check 192.168.255.250:3010 -a 1234qwe!@#
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.255.101:3011 (adf58df6...) -> 3 keys | 3641 slots | 1 slaves.
192.168.255.253:3010 (d700cfa9...) -> 3 keys | 5461 slots | 0 slaves.
192.168.255.101:3010 (0b7abd55...) -> 4 keys | 3641 slots | 1 slaves.
192.168.255.100:3011 (5c4ac88c...) -> 2 keys | 3641 slots | 1 slaves.
[OK] 12 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.255.250:3010)
S: 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010
   slots: (0 slots) slave
   replicates 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982
S: 278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010
   slots: (0 slots) slave
   replicates adf58df6918571490eb51a0ea3a52df6812419fc
M: adf58df6918571490eb51a0ea3a52df6812419fc 192.168.255.101:3011
   slots:[7282-10922] (3641 slots) master
   1 additional replica(s)
M: d700cfa9b25a44cee8805783cf9548ce525b337a 192.168.255.253:3010
   slots:[0-1819],[5461-7281],[10923-12742] (5461 slots) master
M: 0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010
   slots:[12743-16383] (3641 slots) master
   1 additional replica(s)
M: 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982 192.168.255.100:3011
   slots:[1820-5460] (3641 slots) master
   1 additional replica(s)
S: 143ccae6e432af1c530e2a7d6fbfc2320e735316 192.168.255.250:3011
   slots: (0 slots) slave
   replicates 0b7abd55faf62a007468eccc9a0fa30354df5adf
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

Add slave node for 255.253:3010

(at present, there are 4 master s and 3 slave s, so the architecture diagram needs to be adjusted. The original 255.101:3010 - > 255.250:3011 should be adjusted to 255.101:3010 - > 255.253:3011. The original 255.250:3011 should be used as 255.253:3010 - > 255.250:3011)
Add node: the following is the master corresponding to the newly added slave and slave respectively
Cluster Slave: indicates that the slave node is joined
--Cluster master ID: indicates the node ID of the master corresponding to the slave.

[root@vt-manager app]# redis-cli  --cluster check 192.168.255.250:3010 -a 1234qwe!@#
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.255.101:3011 (adf58df6...) -> 3 keys | 3641 slots | 1 slaves.
192.168.255.253:3010 (d700cfa9...) -> 3 keys | 5461 slots | 0 slaves.
192.168.255.101:3010 (0b7abd55...) -> 4 keys | 3641 slots | 1 slaves.
192.168.255.100:3011 (5c4ac88c...) -> 2 keys | 3641 slots | 1 slaves.
[OK] 12 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.255.250:3010)
S: 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010
   slots: (0 slots) slave
   replicates 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982
S: 278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010
   slots: (0 slots) slave
   replicates adf58df6918571490eb51a0ea3a52df6812419fc
M: adf58df6918571490eb51a0ea3a52df6812419fc 192.168.255.101:3011
   slots:[7282-10922] (3641 slots) master
   1 additional replica(s)
M: d700cfa9b25a44cee8805783cf9548ce525b337a 192.168.255.253:3010
   slots:[0-1819],[5461-7281],[10923-12742] (5461 slots) master
M: 0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010
   slots:[12743-16383] (3641 slots) master
   1 additional replica(s)
M: 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982 192.168.255.100:3011
   slots:[1820-5460] (3641 slots) master
   1 additional replica(s)
S: 143ccae6e432af1c530e2a7d6fbfc2320e735316 192.168.255.250:3011
   slots: (0 slots) slave
   replicates 0b7abd55faf62a007468eccc9a0fa30354df5adf
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

[root@vt-manager app]# redis-cli --cluster del-node 192.168.255.250:3011 143ccae6e432af1c530e2a7d6fbfc2320e735316 -a 1234qwe!@#
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Removing node 143ccae6e432af1c530e2a7d6fbfc2320e735316 from cluster 192.168.255.250:3011
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

[root@vt-manager app]# redis-cli --cluster add-node 192.168.255.253:3011  192.168.255.250:3010 --cluster-slave --cluster-master-id  0b7abd55faf62a007468eccc9a0fa30354df5adf  -a 1234qwe!@#
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 192.168.255.253:3011 to cluster 192.168.255.250:3010
>>> Performing Cluster Check (using node 192.168.255.250:3010)
S: 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010
   slots: (0 slots) slave
   replicates 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982
S: 278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010
   slots: (0 slots) slave
   replicates adf58df6918571490eb51a0ea3a52df6812419fc
M: adf58df6918571490eb51a0ea3a52df6812419fc 192.168.255.101:3011
   slots:[7282-10922] (3641 slots) master
   1 additional replica(s)
M: d700cfa9b25a44cee8805783cf9548ce525b337a 192.168.255.253:3010
   slots:[0-1819],[5461-7281],[10923-12742] (5461 slots) master
M: 0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010
   slots:[12743-16383] (3641 slots) master
M: 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982 192.168.255.100:3011
   slots:[1820-5460] (3641 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 192.168.255.253:3011 to make it join the cluster.
Waiting for the cluster to join
>>> Configure node as replica of 192.168.255.101:3010.
[OK] New node added correctly.

//Because 255.250:3011 was originally used as a slave, there will be cluster node information and data in it, so you need to delete the original data to be normal;
=======================================================================================
[root@vt-manager app]# rm -rf  /etc/redis-cluster/3011/data/*
[root@vt-manager app]# redis-server   /etc/redis-cluster/3011/redis.conf
[root@vt-manager app]# redis-cli --cluster add-node 192.168.255.250:3011  192.168.255.250:3010 --cluster-slave --cluster-master-id  d700cfa9b25a44cee8805783cf9548ce525b337a  -a 1234qwe!@#
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 192.168.255.250:3011 to cluster 192.168.255.250:3010
>>> Performing Cluster Check (using node 192.168.255.250:3010)
S: 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010
   slots: (0 slots) slave
   replicates 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982
S: 278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010
   slots: (0 slots) slave
   replicates adf58df6918571490eb51a0ea3a52df6812419fc
M: adf58df6918571490eb51a0ea3a52df6812419fc 192.168.255.101:3011
   slots:[7282-10922] (3641 slots) master
   1 additional replica(s)
M: d700cfa9b25a44cee8805783cf9548ce525b337a 192.168.255.253:3010
   slots:[0-1819],[5461-7281],[10923-12742] (5461 slots) master
M: 0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010
   slots:[12743-16383] (3641 slots) master
   1 additional replica(s)
M: 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982 192.168.255.100:3011
   slots:[1820-5460] (3641 slots) master
   1 additional replica(s)
S: 8f33ed15a736bb86c11f16294b68241d848073ca 192.168.255.253:3011
   slots: (0 slots) slave
   replicates 0b7abd55faf62a007468eccc9a0fa30354df5adf
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.255.250:3011 to make it join the cluster.
Waiting for the cluster to join
>>> Configure node as replica of 192.168.255.253:3010.
[OK] New node added correctly.
========================================================================

[root@vt-manager app]# redis-cli  --cluster check 192.168.255.250:3010 -a 1234qwe!@#
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.255.101:3011 (adf58df6...) -> 3 keys | 3641 slots | 1 slaves.
192.168.255.253:3010 (d700cfa9...) -> 3 keys | 5461 slots | 1 slaves.
192.168.255.101:3010 (0b7abd55...) -> 4 keys | 3641 slots | 1 slaves.
192.168.255.100:3011 (5c4ac88c...) -> 2 keys | 3641 slots | 1 slaves.
[OK] 12 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.255.250:3010)
S: 75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010
   slots: (0 slots) slave
   replicates 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982
S: 278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010
   slots: (0 slots) slave
   replicates adf58df6918571490eb51a0ea3a52df6812419fc
M: adf58df6918571490eb51a0ea3a52df6812419fc 192.168.255.101:3011
   slots:[7282-10922] (3641 slots) master
   1 additional replica(s)
S: d3c105351fffd4419bc5101819699af984f3a83b 192.168.255.250:3011
   slots: (0 slots) slave
   replicates d700cfa9b25a44cee8805783cf9548ce525b337a
M: d700cfa9b25a44cee8805783cf9548ce525b337a 192.168.255.253:3010
   slots:[0-1819],[5461-7281],[10923-12742] (5461 slots) master
   1 additional replica(s)
M: 0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010
   slots:[12743-16383] (3641 slots) master
   1 additional replica(s)
M: 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982 192.168.255.100:3011
   slots:[1820-5460] (3641 slots) master
   1 additional replica(s)
S: 8f33ed15a736bb86c11f16294b68241d848073ca 192.168.255.253:3011
   slots: (0 slots) slave
   replicates 0b7abd55faf62a007468eccc9a0fa30354df5adf
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

[root@vt-manager app]# redis-cli  -c -h 192.168.255.250 -p 3010   -a 1234qwe!@#   cluster nodes
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
278944c80cd36651809de466e9e9dd3fc243cc8b 192.168.255.100:3010@13010 slave adf58df6918571490eb51a0ea3a52df6812419fc 0 1564386981109 5 connected
adf58df6918571490eb51a0ea3a52df6812419fc 192.168.255.101:3011@13011 master - 0 1564386982116 5 connected 7282-10922
d3c105351fffd4419bc5101819699af984f3a83b 192.168.255.250:3011@13011 slave d700cfa9b25a44cee8805783cf9548ce525b337a 0 1564386980100 6 connected
d700cfa9b25a44cee8805783cf9548ce525b337a 192.168.255.253:3010@13010 master - 0 1564386980101 6 connected 0-1819 5461-7281 10923-12742
0b7abd55faf62a007468eccc9a0fa30354df5adf 192.168.255.101:3010@13010 master - 0 1564386981611 3 connected 12743-16383
75b5a3a58ad4c8c668ad2905cec76612f1eeb4e5 192.168.255.250:3010@13010 myself,slave 5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982 0 1564386977000 1 connected
5c4ac88c46b805ae6e51ac23ec5b2eb89c43d982 192.168.255.100:3011@13011 master - 0 1564386981611 4 connected 1820-5460
8f33ed15a736bb86c11f16294b68241d848073ca 192.168.255.253:3011@13011 slave 0b7abd55faf62a007468eccc9a0fa30354df5adf 0 1564386980101 3 connected

Redis common configuration

Shrinking cluster

Offline node 127.0.0.1:6385 (master) / 127.0.0.1:6386 (slave)
(1) first delete the slave corresponding to the master
redis-cli --cluster del-node 127.0.0.1:6386 530cf27337c1141ed12268f55ba06c15ca8494fc
 Del node is followed by the ip:port and node ID of the slave node.
(2) clear the master's slot
redis-cli --cluster reshard 127.0.0.1:6385 --cluster-from 46f0b68b3f605b3369d3843a89a2b4a164ed21e8 --cluster-to 2846540d8284538096f111a8ce7cf01c50199237 --cluster-slots 1024 --cluster-yes
 The reshard subcommand has been described previously. One thing to note here is that since our cluster has four primary nodes in total, and each time we can only write one destination node, the above command needs to be executed three times (- cluster to corresponds to different destination nodes).
--Cluster yes: the slot to be migrated will not be displayed, but will be migrated directly.
(3) offline (delete) node
redis-cli --cluster del-node 127.0.0.1:6385 46f0b68b3f605b3369d3843a89a2b4a164ed21e8

redis joins systemctl to start.

(1) first, you need to

daemonize yes
 Modified to
daemonize no

(2) create startup script

vim /lib/systemd/system/redis.service
//Enter the following in redis.service
[Unit]
Description=The redis-server Process Manager
After=syslog.target network.target
[Service]
#Type=forking
PIDFile=/var/run/redis.pid
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf  #Specify the running program and redis configuration file
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
#Reload systemd
systemctl daemon-reload
#Start redis
systemctl start redis
#chkconfig mysqld on 
systemctl enable redis
#View redis status
systemctl status redis
#Stop redis
systemctl stop redis

Delete method after node adding error

redis-cli  --cluster del-node  slave-node:port  slave-uuid
redis-cli --cluster del-node 192.168.255.100:3011  011367d777d2ef363f8a15689efa9df4b0bed8b8
 In addition to deleting here, you also need to delete the values in nodes-xx.conf. The most direct way is to delete this file, in order to generate a new file after restarting the node.
If not deleted, 100:3011 cannot be added again (due to key value conflict)

Topics: Operation & Maintenance Redis vim network