当前位置:网站首页>搭建哨兵模式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和所有哨兵。
边栏推荐
- Gstore weekly gstore source code analysis (4): black and white list configuration analysis of security mechanism
- C的内存管理
- Codeworks 5 questions per day (1700 average) - day 4
- 高频面试题
- Introduction to the paper | analysis and criticism of using the pre training language model as a knowledge base
- Novice must see, click two buttons to switch to different content
- A4988 drive stepper motor "recommended collection"
- [test development] software testing - concept
- 中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
- 移动机器人路径规划:人工势场法[通俗易懂]
猜你喜欢

新手必看,點擊兩個按鈕切換至不同的內容
![[0701] [paper reading] allowing data imbalance issue with perforated input during influence](/img/c7/9b7dc4b4bda4ecfe07aec1367fe059.png)
[0701] [paper reading] allowing data imbalance issue with perforated input during influence

线程应用实例

高级性能测试系列《24. 通过jdbc执行sql脚本》

Introduction to the paper | analysis and criticism of using the pre training language model as a knowledge base

The difference between interceptor and filter

Tutorial (5.0) 10 Troubleshooting * fortiedr * Fortinet network security expert NSE 5

IEDA refactor的用法

守望先锋世界观架构 ——(一款好的游戏是怎么来的)

《架构整洁之道》读书笔记(下)
随机推荐
Typescript 之 快速入门
冒泡排序数组
Virtual machine initialization script, virtual machine mutual secret key free
使用 Cheat Engine 修改 Kingdom Rush 中的金钱、生命、星
Tutorial (5.0) 10 Troubleshooting * fortiedr * Fortinet network security expert NSE 5
教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 網絡安全專家 NSE 5
IDEA编辑器去掉sql语句背景颜色SQL语句警告No data sources are configured to run this SQL...和SQL Dialect is Not Config
[paper reading] Ca net: leveraging contextual features for lung cancer prediction
Reduce -- traverse element calculation. The specific calculation formula needs to be passed in and combined with BigDecimal
#gStore-weekly | gStore源码解析(四):安全机制之黑白名单配置解析
二进制操作
Markdown基础语法
以太网PHY层芯片LAN8720A简介
潇洒郎:彻底解决Markdown图片问题——无需上传图片——无需网络——转发给他人图片无缺失
《架构整洁之道》读书笔记(下)
新手必看,点击两个按钮切换至不同的内容
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
Tutorial (5.0) 09 Restful API * fortiedr * Fortinet network security expert NSE 5
《病人家属,请来一下》读书笔记
Hospital online inquiry source code hospital video inquiry source code hospital applet source code