Redis distributed cluster build 2022 version (linux environment)

Install Redis-6.2.6 in Linux environment, configure and run_01
https://gblfy.blog.csdn.net/article/details/105583077

Problems that Redis distributed cluster can solve cluster concept
Solve the problem of single node concurrency pressure and physical upper limit in the existing system By adding the number of servers to provide the same service, the server can reach a stable and efficient state
1. Overview of node distribution

Demo case
3 master 3 slave scale out

server port Node description
192.168.0.101 7001 master
192.168.0.101 7002 slave
192.168.0.102 7003 master
192.168.0.102 7004 slave
192.168.0.103 7005 master
192.168.0.103 7006 slave
Second, the software configuration initialization

2.1~2.5 belong to the public part, 101/102/103 servers need to be executed in sequence

2.1. Download
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
2.2. Unzip
cd /app
tar -zxvf redis-6.2.6.tar.gz
2.3. Compile and install
cd redis-6.2.6/
make install
2.4. Configuration extraction
mkdir /app/redis-cluster/
cp /app/redis-6.2.6/redis.conf /app/redis-cluster/
2.5. Configuration editing
vim /app/redis-cluster/redis.conf
2.6. 101 Node Operations
把bind 127.0.0.1 -::1调整为bind 0.0.0.0
port 6379      改为  port 7001
把daemonize no修改为yes 允许后台启动
pidfile /var/run/redis_6379.pid 改为 pidfile /var/run/redis_7001.pid

注释打开 cluster-enabled yes
注释打开 cluster-node-timeout 15000
注释打开并修改node节点 cluster-config-file nodes-7001.conf
保存退出
2.7. 102 Node Operations
把bind 127.0.0.1 -::1调整为bind 0.0.0.0
port 6379      改为  port 7003
把daemonize no修改为yes 允许后台启动
pidfile /var/run/redis_6379.pid 改为 pidfile /var/run/redis_7003.pid

注释打开 cluster-enabled yes
注释打开 cluster-node-timeout 15000
注释打开并修改node节点 cluster-config-file nodes-7003.conf
保存退出
2.8. 103 Node Operations
把bind 127.0.0.1 -::1调整为bind 0.0.0.0
port 6379      改为  port 7005
把daemonize no修改为yes 允许后台启动
pidfile /var/run/redis_6379.pid 改为 pidfile /var/run/redis_7005.pid

注释打开 cluster-enabled yes
注释打开 cluster-node-timeout 15000
注释打开并修改node节点 cluster-config-file nodes-7005.conf
保存退出
3. Software configuration clustering
3.1. 101 Node Execution
  • Configuration extraction
cd /app/redis-cluster/
cp redis.conf redis-7001.conf
cp redis.conf redis-7002.conf
vim redis-7002.conf
  • The specific modification details Modify
    the port to7001 pidfile /var/run/redis_ .pid to pidfile /var/run/redis_ .pid Modify the node node cluster-config-file nodes- .conf to cluster-config-file nodes- .conf7002
    70017002
    70017002

  • start redis

/app/redis-6.2.6/src/redis-server /app/redis-cluster/redis-7001.conf
/app/redis-6.2.6/src/redis-server /app/redis-cluster/redis-7002.conf
ps -ef |grep redis
3.2. 102 Node Execution
  • Configuration extraction
cd /app/redis-cluster/
cp redis.conf redis-7003.conf
cp redis.conf redis-7004.conf
vim redis-7004.conf
  • Specific modification details

Modify port to7003 pidfile /var/run/redis_ .pid to pidfile /var/run/redis_ .pid Modify node node cluster-config-file nodes- .conf to cluster-config-file nodes- .conf7004
70037004
70037004

  • start redis
/app/redis-6.2.6/src/redis-server /app/redis-cluster/redis-7003.conf
/app/redis-6.2.6/src/redis-server /app/redis-cluster/redis-7004.conf
ps -ef |grep redis
3.3. 103 Node Execution
  • Configuration extraction
cd /app/redis-cluster/
cp redis.conf redis-7005.conf
cp redis.conf redis-7006.conf
vim redis-7006.conf
  • Specific modification details

Modify port to7005 pidfile /var/run/redis_ .pid to pidfile /var/run/redis_ .pid Modify node node cluster-config-file nodes- .conf to cluster-config-file nodes- .conf7006
70057006
70057006

  • start redis
/app/redis-6.2.6/src/redis-server /app/redis-cluster/redis-7005.conf
/app/redis-6.2.6/src/redis-server /app/redis-cluster/redis-7006.conf
 ps -ef |grep redis
4. Node handshake

The above is just to build a cluster, and there is no relationship between the 6 nodes. Next, through the node handshake, the relationship between the nodes of the cluster occurs.

4.1. Turn off the firewall

centos7.x

systemctl stop firewalld

centos6.x

service iptables stop
4.2. Node handshake

Log in to the 7001 node of the 101 server, and execute (copy and paste one by one) the following commands in sequence:

/app/redis-6.2.6/src/redis-cli -h 192.168.0.101  -p 7001
cluster meet 192.168.0.101  7002
cluster meet 192.168.0.102  7003
cluster meet 192.168.0.102  7004
cluster meet 192.168.0.103  7005
cluster meet 192.168.0.103  7006
5. Slot allocation

Log in to the 7001 node of the 101 server, and execute (copy and paste one by one) the following commands in sequence:

5.1. Slot allocation
/app/redis-6.2.6/src/redis-cli -h 192.168.0.101 -p 7001 cluster addslots {
    
    0..5461}
/app/redis-6.2.6/src/redis-cli -h 192.168.0.102 -p 7003 cluster addslots {
    
    5462..10922}
