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模式的更多相关文章

  1. Redis哨兵(sentinel)模式搭建

    一.Sentinel介绍 之前骚了一波Redis的简介及应用场景,今天试了下他的哨兵模式: Sentinel是Redis的高可用性(HA)解决方案,由一个或多个Sentinel实例组成的Sentine ...

  2. SpringBoot连接Redis (Sentinel模式&Cluster模式)

    一.引入pom <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...

  3. Redis(九)高可用专栏之Sentinel模式

    本文讲述Redis高可用方案中的哨兵模式--Sentinel,RedisClient中的Jedis如何使用以及使用原理. Redis主从复制 Redis Sentinel模式 Jedis中的Senti ...

  4. Redis配置集群一(window)

    因为接下来的项目要使用到redis作为我们项目的缓存,所以就花了一天时间研究了一下redis的一些用法,因为没转linux虚拟机,所以就决定先研究一下windows版本的redis集群.主要是redi ...

  5. SpringBoot进阶教程(三十)整合Redis之Sentinel哨兵模式

    Redis-Sentinel是官方推荐的高可用解决方案,当redis在做master-slave的高可用方案时,假如master宕机了,redis本身(以及其很多客户端)都没有实现自动进行主备切换,而 ...

  6. Redis笔记-Sentinel哨兵模式

    Redis以主从的模式搭建集群后,如果主节点Master挂掉,虽然可以实现将备用节点Slave切换成主节点,但是Redis本身并没有自动监控机制,需要借助Sentinel哨兵模式,实现监控并实现自动切 ...

  7. redis单点、redis主从、redis哨兵sentinel,redis集群cluster配置搭建与使用

    目录 redis单点.redis主从.redis哨兵 sentinel,redis集群cluster配置搭建与使用 1 .redis 安装及配置 1.1 redis 单点 1.1.2 在命令窗口操作r ...

  8. 【Redis】Redis学习(四) Redis Sentinel模式详解

    主从模式的弊端就是不具备高可用性,当master挂掉以后,Redis将不能再对外提供写入操作,因此sentinel应运而生. Redis Sentinel是Redis官方提供的集群管理工具,主要有三大 ...

  9. Redis全方位讲解--哨兵模式(Sentinel模式)

    前言 当按照上一篇<redis主从复制>部署好之后,我们会想,一旦redis的master出现了宕机,并且我们并没有及时发现,这时候就可能会出现数据丢失或程序无法运行.此时,redis的哨 ...

随机推荐

  1. C#中的值类型和引用类型,深拷贝,浅拷贝

    from https://www.jianshu.com/p/2d27b06e253f 一.C#中的值类型和引用类型 概念 值类型直接存储其值. 引用类型存储对值的引用. 说起来有些拗口,其本质是Va ...

  2. Docker:测试环境的准备-建立一台centos测试机

    一.安装虚拟机并配置网络,下面演示在一台工作机上搭建环境 基础准备: 安装VMware-workstation-full-15.0.0-10134415.exe 安装虚拟机,镜像文件:CentOS-7 ...

  3. Scrapy案例02-腾讯招聘信息爬取

    目录 1. 目标 2. 网站结构分析 3. 编写爬虫程序 3.1. 配置需要爬取的目标变量 3.2. 写爬虫文件scrapy 3.3. 编写yield需要的管道文件 3.4. setting中配置请求 ...

  4. css_属性

    老师的博客:https://www.cnblogs.com/liwenzhou/p/7999532.htm css的属性 整体属性的:作用于全局 width:表示宽 height:表示长 color: ...

  5. windows环境:idea或者eclipse指定用户名操作hadoop集群

    方法 在系统的环境变量或java JVM变量添加HADOOP_USER_NAME(具体值视情况而定). 比如:idea里面可以如下添加HADOOP_USER_NAME=hdfs 原理:直接看源码 /h ...

  6. spring boot +mybatis(通过properties配置) 集成

    注:日常学习记录贴,下面描述的有误解的话请指出,大家一同学习. 因为我公司现在用的是postgresql数据库,所以我也用postgresql进行测试 一.前言 1.Spring boot 会默认读取 ...

  7. 【题解】P1171 售货员的难题

    Tags 搜索,状压​. 裸的旅行商问题 #include <stdio.h> #include <string.h> #define re register #define ...

  8. ios自动打包-fastlane 安装、使用、更新和卸载

    ios自动打包使用fastlane 1.首先安装xcode 首先检查是否已经安装 Xcode 命令行工具,fastlane 使用 xcodebuild 命令进行打包,运行 xcode-select - ...

  9. windows做代理服务器让内部linux上网

    fiddler代理上网 1 下载安装:http://www.telerik.com/fiddl er 2 设置代理,如下图 3 代理服务器信息 代理服务器的IP : 10.1.44.11 代理服务器的 ...

  10. IDEA SpringBoot多模块项目搭建详细过程(转)

    文章转自https://blog.csdn.net/zcf980/article/details/83040029 项目源码: 链接: https://pan.baidu.com/s/1Gp9cY1Q ...