当前位置:网站首页>美团二面:为什么Redis会有哨兵?
美团二面:为什么Redis会有哨兵?
2022-07-27 15:56:00 【InfoQ】

为什么要有哨兵机制?

哨兵机制是如何工作的?

- 哨兵节点是如何监控节点的?又是如何判断主节点是否真的故障了?
- 根据什么规则选择一个从节点切换为主节点?
- 怎么把新主节点的相关信息通知给从节点和客户端呢?
如何判断主节点真的故障了?


如何选新主节点?
- 第一轮考察:哨兵首先会根据从节点的优先级来进行排序,优先级越小排名越靠前,
- 第二轮考察:如果优先级相同,则查看复制的下标,哪个从「主节点」接收的复制数据多,哪个就靠前。
- 第三轮考察:如果优先级和下标都相同,就选择从节点 ID 较小的那个。
第一轮考察:优先级最高的从节点胜出
第二轮考察:复制进度最靠前的从节点胜出

第三轮考察:ID 号小的从节点胜出
- 过滤掉已经离线的从节点;
- 过滤掉历史网络连接状态不好的从节点;
- 将剩下的从节点,进行三轮考察:优先级、复制进度、ID 号。在每一轮考察过程中,如果找到了一个胜出的从节点,就将其作为新主节点。
由哪个哨兵进行主从故障转移?

- 第一,拿到半数以上的赞成票;
- 第二,拿到的票数同时还需要大于等于哨兵配置文件中的 quorum 值。
- 哨兵集群可以判定主节点“客观下线”。哨兵集群还剩下 3 个哨兵,当一个哨兵判断主节点“主观下线”后,询问另外 2 个哨兵后,有可能能拿到 3 张赞同票,这时就达到了 quorum 的值,因此,哨兵集群可以判定主节点为“客观下线”。
- 哨兵集群可以完成主从切换。当有个哨兵标记主节点为「客观下线」后,就会进行选举 Leader 的过程,因为此时哨兵集群还剩下 3 个哨兵,那么还是可以拿到半数以上(5/2+1=3)的票,而且也达到了 quorum 值,满足了选举 Leader 的两个条件, 所以就能选举成功,因此哨兵集群可以完成主从切换。
如何通知客户端新主节点的信息?
哨兵集群是如何组成的?
sentinel monitor <master-name> <ip> <redis-port> <quorum>

- 《Redis 核心技术与实战》
- 《Redis 设计与实现》
总结
- 过滤掉已经离线的从节点;
- 过滤掉历史网络连接状态不好的从节点;
- 将剩下的从节点,进行三轮考察:优先级、复制进度、ID 号。在每一轮考察过程中,如果找到了一个胜出的从节点,就将其作为新主节点。
- 第一,拿到半数以上的赞成票;
- 第二,拿到的票数同时还需要大于等于哨兵配置文件中的 quorum 值。
边栏推荐
- Wechat applet to make calls
- 知物由学 | 小游戏的安全风险在哪里?
- The Ministry of industry and information technology re governs data security, and Netease Yidun "privacy compliance" keeps the bottom line of enterprise operation
- Zhengzhou University database course resource description
- Convolutional neural network -- SSD thesis translation
- 知物由学 | 再造巴别塔,我们如何进行NLP跨语言知识迁移?
- PostgreSQL 14 支持winserver2022吗?
- 防止sql注入
- 细数国产接口协作平台的六把武器!
- Profiles vs Permission Sets
猜你喜欢

Convolutional neural network -- from r-cnn, fast r-cnn to fast r-cnn, mask r-cnn

How to develop an online Excel spreadsheet system (Part 1)

What's the use of games| Game application value research case collection

JS to realize the right-click menu bar function

Know things by learning | build a real-time anti plug-in mechanism from 0 to 1 to supplement the offensive and defensive power of mobile games in multiple dimensions

Convolutional neural network -- Translation of yolov2 (yolo9000) papers

Learn from things | Yidun mobile terminal isomorphism practice, improve the official website interaction experience in a few steps

WebDriverException( selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executabl

JDBC connection database reading foreground cannot display data

Salesforce certified sharing and visibility Designer (su20) certification examination summary
随机推荐
X-sheet development tutorial: initialization configuration custom layout
[introduction to database system (Wang Shan)] Chapter 4 - Database Security
2022 high altitude installation, maintenance and removal of test question simulation test platform operation
Help, boost and take responsibility, the new value and significance of the 6th Tuba rabbit 718 national home decoration Festival
Oracle 11g数据库安装教程
细数国产接口协作平台的六把武器!
[Southwest University] information sharing of postgraduate entrance examination and re examination
[introduction to database system (Wang Shan)] Chapter 11 concurrency control
Are those who are absent from the written examination shortlisted for the teacher recruitment interview? Henan Xiangfu: the statistics of individual candidates' scores are wrong
快解析结合海典医药
Salesforce certified sharing and visibility Designer (su20) certification examination summary
Operation of simulated examination platform for 2022 low voltage electrician examination questions
7月第4周易盾业务风控关注 | 最高法对APP强索个人信息进行规制
How to solve the error of ora-00955 when Oracle modifies the primary key
知物由学 | SO加固如何提升Android应用的安全性?
Getting started with shell programming base
js实现右键菜单栏功能
【cf】#681 A. Kids Seating (Div. 2, based on VK Cup 2019-2020 - Final)
Understand JVM language
[MCU] 2.3 CPU of AT89S52