Redis 5 - new cluster installation mode - redis cli - Cluster Create

Keywords: Programming Redis firewall CentOS network

outline

For the principle of cluster, please refer to Redis design and Implementation - working principle of cluster , I won't go into details here. I introduced how to use redis trib toolset to install cluster a long time ago How to build and use Redis cluster In the past two days, I read the official documents and found a new way of installation and deployment, which was recorded by blog

Preparation

Three virtual machines are prepared with IP addresses as follows:

192.168.10.23
192.168.10.24
192.168.10.25

Each machine starts three RedisServer instances with ports of 7001 to 7009. Modify the redis.conf configuration file of each instance according to the following configuration

#port
port 7001
#Enable cluster function
cluster-enabled yes
#The name of the cluster node configuration file, which is not written manually and is automatically generated and modified by the program
cluster-config-file cluster-nodes-7001.conf
#Cluster node timeout, used with cluster replica validity factor
cluster-node-timeout 1000
#The number of times cluster node timeout is detected to be unavailable. If cluster node timeout is set to 1000ms and cluster replica validity factor is set to 5, then cluster nodes between 1000 * 5 will be marked as suspected offline if they are not available
cluster-replica-validity-factor 5
#Minimum number of slave nodes under master node
cluster-migration-barrier 1
#yes requires all primary nodes to work normally, and all hash slots are assigned to the working primary node, so that the cluster can provide services. If you want some hash slots to respond to the request, set to no
cluster-require-full-coverage yes
#yes, when the master node is hung up, the slave node cannot run for the master node
cluster-replica-no-failover no
#Enable AOF persistence
appendonly yes
#Set RDB and AOF file directories
dir /home/acct/data/redis/dbfile

Remember to create the directory / home/acct/data/redis/dbfile and / home/acct/data/redis/config on the host. The former stores the persistent file and the latter stores redis.conf

Upload the configuration file to the directory of each host

Boot instance

Start the corresponding redis server on three machines

redis-server /home/acct/data/redis/config/redis-7001.conf
redis-server /home/acct/data/redis/config/redis-7002.conf
redis-server /home/acct/data/redis/config/redis-7003.conf

redis-server /home/acct/data/redis/config/redis-7004.conf
redis-server /home/acct/data/redis/config/redis-7005.conf
redis-server /home/acct/data/redis/config/redis-7006.conf

redis-server /home/acct/data/redis/config/redis-7007.conf
redis-server /home/acct/data/redis/config/redis-7008.conf
redis-server /home/acct/data/redis/config/redis-7009.conf

You can use ps -ef|grep redis to start

Configuration cluster

To do this, you must configure the firewall policy or close the firewall and open the port. The Redis cluster requires two ports, one of which is redis.conf.port plus 10000. For example, if the port is 7001, it also needs a 17001 port. According to your firewall security level, you may need to list many items, which will not be given here

On my own virtual machine, I shut down the firewall directly and violently.

centos7.x: systemctl stop firewalld.service

 

Note: the production environment must be clearly communicated with the network administrator before making a decision. Do not apply for opening or close the firewall rashly

One command configuration cluster

Redis cli -- cluster command provided by Redis 5 can automatically solve the problem of cluster building at one time, and even give you an average score of hash slots, as long as you click yes

redis-cli --cluster create \
192.168.10.23:7001 \
192.168.10.23:7002 \
192.168.10.23:7003 \
192.168.10.24:7004 \
192.168.10.24:7005 \
192.168.10.24:7006 \
192.168.10.25:7007 \
192.168.10.25:7008 \
192.168.10.25:7009 \
--cluster-replicas 2

The implementation effect is as follows

[acct@centos-template /home/acct/data/redis]$ redis-cli --cluster create 192.168.10.23:7001 192.168.10.23:7002 192.168.10.23:7003 192.168.10.24:7004 192.168.10.24:7005 192.168.10.24:7006 192.168.10.25:7007 192.168.10.25:7008 192.168.10.25:7009 --cluster-replicas 2
>>> Performing hash slots allocation on 9 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.10.24:7005 to 192.168.10.23:7001
Adding replica 192.168.10.25:7008 to 192.168.10.23:7001
Adding replica 192.168.10.23:7002 to 192.168.10.24:7004
Adding replica 192.168.10.23:7003 to 192.168.10.24:7004
Adding replica 192.168.10.24:7006 to 192.168.10.25:7007
Adding replica 192.168.10.25:7009 to 192.168.10.25:7007
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves of the same master are in the same host
M: e730a96a3a6985594af909291a804cca2c0953b6 192.168.10.23:7001
   slots:[0-5460] (5461 slots) master
