当前位置:网站首页>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
边栏推荐
- B+ tree (4) joint index -- MySQL from entry to proficiency (16)
- Sword finger offer (IX): abnormal jumping steps
- 数据泄漏、删除事件频发,企业应如何构建安全防线?
- ROS2学习(1)ROS2简述
- Photoshop (cc2020) unfinished
- B+ tree index use (9) grouping, back to table, overlay index (21)
- Oom caused by improper use of multithreading
- Seven steps to copywriting script ---- document team collaborative management
- .net6与英雄联盟邂逅之——根据官方LCU API制作游戏助手
- panic: Error 1045: Access denied for user ‘root‘@‘117.61.242.215‘ (using password: YES)
猜你喜欢

【Oauth2】七、微信OAuth2授权登录

Unicode file parsing methods and existing problems

Win11+VS2019配置YOLOX

Pytoch learning notes (II) the use of neural networks

JS get the current time, time and timestamp conversion

《Kotlin系列》之MVVM架构封装(kotlin+mvvm)

如何构建以客户为中心的产品蓝图:来自首席技术官的建议

Seven steps to copywriting script ---- document team collaborative management

We were tossed all night by a Kong performance bug
![[oauth2] VIII. Configuration logic of oauth2 login -oauth2loginconfigurer and oauth2clientconfigurer](/img/7e/4f652c4d3d72ad563ddbc1c1f1f50b.png)
[oauth2] VIII. Configuration logic of oauth2 login -oauth2loginconfigurer and oauth2clientconfigurer
随机推荐
【开源之美】nanomsg(2) :req/rep 模式
The shell script in Jenkins fails to execute but does not exit by itself
421. Maximum XOR value of two numbers in the array
[oauth2] VIII. Configuration logic of oauth2 login -oauth2loginconfigurer and oauth2clientconfigurer
数据泄漏、删除事件频发,企业应如何构建安全防线?
天翼云Web应用防火墙(边缘云版)支持检测和拦截Apache Spark shell命令注入漏洞
Precautions for triggering pytest.main() from other files
华为机考 ~ 偏移量实现字符串加密
我们被一个 kong 的性能 bug 折腾了一个通宵
B+ tree selection index (1) -- MySQL from entry to proficiency (22)
JS object assignment problem
Solution 5g technology helps build smart Parks
In 2022, we "sent away" so many Internet products in only one month
Unicode file parsing methods and existing problems
带你熟悉云网络的“电话簿”:DNS
估值15亿美元的独角兽被爆裁员,又一赛道遇冷?
How to realize the reality of temporary graphic elements
(Reprint) creation methods of various points in ArcGIS Engine
Probability theory and mathematical statistics
一文学透MySQL表的创建和约束