/app/redis-6.2.6/src/redis-cli -h 192.168.0.103 -p 7005 cluster addslots {
    
    10923..16383}
5.2. View cluster information
/app/redis-6.2.6/src/redis-cli -h 192.168.0.101 -p 7001

View cluster information: cluster info
View node information: cluster nodes

5.3. Log Operation Information
root@redis-cluster]# /app/redis-6.2.6/src/redis-cli -h 192.168.0.101 -p 7001
192.168.0.101: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:6
cluster_size:3
cluster_current_epoch:5
cluster_my_epoch:1
cluster_stats_messages_ping_sent:670
cluster_stats_messages_pong_sent:676
cluster_stats_messages_meet_sent:5
cluster_stats_messages_sent:1351
cluster_stats_messages_ping_received:676
cluster_stats_messages_pong_received:675
cluster_stats_messages_received:1351
192.168.0.101:7001> cluster nodes
86002bbf6c62cd5d7511473ee1947531c25e1348 192.168.0.102:7003@17003 master - 0 1647941463270 3 connected 5462-10922
5f1128f200cd4446432e499a1a16f17c5a6178a7 192.168.0.103:7006@17006 master - 0 1647941462000 5 connected
895cfd76481d0ceba0fa5c5ba715980d08c2af83 192.168.0.102:7004@17004 master - 0 1647941464276 4 connected
59423855a7d7062a73f3de80826cbcd1021631de 192.168.0.101:7001@17001 myself,master - 0 1647941461000 2 connected 0-5461
4c9c2e112fded275bd02ab579ab8333c1cc98030 192.168.0.101:7002@17002 master - 0 1647941461000 1 connected
8de49a5b81ab20c4e087dcaeba9aa126773f0657 192.168.0.103:7005@17005 master - 0 1647941462266 0 connected 10923-16383
192.168.0.101:7001>

Note: It is currently the master, and the node information will be used. Do not close this window first,
and then open a new window for the next step.

Six, configure the master-slave

Log in to the 7001 node of the 101 server, and execute (copy and paste one by one) the following commands in sequence:

6.1. Configure master-slave

Master-slave replication principle (cross replication): 7004 replication 7001, 7006 replication 7003, 7002 replication 7005

/app/redis-6.2.6/src/redis-cli -h 192.168.0.102 -p 7004 cluster replicate 59423855a7d7062a73f3de80826cbcd1021631de
/app/redis-6.2.6/src/redis-cli -h 192.168.0.103 -p 7006 cluster replicate 86002bbf6c62cd5d7511473ee1947531c25e1348
/app/redis-6.2.6/src/redis-cli -h 192.168.0.101 -p 7002 cluster replicate 8de49a5b81ab20c4e087dcaeba9aa126773f0657
6.2. Operation records
[root@ ~]# /app/redis-6.2.6/src/redis-cli -h 192.168.0.102 -p 7004 cluster replicate 59423855a7d7062a73f3de80826cbcd1021631de
OK
[root@ ~]# /app/redis-6.2.6/src/redis-cli -h 192.168.0.103 -p 7006 cluster replicate 86002bbf6c62cd5d7511473ee1947531c25e1348
OK
[root@ ~]# /app/redis-6.2.6/src/redis-cli -h 192.168.0.101 -p 7002 cluster replicate 8de49a5b81ab20c4e087dcaeba9aa126773f0657
OK
[root@ ~]#
7. Cluster verification

Log in to the 7001 node of the 101 server, and execute (copy and paste one by one) the following commands in sequence:

7.1. Login to 7001 node
/app/redis-6.2.6/src/redis-cli -h 192.168.0.101 -p 7001
7.2. Viewing cluster information
/app/redis-6.2.6/src/redis-cli -h 192.168.0.101 -p 7001

View cluster information: cluster info
View node information: cluster nodes

Note: At present, when the master node hangs up with 3 masters and 3 slaves, the slave nodes automatically go up.

7.3. Operation records
[root@ ~]# /app/redis-6.2.6/src/redis-cli -h 192.168.0.101 -p 7001
192.168.0.101: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:6
cluster_size:3
cluster_current_epoch:5
cluster_my_epoch:1
cluster_stats_messages_ping_sent:1365
cluster_stats_messages_pong_sent:1344
cluster_stats_messages_meet_sent:5
cluster_stats_messages_sent:2714
cluster_stats_messages_ping_received:1344
cluster_stats_messages_pong_received:1370
cluster_stats_messages_received:2714
192.168.0.101:7001> cluster nodes
8de49a5b81ab20c4e087dcaeba9aa126773f0657 192.168.0.103:7005@17005 master - 0 1647932952097 4 connected 10923-16383
86002bbf6c62cd5d7511473ee1947531c25e1348 192.168.0.102:7003@17003 master - 0 1647932951094 2 connected 5462-10922
59423855a7d7062a73f3de80826cbcd1021631de 192.168.0.101:7001@17001 myself,master - 0 1647932950000 1 connected 0-5461
4c9c2e112fded275bd02ab579ab8333c1cc98030 192.168.0.101:7002@17002 slave 8de49a5b81ab20c4e087dcaeba9aa126773f0657 0 1647932950092 4 connected
5f1128f200cd4446432e499a1a16f17c5a6178a7 192.168.0.103:7006@17006 slave 86002bbf6c62cd5d7511473ee1947531c25e1348 0 1647932949000 2 connected
895cfd76481d0ceba0fa5c5ba715980d08c2af83 192.168.0.102:7004@17004 slave 59423855a7d7062a73f3de80826cbcd1021631de 0 1647932951000 1 connected
192.168.0.101:7001> exit
[root@~]#

Guess you like

Origin blog.csdn.net/weixin_40816738/article/details/123676653