S: b80e23c0a80fe54ffaf934e1bb9a6c5927fdafe5 192.168.10.23:7002
   replicates 5113f201c95db8e342b954e72da89ceadbdf7d4f
S: a4b0199cf8a95e3cfe239db38c0ca20cb0636bfe 192.168.10.23:7003
   replicates 5113f201c95db8e342b954e72da89ceadbdf7d4f
M: 5113f201c95db8e342b954e72da89ceadbdf7d4f 192.168.10.24:7004
   slots:[5461-10922] (5462 slots) master
S: 3b4cce96f5412c0b6a9e304e326e11df7b7e8e36 192.168.10.24:7005
   replicates 74c3c0f445317d40cdead5305139be6693dcc83d
S: b8d787d6eca1a139d493e69489fa9c8224bbcbca 192.168.10.24:7006
   replicates 74c3c0f445317d40cdead5305139be6693dcc83d
M: 74c3c0f445317d40cdead5305139be6693dcc83d 192.168.10.25:7007
   slots:[10923-16383] (5461 slots) master
S: 9c73b7b1e09f04ccad6f3c09ac8030bd46143a22 192.168.10.25:7008
   replicates e730a96a3a6985594af909291a804cca2c0953b6
S: b10aa1db953e489173bb4af124a0d6beebfb86e8 192.168.10.25:7009
   replicates e730a96a3a6985594af909291a804cca2c0953b6
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.10.23:7001)
M: e730a96a3a6985594af909291a804cca2c0953b6 192.168.10.23:7001
   slots:[0-5460] (5461 slots) master
   2 additional replica(s)
S: b10aa1db953e489173bb4af124a0d6beebfb86e8 192.168.10.25:7009
   slots: (0 slots) slave
   replicates e730a96a3a6985594af909291a804cca2c0953b6
S: 9c73b7b1e09f04ccad6f3c09ac8030bd46143a22 192.168.10.25:7008
   slots: (0 slots) slave
   replicates e730a96a3a6985594af909291a804cca2c0953b6
S: 3b4cce96f5412c0b6a9e304e326e11df7b7e8e36 192.168.10.24:7005
   slots: (0 slots) slave
   replicates 74c3c0f445317d40cdead5305139be6693dcc83d
S: b8d787d6eca1a139d493e69489fa9c8224bbcbca 192.168.10.24:7006
   slots: (0 slots) slave
   replicates 74c3c0f445317d40cdead5305139be6693dcc83d
S: a4b0199cf8a95e3cfe239db38c0ca20cb0636bfe 192.168.10.23:7003
   slots: (0 slots) slave
   replicates 5113f201c95db8e342b954e72da89ceadbdf7d4f
S: b80e23c0a80fe54ffaf934e1bb9a6c5927fdafe5 192.168.10.23:7002
   slots: (0 slots) slave
   replicates 5113f201c95db8e342b954e72da89ceadbdf7d4f
M: 5113f201c95db8e342b954e72da89ceadbdf7d4f 192.168.10.24:7004
   slots:[5461-10922] (5462 slots) master
   2 additional replica(s)
M: 74c3c0f445317d40cdead5305139be6693dcc83d 192.168.10.25:7007
   slots:[10923-16383] (5461 slots) master
   2 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

View cluster status

[acct@centos-template /home/acct/data/redis]$ redis-cli -c -p 7001 cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:9
cluster_size:3
cluster_current_epoch:9
cluster_my_epoch:1
cluster_stats_messages_ping_sent:119
cluster_stats_messages_pong_sent:114
cluster_stats_messages_sent:233
cluster_stats_messages_ping_received:106
cluster_stats_messages_pong_received:119
cluster_stats_messages_meet_received:8
cluster_stats_messages_received:233

test

[acct@centos-template /home/acct/data/redis]$ redis-cli -c -p 7001
127.0.0.1:7001> set username Messi
-> Redirected to slot [14315] located at 192.168.10.25:7007
OK
192.168.10.25:7007> 

For more cluster later maintenance commands, please refer to the official Redis document https://redis.io/commands#cluster See.

Posted by Dillinger on Fri, 17 Jan 2020 03:15:30 -0800