当前位置:网站首页>Centos7 deployment sentry redis (with architecture diagram, clear and easy to understand)
Centos7 deployment sentry redis (with architecture diagram, clear and easy to understand)
2022-07-03 14:51:00 【Natural player】
1 origin
From the last article How to use it correctly Vertx operation Redis(3.9.4 With source code analysis ) Speaking of ,
This article shares Vert.x Connect and operate Redis, It introduces monomer Redis And clusters rRedis The connection and operation of ,
Because of monomer Redis And clusters Redis The previous experiments have been completed (Ubuntu20.04), It can be used directly , however , Sentinel's Redis No building , therefore , Only connection and operation codes can be given , No test is given ,
therefore , Over the weekend ( It's raining , The typhoon “ Siemba ”[xiān bā] Attack ) In the way of setting up sentinels on experimental machines Redis colony ,
Test sentinel mode Vert.x Connect and operate Redis, Improve the previous article ,
Because the experimental machine is CentOS7 The system of ,
Deploy Sentinel Redis It took some time , There is still reference value ,
Share as follows .
2 Get ready
The overall structure is shown in the figure below , It can be seen from the picture that , sentry 3 individual , Form a sentinel cluster ; node 3 individual , One master node and two slave nodes . The sentinel monitors the running status of the node cluster , And instantly switch Services , Guarantee Redis Normal operation .
2.1 Compile environment
CentOS7 default gcc Version is 4.8.5, see gcc command :gcc -v
, The results are shown in the following figure :
The version gcc Can't compile Redis6.0.6, So it needs to be upgraded gcc, Use the following command :
# Software set (Software collections)
yum -y install centos-release-scl
# gcc And tool set
sudo yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
# Enable gcc
scl enable devtoolset-9 bash
After installation gcc edition , As shown in the figure below :
2.2 Redis Get ready
This article USES the Redis6.0.6, The version Redis Sentinel and cluster deployment can be realized .
Download address :http://download.redis.io/releases/redis-6.0.6.tar.gz
2.3 compile Redis
decompression Redis To directory , Such as :/home/xindaqi/install/redis
tar -zxvf redis-6.0.6.tar.gz -C /home/xindaqi/install/redis
Get into redis-6.0.6 Folder , compile Redis, command :make
,
As shown in the figure below :
thus , complete Redis compile ,
The environment is ready .
3 To configure
In sentinel mode , Configure three Redis node ( Virtual node ), therefore , It consists of one master node and two slave nodes ,
Compile the above Redis Copy three copies , Store to path :/home/xindaqi/install/redis/sentinel,
Name it 9001,9002,9003, Long like this :
among ,9001 Master node ,9002 and 9003 As a slave node .
Node information is as follows :
Serial number | node IP | port | describe |
---|---|---|---|
1 | 192.168.1.12 | 9001 | Master node |
2 | 192.168.1.12 | 9002 | From the node |
3 | 192.168.1.12 | 9003 | From the node |
The sentry information is as follows :
Serial number | node IP | port | describe |
---|---|---|---|
1 | 192.168.1.12 | 26379 | sentry 1 |
2 | 192.168.1.12 | 26380 | sentry 2 |
3 | 192.168.1.12 | 26381 | sentry 3 |
3.1 Node configuration
3.1.1 Master node
Modify in the master node Redis To configure :redis.conf,
The changes are as follows :
# notes IP binding ,Redis Service for all IP to open up
# bind 127.0.0.1 ::1
# Turn off protection mode , all IP Accessible Redis Server side
protected-mode no
# Redis Service port
port 9001
# The daemons run Redis Server side
daemonize yes
# pid file :9001
pidfile /var/run/redis_9006.pid
# Log files :9001
logfile /home/xindaqi/project/logs/redis-9001.log
3.1.2 From the node
The slave node configuration information is as follows :redis.conf,
Different from the master node , The slave node needs to configure the master node partition information (replicaof), For synchronizing data and delivering messages .
- From the node 1
Port usage 9002.
# notes IP binding ,Redis Service for all IP to open up
# bind 127.0.0.1 ::1
# Turn off protection mode , all IP Accessible Redis Server side
protected-mode no
# Redis Service port
port 9002
# The daemons run Redis Server side
daemonize yes
# pid file :9001
pidfile /var/run/redis_9006.pid
# Log files :9001
logfile /home/xindaqi/project/logs/redis-9002.log
# Master node replica : Synchronize the data of the master node to the slave node
replicaof 192.168.1.12 9001
- From the node 2
Port usage 9003.
# notes IP binding ,Redis Service for all IP to open up
# bind 127.0.0.1 ::1
# Turn off protection mode , all IP Accessible Redis Server side
protected-mode no
# Redis Service port
port 9003
# The daemons run Redis Server side
daemonize yes
# pid file :9001
pidfile /var/run/redis_9006.pid
# Log files :9001
logfile /home/xindaqi/project/logs/redis-9003.log
# Master node replica : Synchronize the data of the master node to the slave node
replicaof 192.168.1.12 9001
3.1.3 Start the master-slave service
After configuration , Next, you can start the master-slave service , Check out the information .
Use Shell The script starts the service , The contents are as follows :
echo "Starting Redis master and slave"
cd /home/xindaqi/install/redis/sentinel
9001/src/redis-server 9001/redis.conf
9002/src/redis-server 9002/redis.conf
9003/src/redis-server 9003/redis.conf
echo "Redis master and slave is started!!!"
3.1.4 Node information
- Get into Redis Master node :
src/redis-cli -h 192.168.1.12 -p 9001
- View node information
Node information includes the number of slave nodes 、 From the node IP and Port etc. .
info replication
- Enter from node
src/redis-cli -h 192.168.1.12 -p 9002
- View slave node information
View the master node information from the node , Such as IP and Port And the working state of the main node :UP perhaps DOWN.
info replication
3.2 Sentinel configuration
After completing node configuration , Next, you need to configure sentinels ,
this paper , Sentinels also use clusters ( fictitious ) The way ,
Configure three sentinel nodes , It can be seen from the above ,Redis6.0.6 Support sentry and cluster configuration , therefore ,
You can directly modify the sentry's configuration file :sentinel.conf.
3.2.1 sentinel
Sentinel configuration , The core is to configure the port of the sentry and the master node for monitoring ,
adopt sentinel monitor mymaster 192.168.1.12 9001 2 Monitor master , And name the main node ,
Yes , The name of the master node is actually configured in the sentinel ,
because , The client connection is through the sentinel .
- sentry -1
# The port where the sentry runs
port 26379
# The daemons run
daemonize yes
# Process documents
pidfile "/var/run/redis-sentinel-26379.pid"
# Log location
logfile "/home/xindaqi/project/logs/sentinel-26379.log"
# Main node information monitored by sentry
# mymaster: Master node name
# 192.168.1.12: Master node IP
# 9001: Master node Port
# 2: Identify the number of sentinels at the primary node , If the number of sentinels reaches this number, it is determined that the primary node is lost , Then it is determined that the primary node is objectively disconnected
sentinel monitor mymaster 192.168.1.12 9001 2
- sentry -2
# The port where the sentry runs
port 26380
# The daemons run
daemonize yes
# Process documents
pidfile "/var/run/redis-sentinel-26380.pid"
# Log location
logfile "/home/xindaqi/project/logs/sentinel-26380.log"
# Main node information monitored by sentry
# mymaster: Master node name
# 192.168.1.12: Master node IP
# 9001: Master node Port
# 2: Identify the number of sentinels at the primary node , If the number of sentinels reaches this number, it is determined that the primary node is lost , Then it is determined that the primary node is objectively disconnected
sentinel monitor mymaster 192.168.1.12 9001 2
- sentry -3
# The port where the sentry runs
port 26381
# The daemons run
daemonize yes
# Process documents
pidfile "/var/run/redis-sentinel-26381.pid"
# Log location
logfile "/home/xindaqi/project/logs/sentinel-26381.log"
# Main node information monitored by sentry
# mymaster: Master node name
# 192.168.1.12: Master node IP
# 9001: Master node Port
# 2: Identify the number of sentinels at the primary node , If the number of sentinels reaches this number, it is determined that the primary node is lost , Then it is determined that the primary node is objectively disconnected
sentinel monitor mymaster 192.168.1.12 9001 2
3.2.2 Activate the sentry
After completing the sentry configuration , Next, start the sentry , Also use Shell perform ,
Shell The script is as follows :
echo "Starting Redis sentinel"
cd /home/xindaqi/install/redis/sentinel
9001/src/redis-sentinel 9001/sentinel.conf
9002/src/redis-sentinel 9002/sentinel.conf
9003/src/redis-sentinel 9003/sentinel.conf
echo "Redis sentinel is started!!!"
3.2.3 Check the sentry information
- Enter the sentry
src/redis-cli -h 192.168.1.12 -p 26379
- Check the information
View the master node information in the current cluster through the sentry 、 Number of slave nodes and sentinels , As shown in the figure below .
info sentinel
3.3 port configuration
because CentOS7 The default firewall is on , By default, all ports are closed ,
therefore , Deployed services need to expose ports , You need to open ports one by one ,
The ports that need to be opened here are :26379、26380、26381、9001、9002 and 9003.
With 26379 Port as an example :
# Open port
sudo firewall-cmd --zone=public --add-port=26379/tcp --permanent
# Port validation
sudo firewall-cmd --reload
4 Summary
The core :
(1) Environmental preparation :gcc upgrade ,Redis compile ;
(2) Configuration node : Master and slave nodes ;
(3) Deploy sentinels : Listen to the master node , Configure master node name ;
(4) Open ports :CentOS7 Default off Port , therefore , You need to open all ports of sentinels and nodes .
Q&A
error: ‘struct redisServer’ has no member named ‘aof_rewrite_perc’
CentOS7 Default
gcc -v
Improve gcc edition , Install the following plug-ins :
# Software set (Software collections)
yum -y install centos-release-scl
# gcc And tool set
sudo yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
# Enable gcc
scl enable devtoolset-9 bash
边栏推荐
- 7-10 stack of hats (25 points) (C language solution)
- Four data flows and cases of grpc
- dllexport和dllimport
- Output student grades
- The picture quality has been improved! LR enhancement details_ Lightroom turns on AI photo detail enhancement: picture clarity increases by 30%
- Bucket sorting in C language
- Puzzle (016.3) is inextricably linked
- 零拷贝底层剖析
- 4-20-4-23 concurrent server, TCP state transition;
- Vs+qt application development, set software icon icon
猜你喜欢
C language to realize mine sweeping
Open under vs2019 UI file QT designer flash back problem
dllexport和dllimport
C language DUP function
retrofit
复合类型(自定义类型)
Devaxpress: range selection control rangecontrol uses
[graphics] hair simulation in tressfx
Luogu p4047 [jsoi2010] tribal division solution
Tonybot humanoid robot checks the port and corresponds to port 0701
随机推荐
C language DUP function
Four data flows and cases of grpc
牛客 BM83 字符串變形(大小寫轉換,字符串反轉,字符串替換)
[ue4] material and shader permutation
Creation of data table of Doris' learning notes
7-3 rental (20 points)
556. 下一个更大元素 III : 简单构造模拟题
Zzuli:1053 sine function
QT program font becomes larger on computers with different resolutions, overflowing controls
分布式事务(Seata) 四大模式详解
Some concepts about agile
Dllexport et dllimport
亚马逊、速卖通、Lazada、Shopee、eBay、wish、沃尔玛、阿里国际、美客多等跨境电商平台,测评自养号该如何利用产品上新期抓住流量?
[opengl] face pinching system
Zzuli:1049 square sum and cubic sum
Déformation de la chaîne bm83 de niuke (conversion de cas, inversion de chaîne, remplacement de chaîne)
7-3 count the number of words in a line of text
[qingniaochangping campus of Peking University] in the Internet industry, which positions are more popular as they get older?
Use of form text box (I) select text
Puzzle (016.4) domino effect