当前位置:网站首页>Redis (15) -- master-slave replication of redis -- sentinel mode
Redis (15) -- master-slave replication of redis -- sentinel mode
2022-04-21 08:11:00 【Jiang Hao】
11.5) Sentinel mode
11.5.1) brief introduction
The automatic version of anti guest oriented , Be able to monitor the failure of the host in the background , If it fails, it will automatically convert from the library to the main library according to the number of votes
11.5.2) Use steps
11.5.2.1) Adjust to one master and two servants mode
127.0.0.1:11079> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=127.0.0.1,port=11081,state=online,offset=266,lag=1
slave1:ip=127.0.0.1,port=11080,state=online,offset=266,lag=1
master_failover_state:no-failover
master_replid:e504980f294d5cb1c873bf68464b81ce21294369
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:266
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:266
11079 : host
11080 、11081: Slave
11.5.2.2) New configuration file
Self defined /myredis New under the directory sentinel.conf file
sentinel monitor mymaster 127.0.0.1 11079 1
Execute startup command :
redis-sentinel /root/myredis/sentinel.conf
Successful launch :
[root@VM-20-6-centos bin]# redis-sentinel /root/myredis/sentinel.conf
17788:X 21 Apr 2022 00:31:15.637 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
17788:X 21 Apr 2022 00:31:15.637 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=17788, just started
17788:X 21 Apr 2022 00:31:15.637 # Configuration loaded
17788:X 21 Apr 2022 00:31:15.638 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.6 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in sentinel mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 26379
| `-._ `._ / _.-' | PID: 17788
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
17788:X 21 Apr 2022 00:31:15.639 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
17788:X 21 Apr 2022 00:31:15.647 # Sentinel ID is cb52f79e99489e385a57361aef7982875b0384aa
17788:X 21 Apr 2022 00:31:15.647 # +monitor master mymaster 127.0.0.1 11079 quorum 1
17788:X 21 Apr 2022 00:31:15.648 * +slave slave 127.0.0.1:11081 127.0.0.1 11081 @ mymaster 127.0.0.1 11079
17788:X 21 Apr 2022 00:31:15.655 * +slave slave 127.0.0.1:11080 127.0.0.1 11080 @ mymaster 127.0.0.1 11079
11.5.2.3) test
Stop the host service :
127.0.0.1:11079> shutdown
not connected> exit
Above redis-sentinel Interface :
17788:X 21 Apr 2022 00:34:33.399 # +promoted-slave slave 127.0.0.1:11080 127.0.0.1 11080 @ mymaster 127.0.0.1 11079
17788:X 21 Apr 2022 00:34:33.399 # +failover-state-reconf-slaves master mymaster 127.0.0.1 11079
17788:X 21 Apr 2022 00:34:33.482 * +slave-reconf-sent slave 127.0.0.1:11081 127.0.0.1 11081 @ mymaster 127.0.0.1 11079
17788:X 21 Apr 2022 00:34:34.438 * +slave-reconf-inprog slave 127.0.0.1:11081 127.0.0.1 11081 @ mymaster 127.0.0.1 11079
17788:X 21 Apr 2022 00:34:34.438 * +slave-reconf-done slave 127.0.0.1:11081 127.0.0.1 11081 @ mymaster 127.0.0.1 11079
17788:X 21 Apr 2022 00:34:34.509 # +failover-end master mymaster 127.0.0.1 11079
17788:X 21 Apr 2022 00:34:34.509 # +switch-master mymaster 127.0.0.1 11079 127.0.0.1 11080
17788:X 21 Apr 2022 00:34:34.509 * +slave slave 127.0.0.1:11081 127.0.0.1 11081 @ mymaster 127.0.0.1 11080
17788:X 21 Apr 2022 00:34:34.509 * +slave slave 127.0.0.1:11079 127.0.0.1 11079 @ mymaster 127.0.0.1 11080
It can be seen that the slave 11080 Switch to host , Restart the host , see 11079 Service information :
127.0.0.1:11079> info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:11080
master_link_status:up
master_last_io_seconds_ago:1
see 11080 Service information :
127.0.0.1:11080> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=127.0.0.1,port=11081,state=online,offset=32883,lag=0
slave1:ip=127.0.0.1,port=11079,state=online,offset=32869,lag=0
master_failover_state:no-failover
master_replid:e2db42e820ac3d927269cd59ef3bc775e7e5405f
master_replid2:e504980f294d5cb1c873bf68464b81ce21294369
master_repl_offset:32883
second_repl_offset:12586
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:225
repl_backlog_histlen:32659
It is found that the above has automatically removed the host from 11079 Switch to a 11080 了
11.5.3) Replication delay
Because all write operations are performed on the host first (Master) On the operation , Then synchronize the update to the slave (Slave) On , So from the host (Master) Synchronize to slave (Slave) There is a certain delay , When the system is busy , The delay problem will be more serious , Slave (Slave) The increase in the number of machines will make the problem more serious .
11.5.4) Fault recovery ( Election rules )

