Redis配置sentinel模式
Redis配置sentinel模式
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
哨兵(sentinel)主要是完成三个功能:监控,通知,自动故障转移功能。sentinel是安装Redis服务时默认安装的,因此我们可以直接使用!
一.配置项说明
1>.port
服务的监听端口,比如:port 26479。
2>.sentinel monitor <master-name> <ip><redis-port><quorm>
<quorum>表示sentinel集群的quorum机制,即至少有quorum个sentinel节点同时判断主节点故障时,才任务其真的故障。
s_down:subjectively down
o_down:objectively down
3>.semtinel auth-pass <master-name><password>
4>.sentinel down-afer-milliseconds <master-name><millseconds>
监听到指定的集群的主节点异常状态持久多久方才将标记为“故障”。
5>.sentinel parallel-syncs <master-name> <numslaves>
指在failover过程中,能够被sentinel并行配置的从节点的数量。
6>.sentinel failover-timeout <master-name> <milliseconds>
sentinel必须在此指定的时间长内完成故障转移操作,否则,将视为故障转移操作失败。
7>.sentinel notification-script <master-name> <script-path>
通知脚本,此脚本被自动传递多个参数。
8>.redis-cli -h SENTINEL_HOST -p SENTINEL_PORT
二.实操案例
1>.编写sentinel的配置文件(我们复用redis集群的虚拟机)
[root@node101.yinzhengjie.org.cn ~]# egrep -v "^$|^#" /etc/redis-sentinel.conf
bind node101.yinzhengjie.org.cn
port
dir /tmp
sentinel monitor yinzhengjie-redis node101.yinzhengjie.org.cn
sentinel auth-pass yinzhengjie-redis yinzhengjie
sentinel down-after-milliseconds yinzhengjie-redis
sentinel parallel-syncs yinzhengjie-redis
sentinel failover-timeout yinzhengjie-redis
logfile /var/log/redis/sentinel.log
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# egrep -v "^$|^#" /etc/redis-sentinel.conf
[root@node102.yinzhengjie.org.cn ~]# egrep -v "^$|^#" /etc/redis-sentinel.conf
bind node102.yinzhengjie.org.cn
port
dir /tmp
sentinel monitor yinzhengjie-redis node101.yinzhengjie.org.cn
sentinel auth-pass yinzhengjie-redis yinzhengjie
sentinel down-after-milliseconds yinzhengjie-redis
sentinel parallel-syncs yinzhengjie-redis
sentinel failover-timeout yinzhengjie-redis
logfile /var/log/redis/sentinel.log
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# egrep -v "^$|^#" /etc/redis-sentinel.conf
[root@node103.yinzhengjie.org.cn ~]# egrep -v "^$|^#" /etc/redis-sentinel.conf
bind node103.yinzhengjie.org.cn
port
dir /tmp
sentinel monitor yinzhengjie-redis node101.yinzhengjie.org.cn
sentinel auth-pass yinzhengjie-redis yinzhengjie
sentinel down-after-milliseconds yinzhengjie-redis
sentinel parallel-syncs yinzhengjie-redis
sentinel failover-timeout yinzhengjie-redis
logfile /var/log/redis/sentinel.log
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# egrep -v "^$|^#" /etc/redis-sentinel.conf
2>.启动sentinel服务
[root@node101.yinzhengjie.org.cn ~]# systemctl start redis-sentinel
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# systemctl status redis-sentinel
● redis-sentinel.service - Redis Sentinel
Loaded: loaded (/usr/lib/systemd/system/redis-sentinel.service; disabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/redis-sentinel.service.d
└─limit.conf
Active: active (running) since Sat -- :: CST; 11s ago
Main PID: (redis-sentinel)
CGroup: /system.slice/redis-sentinel.service
└─ /usr/bin/redis-sentinel node101.yinzhengjie.org.cn: [sentinel] Apr :: node101.yinzhengjie.org.cn systemd[]: Starting Redis Sentinel...
Apr :: node101.yinzhengjie.org.cn systemd[]: Started Redis Sentinel.
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 172.30.1.101: *:*
LISTEN 172.30.1.101: *:*
LISTEN *: *:*
LISTEN ::: :::*
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# tail /etc/redis-sentinel.conf
logfile "/var/log/redis/sentinel.log"
# Generated by CONFIG REWRITE
supervised systemd
sentinel config-epoch yinzhengjie-redis
sentinel leader-epoch yinzhengjie-redis
sentinel known-slave yinzhengjie-redis 172.30.1.102
sentinel known-slave yinzhengjie-redis 172.30.1.103
sentinel known-sentinel yinzhengjie-redis 172.30.1.102 9c195f20e954d9032f57900c1839857ee4c31be4
sentinel known-sentinel yinzhengjie-redis 172.30.1.103 fbafb3bdbd04c61cf9c4e8dcf0147c7a20f22243
sentinel current-epoch
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# systemctl start redis-sentinel
[root@node102.yinzhengjie.org.cn ~]# systemctl start redis-sentinel
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# systemctl status redis-sentinel
● redis-sentinel.service - Redis Sentinel
Loaded: loaded (/usr/lib/systemd/system/redis-sentinel.service; disabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/redis-sentinel.service.d
└─limit.conf
Active: active (running) since Sat -- :: CST; 42s ago
Main PID: (redis-sentinel)
CGroup: /system.slice/redis-sentinel.service
└─ /usr/bin/redis-sentinel node102.yinzhengjie.org.cn: [sentinel] Apr :: node102.yinzhengjie.org.cn systemd[]: Starting Redis Sentinel...
Apr :: node102.yinzhengjie.org.cn systemd[]: Started Redis Sentinel.
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 172.30.1.102: *:*
LISTEN 172.30.1.102: *:*
LISTEN *: *:*
LISTEN ::: :::*
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# tail /etc/redis-sentinel.conf
logfile "/var/log/redis/sentinel.log"
# Generated by CONFIG REWRITE
supervised systemd
sentinel config-epoch yinzhengjie-redis
sentinel leader-epoch yinzhengjie-redis
sentinel known-slave yinzhengjie-redis 172.30.1.103
sentinel known-slave yinzhengjie-redis 172.30.1.102
sentinel known-sentinel yinzhengjie-redis 172.30.1.103 fbafb3bdbd04c61cf9c4e8dcf0147c7a20f22243
sentinel known-sentinel yinzhengjie-redis 172.30.1.101 5697f4a91fe1bf43f075e729bdde6ec504dc820e
sentinel current-epoch
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# systemctl start redis-sentinel
[root@node103.yinzhengjie.org.cn ~]# systemctl start redis-sentinel
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# systemctl status redis-sentinel
● redis-sentinel.service - Redis Sentinel
Loaded: loaded (/usr/lib/systemd/system/redis-sentinel.service; disabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/redis-sentinel.service.d
└─limit.conf
Active: active (running) since Sat -- :: PDT; 5s ago
Main PID: (redis-sentinel)
CGroup: /system.slice/redis-sentinel.service
└─ /usr/bin/redis-sentinel node103.yinzhengjie.org.cn: [sentinel] Apr :: node103.yinzhengjie.org.cn systemd[]: Starting Redis Sentinel...
Apr :: node103.yinzhengjie.org.cn systemd[]: Started Redis Sentinel.
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# tail /etc/redis-sentinel.conf
logfile "/var/log/redis/sentinel.log"
# Generated by CONFIG REWRITE
supervised systemd
sentinel config-epoch yinzhengjie-redis
sentinel leader-epoch yinzhengjie-redis
sentinel known-slave yinzhengjie-redis 172.30.1.102
sentinel known-slave yinzhengjie-redis 172.30.1.103
sentinel known-sentinel yinzhengjie-redis 172.30.1.101 5697f4a91fe1bf43f075e729bdde6ec504dc820e
sentinel known-sentinel yinzhengjie-redis 172.30.1.102 9c195f20e954d9032f57900c1839857ee4c31be4
sentinel current-epoch
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# systemctl start redis-sentinel
3>.查看当前集群的状态
[root@node101.yinzhengjie.org.cn ~]# redis-cli -h node101.yinzhengjie.org.cn -p
node101.yinzhengjie.org.cn:>
node101.yinzhengjie.org.cn:> SENTINEL masters
) ) "name"
) "yinzhengjie-redis"
) "ip"
) "172.30.1.101"
) "port"
) ""
) "runid"
) "514f95dd0a54449ec221b662da02caa65f74353e"
) "flags"
) "master"
) "link-pending-commands"
) ""
) "link-refcount"
) ""
) "last-ping-sent"
) ""
) "last-ok-ping-reply"
) ""
) "last-ping-reply"
) ""
) "down-after-milliseconds"
) ""
) "info-refresh"
) ""
) "role-reported"
) "master"
) "role-reported-time"
) ""
) "config-epoch"
) ""
) "num-slaves"
) ""
) "num-other-sentinels"
) ""
) "quorum"
) ""
) "failover-timeout"
) ""
) "parallel-syncs"
) ""
node101.yinzhengjie.org.cn:>
node101.yinzhengjie.org.cn:>
node101.yinzhengjie.org.cn:26379> SENTINEL masters #查看主节点信息
node101.yinzhengjie.org.cn:> SENTINEL slaves yinzhengjie-redis
) ) "name"
) "172.30.1.102:6379"
) "ip"
) "172.30.1.102"
) "port"
) ""
) "runid"
) "2b4d70685d17183e80816314d160162770d01aec"
) "flags"
) "slave"
) "link-pending-commands"
) ""
) "link-refcount"
) ""
) "last-ping-sent"
) ""
) "last-ok-ping-reply"
) ""
) "last-ping-reply"
) ""
) "down-after-milliseconds"
) ""
) "info-refresh"
) ""
) "role-reported"
) "slave"
) "role-reported-time"
) ""
) "master-link-down-time"
) ""
) "master-link-status"
) "ok"
) "master-host"
) "172.30.1.101"
) "master-port"
) ""
) "slave-priority"
) ""
) "slave-repl-offset"
) ""
) ) "name"
) "172.30.1.103:6379"
) "ip"
) "172.30.1.103"
) "port"
) ""
) "runid"
) "4ed8d98123094a5922650a4d7047bba03851f6b7"
) "flags"
) "slave"
) "link-pending-commands"
) ""
) "link-refcount"
) ""
) "last-ping-sent"
) ""
) "last-ok-ping-reply"
) ""
) "last-ping-reply"
) ""
) "down-after-milliseconds"
) ""
) "info-refresh"
) ""
) "role-reported"
) "slave"
) "role-reported-time"
) ""
) "master-link-down-time"
) ""
) "master-link-status"
) "ok"
) "master-host"
) "172.30.1.101"
) "master-port"
) ""
) "slave-priority"
) ""
) "slave-repl-offset"
) ""
node101.yinzhengjie.org.cn:>
node101.yinzhengjie.org.cn:>
node101.yinzhengjie.org.cn:26379> SENTINEL slaves yinzhengjie-redis #查看从节点信息
我们可以使用SENTINEL实现自动容灾,也可以根据SENTINEL提供的信息手动修改master节点等操作。
Redis配置sentinel模式的更多相关文章
- Redis哨兵(sentinel)模式搭建
一.Sentinel介绍 之前骚了一波Redis的简介及应用场景,今天试了下他的哨兵模式: Sentinel是Redis的高可用性(HA)解决方案,由一个或多个Sentinel实例组成的Sentine ...
- SpringBoot连接Redis (Sentinel模式&Cluster模式)
一.引入pom <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
- Redis(九)高可用专栏之Sentinel模式
本文讲述Redis高可用方案中的哨兵模式--Sentinel,RedisClient中的Jedis如何使用以及使用原理. Redis主从复制 Redis Sentinel模式 Jedis中的Senti ...
- Redis配置集群一(window)
因为接下来的项目要使用到redis作为我们项目的缓存,所以就花了一天时间研究了一下redis的一些用法,因为没转linux虚拟机,所以就决定先研究一下windows版本的redis集群.主要是redi ...
- SpringBoot进阶教程(三十)整合Redis之Sentinel哨兵模式
Redis-Sentinel是官方推荐的高可用解决方案,当redis在做master-slave的高可用方案时,假如master宕机了,redis本身(以及其很多客户端)都没有实现自动进行主备切换,而 ...
- Redis笔记-Sentinel哨兵模式
Redis以主从的模式搭建集群后,如果主节点Master挂掉,虽然可以实现将备用节点Slave切换成主节点,但是Redis本身并没有自动监控机制,需要借助Sentinel哨兵模式,实现监控并实现自动切 ...
- redis单点、redis主从、redis哨兵sentinel,redis集群cluster配置搭建与使用
目录 redis单点.redis主从.redis哨兵 sentinel,redis集群cluster配置搭建与使用 1 .redis 安装及配置 1.1 redis 单点 1.1.2 在命令窗口操作r ...
- 【Redis】Redis学习(四) Redis Sentinel模式详解
主从模式的弊端就是不具备高可用性,当master挂掉以后,Redis将不能再对外提供写入操作,因此sentinel应运而生. Redis Sentinel是Redis官方提供的集群管理工具,主要有三大 ...
- Redis全方位讲解--哨兵模式(Sentinel模式)
前言 当按照上一篇<redis主从复制>部署好之后,我们会想,一旦redis的master出现了宕机,并且我们并没有及时发现,这时候就可能会出现数据丢失或程序无法运行.此时,redis的哨 ...
随机推荐
- 解决Linux系统下Mysql数据库中文显示成问号的问题
当我们将开发好的javaWEB项目部署到linux系统上,操作数据库的时候,会出现中文乱码问题,比如做插入操作,发现添加到数据库的数据中文出现论码,下面就将解决linux下mysql中文乱码问题! 打 ...
- C#微信支付对接
c#版在pc端发起微信扫码支付 主要代码: /** * 生成直接支付url,支付url有效期为2小时,模式二 * @param productId 商品ID * @return 模式二URL */ ...
- laravel部署创建新项目 助记
打开进入homestead虚拟机,并进入code文件夹 cd ~/homestead && vagrant up && vagrant ssh cd ~/Code 进行 ...
- jquery datatable 实例操作
var dataTables = $(".table").dataTable({ data: d,//为ajax的值,没有直接用插件自带的请求数据方式,个人觉得data的方式好控制 ...
- 全民抵制“辱华”品牌秀,D&G神回复:呵呵~ 那不是我!
### 补发一下,前写天写的: 就在今天下午,有网友爆出知名品牌 Dolce&Gabbana(杜嘉班纳)的设计师兼创始人Stefano Gabbana在ins上公然发表辱华言论. 下面截图 可 ...
- 【笔记】基于Python的数字图像处理
[博客导航] [Python相关] 前言 基于Python的数字图像处理,离不开相关处理的第三方库函数.搜索网络资源,列出如下资源链接. Python图像处理库到底用哪家 python计算机视觉编程— ...
- 自定义JDBC链接池
上篇简单介绍了jdbc链接数据库: 本篇就说一下自定义连接池以及增删改查的测试: 自定义连接池 自定义链接池的原因 JDBC连接中用到Connection 在每次对数据进行增删查改 都要 开启 ...
- 【Python 03】程序设计与Python语言概述
人生苦短,我用Python. Python在1990年诞生于荷兰,2010年Python2发布最后一版2.7,Python核心团队计划在2020年停止支持 Python2,目前Python3是未来. ...
- springMVC框架核心方法调用源码解析
- OpenCV 与 OpenGL 的关系是什么?
OpenCV是 Open Source Computer Vision LibraryOpenGL是 Open Graphics LibraryOpenCV主要是提供图像处理和视频处理的基础算法库,还 ...