0
点赞
收藏
分享

微信扫一扫

Redis—哨兵模式

90哦吼 2022-01-04 阅读 74

在这里插入图片描述

哨兵模式配置

  • 主从配置:
    https://blog.csdn.net/qq_45246098/article/details/122286747
##⾸先实现三个redis实例之间的主从配置(如上)

## 创建并启动三个哨兵
## 拷⻉sentinel.conf⽂件三份:sentinel-26380.conf sentinel-26382.conf sentinel-26382.conf

## 创建sentinelconf⽬录
[root@theo redis-5.0.5]# mkdir sentinelconf
## 拷⻉sentinel.conf⽂件到 sentinelconf⽬录:sentinel-26380.conf
## grep -v "#" 查找并删除注释代码    grep -v "^$"查找并删除空白行
[root@theo redis-5.0.5]# cat sentinel.conf | grep -v "#" | grep -v "^$" >
sentinelconf/sentinel-26380.conf
[root@theo redis-5.0.5]# cd sentinelconf/
[root@theo sentinelconf]# ll
total 4
-rw-r--r-- 1 root root 326 May 19 17:09 sentinel-26380.conf
## 编辑 sentinelconf/sentinel-26380.conf⽂件
[root@theo sentinelconf]# vim sentinel-26380.conf
port 26380
daemonize no
pidfile "/var/run/redis-sentinel-26380.pid"
logfile ""
dir "/tmp"
sentinel deny-scripts-reconfig yes
# 此处配置默认的主库的ip 和端⼝ 最后的数字是哨兵数量的⼀半多⼀个 (3个哨兵就写2 5个就写3)
sentinel monitor mymaster 127.0.0.1 6380 2
## 添加此命令设置 主机宕机后无响应30秒则选举新主机
sentinel down-after-milliseconds mymaster 30000 

sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
protected-mode no
sentinel current-epch 0
## 复制两份配置
[root@theo sentinelconf]# sed 's/26380/26381/g' sentinel-26380.conf > sentinel-26381.conf
[root@theo sentinelconf]# sed 's/26380/26382/g' sentinel-26380.conf > sentinel-26382.conf

使用示例

##启动 主redis 备1redis 备2redis
[root@theo ~]# redis-server /usr/local/redis-5.0.5/msconf/redis-master.conf
[root@theo ~]# redis-server /usr/local/redis-5.0.5/msconf/redis-slave1.conf
再依次启动三个哨兵:
[root@theo ~]# redis-sentinel /usr/local/redis-5.0.5/sentinelconf/sentinel-26380.conf
  • 当主机master宕机30秒后 3个哨兵会监控发现并推举出两个从机slave中状态较好者为主机
  • 原主机恢复后会轮为从机继续运行
举报

相关推荐

0 条评论