1、 The priority is redis.conf The default , The lower the value, the higher the priority ;
replica-priority 100
2、 Offset : It refers to the one that obtains the most complete data of the original host ;
3、 Every redis After the instance is started, it will generate one randomly 40 Bit runid;
11.5.5)Jedis Implement sentinel mode
private static JedisSentinelPool jedisSentinelPool = null;
public static Jedis getJedisFromSentinel() {
if (jedisSentinelPool == null) {
Set<String> sentinelSet = new HashSet<>();
sentinelSet.add("127.0.0.1:26379");
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxTotal(10); // Maximum number of connections available
jedisPoolConfig.setMaxIdle(5); // Maximum number of idle connections
jedisPoolConfig.setMinIdle(5); // Minimum number of idle connections
jedisPoolConfig.setBlockWhenExhausted(true); // Whether the connection is exhausted and wait
jedisPoolConfig.setMaxWaitMillis(2000); // Waiting time
jedisPoolConfig.setTestOnBorrow(true); // Test the connection ping pong
jedisSentinelPool = new JedisSentinelPool("mymaster", sentinelSet, jedisPoolConfig);
return jedisSentinelPool.getResource();
} else {
return jedisSentinelPool.getResource();
}
}
版权声明
本文为[Jiang Hao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210722552235.html
边栏推荐
- ESmodule规范入门
- [Ethernet switching security] - explanation of port isolation operation principle and two-layer isolation and three-layer communication example configuration
- Yolov5 model environment construction and Google lab training
- YOLOv5模型环境搭建及使用google colab训练
- ESP32 VHCI实现BLE广播,就是这么神奇
- Replication of Apache Solr Remote Code Execution Vulnerability (cve-2019-0193)
- Express architecture in nodejs
- 类加载与类加载器概述
- 【以太网交换安全】--- 端口隔离运行原理及二层隔离三层通信实例配置讲解
- Operation of simulation examination platform of 100 simulated questions for safety production management personnel of hazardous chemical production units in 2022
猜你喜欢

安装mongodb

数据探索性分析(EDA)之数据分布、相关性分析及可视化方法

HTTP cache policy and scheme

Replication of Apache skywalking SQL injection (cve-2020-9483)

The listview column in C automatically adapts to the perfect effect of scaling

Installer mongodb
![[talkative cloud native] load balancing - the passenger flow of small restaurants has increased](/img/55/cc2adf83a86718b634598c4463fcd1.png)
[talkative cloud native] load balancing - the passenger flow of small restaurants has increased

【以太网交换安全】--- 端口隔离运行原理及二层隔离三层通信实例配置讲解

ESP32 VHCI实现BLE广播,就是这么神奇

VMware16 新安装Win11专业版 ,无法读取ISO镜像无法启动安装程序
随机推荐
Compile u-boot for stm32mp157 development board
2022 R2 mobile pressure vessel filling test question simulation test question bank and simulation test
Capturing plaintext password with mimikatz in win10 system
Actual JDBC connection to MySQL database
跨域是什么和如何解决跨域问题的三种方法
Mathematical experiment -- function drawing experiment
Batch replacement of some data of a field in MySQL
Swift memory management
正则表达式验证
It can be downloaded to the data set running loam
[PROJECT] small hat takeout (V)
亿级流量多级缓存架构
The listview column in C automatically adapts to the perfect effect of scaling
Swift 类型检查与转换
set集合
【一、xxx病虫害检测项目】2、网络结构尝试改进:Resnet50、SE、CBAM、Feature Fusion
Mysql双主双从+Atlas数据测试
Win10 prompts that there is no mapping between account name and security ID
Execute rule after MySQL where condition
【项目】小帽外卖(五)