当前位置:网站首页>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
边栏推荐
猜你喜欢

MVVM architecture encapsulation of kotlin series (kotlin+mvvm)

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

Detailed relation extraction model casrel
![[collection of topics that C language learners must know 1] consolidate the foundation and steadily improve](/img/95/bec94176cadfac112585df259156c9.png)
[collection of topics that C language learners must know 1] consolidate the foundation and steadily improve

Force deduction ----- the number of words in the string
![[shaders realize overlay to re cover cross dressing effect _shader effect Chapter 9]](/img/f3/48ca9e1e8889afc0993084d6416575.png)
[shaders realize overlay to re cover cross dressing effect _shader effect Chapter 9]
![[flower carving hands-on] interesting and fun music visualization series small project (13) -- organic rod column lamp](/img/d4/7b9c7c99d46661e1be2963a342dd18.jpg)
[flower carving hands-on] interesting and fun music visualization series small project (13) -- organic rod column lamp

AI theory knowledge map 1 Foundation

Probability theory and mathematical statistics

Multi objective optimization series 1 --- explanation of non dominated sorting function of NSGA2
随机推荐
【着色器实现Overlay重新覆盖变装效果_Shader效果第九篇】
.net6与英雄联盟邂逅之——根据官方LCU API制作游戏助手
panic: Error 1045: Access denied for user ‘root‘@‘117.61.242.215‘ (using password: YES)
Cavans realizes Static Rolling barrage
天翼云Web应用防火墙(边缘云版)支持检测和拦截Apache Spark shell命令注入漏洞
JS get the current time, time and timestamp conversion
[collection of topics that C language learners must know 1] consolidate the foundation and steadily improve
Sword finger offer (VII): Fibonacci sequence
The last time I heard about eBay, or the last time
Detailed relation extraction model casrel
白帽子揭秘:互联网千亿黑产吓退马斯克
Basic sentence structure of English ----- origin
Unicorn, valued at $1.5 billion, was suddenly laid off, and another track was cold?
【Oauth2】七、微信OAuth2授权登录
How to build a customer-centric product blueprint: suggestions from the chief technology officer
图扑 3D 可视化国风设计 | 科技与文化碰撞炫酷”火花“
Unicode file parsing methods and existing problems
El table implements editable table
How to remove black edges from hyperimage images (two methods)
Time complexity and space complexity