当前位置:网站首页>美团二面:为什么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 值。
边栏推荐
- golang 并发缓存击穿或合并请求
- golang worker池
- VSS tip: search all checked out files (search checked out files according to users)
- Wechat applet realizes location map display and introduces map map without navigation
- How to learn C language? This article gives you the complete answer
- What are the safety risks of small games?
- Original direct selling MOS tube knl42150 2.8a/1500v applicable photovoltaic inverter can provide samples
- Getting started with shell programming base
- 机器学习——概念理解之IoU
- MySQL creates a student table and queries grades
猜你喜欢

Kubernetes 1.24 high availability cluster binary deployment

Evaluation index of machine learning (II) -- classification evaluation index

7月第4周易盾业务风控关注 | 最高法对APP强索个人信息进行规制

卷积神经网络——从R-CNN,Fast R-CNN到Faster R-CNN,Mask R-CNN

How to restrict root remote login so that ordinary users have root privileges
![[user article] examples of P4 consolidation practice guide disassemble resolve](/img/84/503fc057ce642038f693b38be69bc0.png)
[user article] examples of P4 consolidation practice guide disassemble resolve

Evaluation index of machine learning (I) -- regression evaluation index
How to improve the security of Android applications?

JS to realize the right-click menu bar function
![[Southwest University] information sharing of postgraduate entrance examination and re examination](/img/15/298ea6f7367741e1e085007c498e51.jpg)
[Southwest University] information sharing of postgraduate entrance examination and re examination
随机推荐
How to solve the error of ora-00955 when Oracle modifies the primary key
How to resolve the public domain name to the intranet IP server -- quickly resolve the domain name and map the Internet access
ts学习笔记-class
Yyds dry inventory interview must brush top101: specified interval reversal in the linked list
Wechat applet cloud function batch delete multiple data error: errcode: -502005 database collection not exists
知物由学 | SO加固如何提升Android应用的安全性?
golang 等待一组goroutine完成,并带返回值(2)
Evaluation index of machine learning (II) -- classification evaluation index
机器学习——概念理解之IoU
WPF做登陆界面
How can we carry out NLP cross language knowledge transfer?
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
How to learn C language? This article gives you the complete answer
卷积神经网络——YOLOV2(YOLO9000)论文翻译
fragmentTransaction.replace第二个参数报错
微信小程序 实现拨打电话
查找表中多余重复记录并删除保留最小一个
PostgreSQL 14 支持winserver2022吗?
ES查询限制10000条数据解决方法
Oracle 11g数据库安装教程