当前位置:网站首页>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
边栏推荐
- The picture quality has been improved! LR enhancement details_ Lightroom turns on AI photo detail enhancement: picture clarity increases by 30%
- Protobuf and grpc
- Use of constraintlayout
- Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution
- Piwigo 2.7.1 sqli learning
- Use of form text box (I) select text
- 创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
- Zzuli:1044 failure rate
- Niuke: crossing the river
- FPGA blocking assignment and non blocking assignment
猜你喜欢
pyQt界面制作(登录+跳转页面)
5-1 blocking / non blocking, synchronous / asynchronous
链表有环,快慢指针走3步可以吗
C language fcntl function
C string format (decimal point retention / decimal conversion, etc.)
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
retrofit
[graphics] efficient target deformation animation based on OpenGL es 3.0
Adobe Premiere Pro 15.4 has been released. It natively supports Apple M1 and adds the function of speech to text
How does vs+qt set the software version copyright, obtain the software version and display the version number?
随机推荐
[opengl] bone animation blending effect
How does vs+qt set the software version copyright, obtain the software version and display the version number?
Analysis of gene family characteristics - chromosome location analysis
dllexport和dllimport
[combinatorics] permutation and combination (set combination, one-to-one correspondence model analysis example)
[ue4] material and shader permutation
Happy capital new dual currency fund nearly 4billion yuan completed its first account closing
Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial
tonybot 人形机器人 红外遥控玩法 0630
Chapter 14 class part 1
China PETG market forecast and Strategic Research Report (2022 Edition)
C # realizes the login interface, and the password asterisk is displayed (hide the input password)
Déformation de la chaîne bm83 de niuke (conversion de cas, inversion de chaîne, remplacement de chaîne)
tonybot 人形机器人 定距移动 代码编写玩法
4-24--4-28
Introduction to opengl4.0 tutorial computing shaders
Use of constraintlayout
Pytorch深度学习和目标检测实战笔记
5-1 blocking / non blocking, synchronous / asynchronous
NOI OPENJUDGE 1.4(15)