当前位置:网站首页>Docker integrates the redis sentinel mode (one master, two slave and three sentinels)
Docker integrates the redis sentinel mode (one master, two slave and three sentinels)
2022-07-26 13:43:00 【CS beat you】
docker Integrate redis Sentinel mode ( One leader, two followers and three sentinels )
Redis-Sentinel yes Redis Official recommended high availability (HA) Solution , When used Redis do Master-slave The high availability of , If master It's down. ,Redis In itself ( Including many of its clients ) No automatic master / standby switching is realized , and Redis-sentinel It is also an independent process , It can monitor multiple master-slave colony , Find out master Can be automatically switched after downtime .Sentinel By one or more Sentinel example Composed of Sentinel The system can monitor any number of primary servers , And all the slave servers under these master servers , And when the monitored master server goes offline , Automatically upgrade a slave server under the offline master server to a new master server .

Let's start with the principle : Pictured above , This is the structure of sentinel mode , Only master Can be done write, The others didn't write Authority , Only read jurisdiction , When master After the failure , A new one will be elected master, And the Sentry will put the new master The address is returned to the project , So that the project can quickly switch to the new master, The following figure shows the switched architecture .

Let's start building docker sentinel Sentinel mode
Encounter pit : use docker swarm Integrate setinel , master Failure cannot be switched automatically , because sentinel From monitoring master obtain slave Of ip yes docker The virtual ip, NAT Unable to switch due to impassability . The following is to use docker run To build . The public network is adopted ip
Prepare three hosts : Deploy one on each of the three machines redis And a sentinel, To achieve high availability
1, start-up master node
docker run -it --name redis-master -v /home/AuthenticationCenter/redis/master:/data -d -p 6379:6379 --network=cloud_desktop_network redis:5.0
notes : Network initialization --attachable The network of patterns , The network can be in docker swarm The cluster is free to add other containers , Later in the project, you can pass Container name visit .
2, Start the second and third slave nodes
docker run -it --name redis-slave-1 -v /home/AuthenticationCenter/redis/slave1:/data -d -p 6380:6379 --network=cloud_desktop_network redis:5.0 redis-server --slaveof 121.201.95.75 6379 --slave-announce-ip 121.201.75.49 --slave-announce-port 6380
explain :--slaveof 121.201.95.75 6379 To configure master Address ,
--slave-announce-ip 121.201.75.49 To configure slave Tell the sentry slave Address
--slave-announce-port 6380 To configure slave Tell the sentry slave The port of
3, Activate the sentry sentinel
Copy three copies as sentinel1.conf , sentinel2.conf , sentinel3.conf , Because the ports started in the container are 26379 , It's all monitoring master node , So the three configurations are the same ,
Execute the following command , Copy 3 Share redis-sentinel The configuration file
cp sentinel.conf sentinel1.conf
cp sentinel.conf sentinel2.conf
cp sentinel.conf sentinel3.conf
sentinel.conf as follows :
port 26379
dir /tmp
# Custom cluster name , among 121.201.95.75 by redis-master Of ip,6379 by redis-master The port of ,2 Is the minimum number of votes ( Because there is 3 platform Sentinel So it can be set to 2)
sentinel monitor mymaster 121.201.95.75 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
# configure connections master Password
sentinel auth-pass mymaster [email protected]
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yesproblem : Many people are curious , Monitor only master, slave How to monitor ,
answer :slave It's through master Back to ip Just listen .
Start three sentinels on three servers ( One sentry per server ), Play the role of disaster recovery , Distributed deployment
start-up sentinel-1 command :docker run -it --name redis-sentinel-1 -v /home/AuthenticationCenter/redis/docker/sentinel/sentinel1.conf:/usr/local/etc/redis/sentinel.conf -d -p 26379:26379 --network=cloud_desktop_network redis:5.0 redis-sentinel /usr/local/etc/redis/sentinel.conf
start-up sentinel-2 command :docker run -it --name redis-sentinel-2 -v /home/AuthenticationCenter/redis/docker/sentinel/sentinel2.conf:/usr/local/etc/redis/sentinel.conf -d -p 26380:26379 --network=cloud_desktop_network redis:5.0 redis-sentinel /usr/local/etc/redis/sentinel.conf
start-up sentinel-3 command :docker run -it --name redis-sentinel-3 -v /home/AuthenticationCenter/redis/docker/sentinel/sentinel3.conf:/usr/local/etc/redis/sentinel.conf -d -p 26381:26379 --network=cloud_desktop_network redis:5.0 redis-sentinel /usr/local/etc/redis/sentinel.conf
4, Check whether the status is successful after configuration
1, Check the sentinel status ( Here's the picture )
Enter one of the Sentinels : docker exec -it Containers id /bin/bash
Get into redis-server : redis-cli -p 26379
see master Of host situation :sentinel slaves mymaster Here's the picture , This is successful , There are indications ip, ok identification
2, Connect three sets redis , The manual in master Write data , see slave Is it synchronized .
1 and 2 It's normal redis The sentry is finished ,
4, old master How to join after hanging up redis Cluster ,
Find out at this time master Node ip, adopt salve Just join by
5,springboot How to use the project ?
It's very simple , Only need to configure sentinels ip And port , Here's the picture :
1, add to maven rely on
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.1.5.RELEASE</version>
</dependency>2, add to redis To configure
#redis
spring.redis.database=0
#spring.redis.password=
# List of sentinels ,master The address Sentry will automatically return
spring.redis.sentinel.master=mymaster
spring.redis.sentinel.nodes=39.107.119.256:26379,39.107.119.256:26380,39.107.119.256:26381
# The maximum number of connections to the database , set up 0 For there is no limit
spring.redis.lettuce.pool.max-active=8
# Maximum number of waiting connections , set up 0 For there is no limit
spring.redis.lettuce.pool.max-idle=8
# Maximum connection setup wait time . If this time is exceeded, an exception will be received . Set to -1 Means unlimited .
spring.redis.lettuce.pool.max-wait=-1ms
# Minimum number of waiting connections , set up 0 For there is no limit
spring.redis.lettuce.pool.min-idle=0
spring.redis.lettuce.shutdown-timeout=100msHere we are ,docker Integrate redis Sentinel cluster complete
边栏推荐
- 【C语言学习者必会的题目集锦1】巩固基础,稳步提高
- Sword finger offer (x): rectangular coverage
- We were tossed all night by a Kong performance bug
- Basic sentence structure of English ----- origin
- 【黑马早报】字节旗下多款APP下架;三只松鼠脱氧剂泄露致孕妇误食;CBA公司向B站索赔4.06亿;马斯克否认与谷歌创始人妻子有婚外情...
- I. creation and constraint of MySQL table
- Solution 5g technology helps build smart Parks
- Probability theory and mathematical statistics
- How to write the introduction of GIS method journals and papers?
- Intercept the coordinate points (four point coordinates of the face frame) face image from the marked XML file and save it in the specified folder
猜你喜欢

The shell script in Jenkins fails to execute but does not exit by itself

【C语言学习者必会的题目集锦1】巩固基础,稳步提高

How to build a customer-centric product blueprint: suggestions from the chief technology officer

Unity中序列化类为json格式

Pytorch学习笔记(二)神经网络的使用

2022年,我们只用一个月就“送走”了这么多互联网产品

Tianjin emergency response Bureau and central enterprises in Tianjin signed an agreement to deepen the construction of emergency linkage mechanism

Algorithm -- continuous sequence (kotlin)

We were tossed all night by a Kong performance bug

Unicode文件解析方法及存在问题
随机推荐
7-25 0-1 backpack (50 points)
JSON数据传递参数&日期型参数传递
[turn] judge the relationship between two geometries in ArcGIS
Detailed explanation of factory mode
ROS2学习(1)ROS2简述
Brief introduction of reflection mechanism
Feixin, which lasted 15 years and had 500million users, was completely dead
冒泡排序的时间复杂度分析
Why does WPS refuse advertising?
Multi objective optimization series 1 --- explanation of non dominated sorting function of NSGA2
向路由组件传递参数
With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
.net6与英雄联盟邂逅之——根据官方LCU API制作游戏助手
Detailed relation extraction model casrel
Precautions for triggering pytest.main() from other files
我们被一个 kong 的性能 bug 折腾了一个通宵
云智技术论坛工业专场 明天见!
Exploration on cache design optimization of community like business
Seven steps to copywriting script ---- document team collaborative management
解决远程主机无法连接mysql数据库的问题