当前位置:网站首页>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
边栏推荐
- 万字长文,浅谈企业数字化建模蓝图
- Sword finger offer (VII): Fibonacci sequence
- The.Net webapi uses groupname to group controllers to render the swagger UI
- 银行业客户体验管理现状与优化策略分析
- 《Kotlin系列》之MVVM架构封装(kotlin+mvvm)
- [beauty of open source] nanomsg (2): req/rep mode
- 从标注好的xml文件中截取坐标点(人脸框四个点坐标)人脸图像并保存在指定文件夹
- Flutter multi-channel packaging operation
- POM文件详解
- Photoshop (cc2020) unfinished
猜你喜欢

Abstract factory and its improvement examples

【OAuth2】八、OAuth2登录的配置逻辑-OAuth2LoginConfigurer和OAuth2ClientConfigurer

Multi objective optimization series 1 --- explanation of non dominated sorting function of NSGA2

See you tomorrow at the industrial session of cloud intelligence technology forum!

Uncover the secret of white hat: 100 billion black products on the Internet scare musk away

Ros2 learning (1) introduction to ros2

【着色器实现Overlay重新覆盖变装效果_Shader效果第九篇】

终极套娃 2.0 | 云原生交付的封装

我们被一个 kong 的性能 bug 折腾了一个通宵

LCL three-phase PWM rectifier (inverter)
随机推荐
Photoshop (cc2020) unfinished
Control the probability of random winning [C | random]
Official announcement! Edweisen group and Baidu xirang reached a deep co creation cooperation
[collection of topics that C language learners must know 1] consolidate the foundation and steadily improve
The serialization class in unity is in JSON format
Huawei computer test ~ offset realizes string encryption
【Oauth2】五、OAuth2LoginAuthenticationFilter
【开源之美】nanomsg(2) :req/rep 模式
Tianjin emergency response Bureau and central enterprises in Tianjin signed an agreement to deepen the construction of emergency linkage mechanism
2022年,我们只用一个月就“送走”了这么多互联网产品
[oauth2] VII. Wechat oauth2 authorized login
Abstract factory and its improvement examples
8 年产品经验,我总结了这些持续高效研发实践经验 · 研发篇
Click El dropdown item/@click.native
This article explains the FS file module and path module in nodejs in detail
官宣!艾德韦宣集团与百度希壤达成深度共创合作
冒泡排序的时间复杂度分析
With frequent data leakage and deletion events, how should enterprises build a security defense line?
POM文件详解
我们被一个 kong 的性能 bug 折腾了一个通宵