当前位置:网站首页>搭建哨兵模式reids、redis从节点脱离哨兵集群
搭建哨兵模式reids、redis从节点脱离哨兵集群
2022-07-02 18:23:00 【夏诗曼CharmaineXia】
安装单机reids详细教程:https://blog.csdn.net/CharmaineXia/article/details/125297843?spm=1001.2014.3001.5502
搭建主从模式集群redis:https://blog.csdn.net/CharmaineXia/article/details/125298465
0.哨兵模式简介
为了防止主从模式中reids主节点宕机以后,整个集群都无法使用,哨兵监视着redis主节点,如果主节点宕机,哨兵会在redis从节点中选出一个当做主节点。
一台哨兵也有自己宕机的风险,所以一般会开启多个哨兵,哨兵之间相互通信,主节点宕机后,哨兵们会通过“投票机制”在从节点中选出redis主节点。
哨兵模式在包含主从模式优点的基础上,还增加了稳定性。
哨兵模式建立在主从模式之上,搭建哨兵前先建好主从模式。
哨兵也要搭建集群,一主二从共有3个reids进程、3个哨兵进程。
三台服务器都配置哨兵文件,并启动哨兵,先配置好一台服务器的哨兵配置文件,然后把配置文件复制到其他服务器即可。
1.设置配置文件路径(非必做)
①创建新目录,原生的sentinel.conf做备份,启动只用以下路径的配置文件。
mkdir /home/admin/redis/redis-5.0.7/redisSentinel
②把配置文件复制过去
cp -r mkdir /home/admin/redis/redis-5.0.7/sentinel.conf /home/admin/redis/redis-5.0.7/redisSentinel
2.修改哨兵配置文件
①修改配置文件
vi /home/admin/redis/redis-5.0.7/redisSentinel/sentinel.conf
## 修改1:让sentinel服务后台运行
daemonize yes
## 修改2:增加日志文件路径
logfile “/home/admin/redis/redis-5.0.7/sentinel.log”
## 修改3:增加redis主节点信息和需要进行选举的法定个数(2代表只有2个哨兵节点同时认为master节点时效时,才算真正的失效)
把sentinel monitor mymaster 127.0.0.1 6379 2改成
sentinel monitor mymaster 192.168.60.83 6379 2
②如果配置文件是复制过来的,还需要注释哨兵的myid,启动哨兵后生成新的myid。
不然哨兵的myid相同,哨兵间无法通信。
③查看修改后的配置文件
cat sentinel.conf |grep -v “#”|grep -v “^$”
3.运行哨兵
①启动三台redis服务(先启主机,后启从机)
cd /usr/local/bin/
./redis-server /home/admin/redis/redis-5.0.7/theRedisConf/redis.conf
②启动三台哨兵服务(先启主机,后启从机)
cd /usr/local/bin/
./redis-sentinel /home/admin/redis/redis-5.0.7/redisSentinel/sentinel.conf
4.全部启动后查看哨兵的配置文件
cat /home/admin/redis/redis-5.0.7/redisSentinel/sentinel.conf |grep -v “#”|grep -v “^$”
5.校验哨兵是否启动成功
①连接哨兵:
redis-cli -p 26379或者进到src下执行 ./redis-cli -p 26379
②查询当前节点状态:
info sentinel
127.0.0.1:26379> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=192.168.60.83:6379,slaves=2,sentinels=3
③查看主节点状态
sentinel master mymaster
④查看从节点状态
sentinel slaves mymaster
⑤查看所有哨兵状态
sentinel sentinels mymaster
六、让从节点脱离哨兵集群的测试:
前提:哨兵模式(3个redis:60.83(主节点)、60.84、60.85,以及3个哨兵)
redis从节点执行“SLAVEOF NO ONE”命令,将使得这个从属服务器关闭复制功能,并从从属服务器转变回主服务器,原来同步所得的数据集不会被丢弃。
测试1:启动三个哨兵,60.85执行变主节点命令,马上查询信息变为主节点,自身没有从节点。同时查询60.83仍然是主节点,60.85仍是它的从节点。过不到一分钟查看60.85变回60.83的从节点(下图为60.83的信息)。
结论:哨兵的配置文件中记录着redis主节点和从节点的IP,一旦哨兵发现某个从节点“独立”了,会把这个从节点拉回redis集群中。测试1从节点脱离主节点失败。
测试2:关闭所有哨兵,60.85执行变主节点命令,马上查询信息变为主节点,自身没有从节点。同时查询60.83仍然是主节点,60.85不再是它的从节点。过一分钟查看60.85没有变回60.83的从节点。

重启60.85服务后,查看60.83,60.85成为了60.83的从节点,查看60.85显示为60.83的从机。

结论:因为60.85的配置文件中将60.83设置为主节点,重启60.85的服务后将回归为60.83的从节点。
最后的结论:命令是即时生效的,配置文件中的设置是每次启动服务时生效的,当执行了“SLAVEOF NO ONE”只会暂时让redis从机脱离集群(不开哨兵的情况下)。想要让redis从机60.85永久的从哨兵模式的redis集群中脱离,需要关闭redis从机60.85和所有哨兵,再删除redis从机60.85配置文件中的redis主机60.83的IP信息、所有哨兵配置文件中关于redis从机60.85的IP信息,最后重启edis60.85和所有哨兵。
边栏推荐
- PHP parser badminton reservation applet development requires online system
- Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
- 思维意识转变是施工企业数字化转型成败的关键
- 线程应用实例
- Mobile robot path planning: artificial potential field method [easy to understand]
- "Patient's family, please come here" reading notes
- 高级性能测试系列《24. 通过jdbc执行sql脚本》
- 《病人家属,请来一下》读书笔记
- A4988驱动步进电机「建议收藏」
- Stm32g0 USB DFU upgrade verification error -2
猜你喜欢

Processing strategy of message queue message loss and repeated message sending

教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 網絡安全專家 NSE 5

高频面试题

Hospital online inquiry source code hospital video inquiry source code hospital applet source code

Tutorial (5.0) 09 Restful API * fortiedr * Fortinet network security expert NSE 5

Watchful pioneer world outlook Architecture - (how does a good game come from)

juypter notebook 修改默认打开文件夹以及默认浏览器

Yolov3 trains its own data set to generate train txt

中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖

According to the atlas of data security products and services issued by the China Academy of information technology, meichuang technology has achieved full coverage of four major sectors
随机推荐
4274. 后缀表达式-二叉表达式树
Emmet基础语法
教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5
股票证券公司排名,有安全保障吗
Page title component
Data dimensionality reduction factor analysis
2022.7.1-----leetcode. two hundred and forty-one
Obligatoire pour les débutants, cliquez sur deux boutons pour passer à un contenu différent
[0701] [论文阅读] Alleviating Data Imbalance Issue with Perturbed Input During Inference
Develop fixed asset management system, what voice is used to develop fixed asset management system
SIFT feature point extraction "suggestions collection"
潇洒郎:彻底解决Markdown图片问题——无需上传图片——无需网络——转发给他人图片无缺失
《病人家属,请来一下》读书笔记
Memory management of C
《代码整洁之道》读书笔记
Reduce -- traverse element calculation. The specific calculation formula needs to be passed in and combined with BigDecimal
Markdown basic grammar
Fastdfs installation
【ERP软件】ERP体系二次开发有哪些危险?
[论文阅读] CA-Net: Leveraging Contextual Features for Lung Cancer Prediction