redis-cli --cluste cluster management

There is no redis-trib.rb in the default epel repository of centos, and redis-cli --cluster has been used since redis5.0 to manage the cluster.

1) Unzip redis6.0

[root@ydong ~]# tar xf redis-6.0.6.tar.gz 

2) Install the compilation environment, and install all development tools and server platform development directly here. In fact, there is no need to install so many, just install gcc and gcc++

yum groupinstall -y "Develo+pment Tools" "Server Platform Development"

3) After the installation, the default version is 版本 :4.8.5, and the higher version of redis requires a higher version of gcc, so you have to continue to upgrade the gcc version

yum install centos-release-scl

yum install devtoolset-7-gcc*

scl enable devtoolset-7 bash

4) Compile redis

cd /usr/local/src/redis-6.0.6/
make

5) Add the command to the environment variable

[root@ydong src]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/src/redis/src

6) Start the service, use redis-server /PATH/CONFIG_FILEredis.conf by default

redis-server

7) Here redis-cli --cluster is used to create a cluster, first modify the redis.conf file. 3 master 3 slave

 bind 0.0.0.0
 cluster-enabled yes
 cluster-config-file nodes-6379.conf
 cluster-node-timeout 15000
 cluster-replica-validity-factor 10
 cluster-migration-barrier 1
 cluster-require-full-coverage yes

8) Create folders 7001, 7002, 7003, 7004, 7005, and put redis.conf in each folder. Modify the port inside to have the same name as the file.

[root@ydong ~]# ss -tnl | grep "700"
LISTEN     0      128          *:17001                    *:*                  
LISTEN     0      128          *:17002                    *:*                  
LISTEN     0      128          *:17003                    *:*                  
LISTEN     0      128          *:17004                    *:*                  
LISTEN     0      128          *:17005                    *:*                  
LISTEN     0      128          *:7001                     *:*                  
LISTEN     0      128          *:7002                     *:*                  
LISTEN     0      128          *:7003                     *:*                  
LISTEN     0      128          *:7004                     *:*                  
LISTEN     0      128          *:7005                     *:*         

9) Use redis-cli --cluster to create a cluster

[root@ydong ~]# redis-cli --cluster create --cluster-replicas 1 192.168.199.157:6379  192.168.199.157:7004 192.168.199.157:7001 192.168.199.157:7002 192.168.199.157:7003 192.168.199.157:7005
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.199.157:7003 to 192.168.199.157:6379
Adding replica 192.168.199.157:7005 to 192.168.199.157:7004
Adding replica 192.168.199.157:7002 to 192.168.199.157:7001
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: e2c9b8c3c985fcbdb1eb6815fbbe8cbf4df819a3 192.168.199.157:6379
   slots:[0-5460] (5461 slots) master
M: 3e645db2a11f848d0f727549053f49f77004ed9d 192.168.199.157:7004
   slots:[5461-10922] (5462 slots) master
M: 0f2f36eba63aaf62ab07abbb7e38c1d54405b08f 192.168.199.157:7001
   slots:[10923-16383] (5461 slots) master
S: adf47225a89a1dcb669be2b0b6904ab1a49ee8ab 192.168.199.157:7002
   replicates e2c9b8c3c985fcbdb1eb6815fbbe8cbf4df819a3
S: 990ba160bf0f2c22b41bffe65f2d14eb3361049e 192.168.199.157:7003
   replicates 3e645db2a11f848d0f727549053f49f77004ed9d
S: 778506f84ceedc9873b83536d2094b40a2380c9a 192.168.199.157:7005
   replicates 0f2f36eba63aaf62ab07abbb7e38c1d54405b08f
Can I set the above configuration? (type 'yes' to accept): yes

#自动创建集群,并平均分配slots  replicas 1表示为希望给每一个主节点配置一个从节点。

10) View cluster information

[root@ydong ~]# redis-cli
127.0.0.1:6379> 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:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:97
cluster_stats_messages_pong_sent:111
cluster_stats_messages_sent:208
cluster_stats_messages_ping_received:106
cluster_stats_messages_pong_received:97
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:208

127.0.0.1:6379> CLUSTER NODES
adf47225a89a1dcb669be2b0b6904ab1a49ee8ab 192.168.199.157:7002@17002 slave e2c9b8c3c985fcbdb1eb6815fbbe8cbf4df819a3 0 1599576610540 1 connected
0f2f36eba63aaf62ab07abbb7e38c1d54405b08f 192.168.199.157:7001@17001 master - 0 1599576613557 3 connected 10923-16383
e2c9b8c3c985fcbdb1eb6815fbbe8cbf4df819a3 192.168.199.157:6379@16379 myself,master - 0 1599576611000 1 connected 0-5460
990ba160bf0f2c22b41bffe65f2d14eb3361049e 192.168.199.157:7003@17003 slave 3e645db2a11f848d0f727549053f49f77004ed9d 0 1599576610000 2 connected
3e645db2a11f848d0f727549053f49f77004ed9d 192.168.199.157:7004@17004 master - 0 1599576612000 2 connected 5461-10922
778506f84ceedc9873b83536d2094b40a2380c9a 192.168.199.157:7005@17005 slave 0f2f36eba63aaf62ab07abbb7e38c1d54405b08f 0 1599576612549 3 connected

11) To add a node, you
need to specify either the newly added ip:portor the existing oneip:port

[root@ydong ~]# redis-cli --cluster add-node  192.168.199.157:7006  192.168.199.157:7005

12) A new node needs to be re-sharded.

[root@ydong ~]# redis-cli --cluster reshard 192.168.199.157:7006  #这个可以随意连接
How many slots do you want to move (from 1 to 16384)? 100  #希望移动多少hash槽
What is the receiving node ID? 296f04ddaad1a56d805ce8d7d898b1bc6c7151fc   #接受的redis ID
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.   #从所有的redis实例中挑出来给你
  Type 'done' once you entered all the source nodes IDs.  #  选择down的话,需要先指明源redis id
Source node #1: all  


13) Delete a node. When deleting, you need to ensure that the node's hash slot is empty. If it is not empty, you need to remove the hash slot before deleting

[root@ydong ~]# redis-cli --cluster del-node 192.168.199.157:7006 296f04ddaad1a56d805ce8d7d898b1bc6c7151fc
>>> Removing node 296f04ddaad1a56d805ce8d7d898b1bc6c7151fc from cluster 192.168.199.157:7006
[ERR] Node 192.168.199.157:7006 is not empty! Reshard data away and try again.

[root@ydong ~]# redis-cli --cluster reshard 192.168.199.157:7006
How many slots do you want to move (from 1 to 16384)? adf47225a89a1dcb669be2b0b6904ab1a49ee8ab
How many slots do you want to move (from 1 to 16384)? 100
What is the receiving node ID? adf47225a89a1dcb669be2b0b6904ab1a49ee8ab
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: 296f04ddaad1a56d805ce8d7d898b1bc6c7151fc
Source node #2: done

[root@ydong ~]# redis-cli --cluster del-node 192.168.199.157:7006 296f04ddaad1a56d805ce8d7d898b1bc6c7151fc
>>> Removing node 296f04ddaad1a56d805ce8d7d898b1bc6c7151fc from cluster 192.168.199.157:7006
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.

Guess you like

Origin blog.csdn.net/qq_44564366/article/details/108477563