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的哨 ...
随机推荐
- 【公众号系列】超详细SAP HANA JOB全解析
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[公众号系列]超详细SAP HANA JOB全解 ...
- SQL Server -- 回忆笔记(三):ADO.NET之C#操作数据库
SQL Server知识点回忆篇(三):ADO.NET之C#操作数据库 1.连接数据库 (1)创建连接字符串: 使用windows身份验证时的连接字符串: private string conStr= ...
- const关键字到底该怎么用
原文地址:https://www.yanbinghu.com/2019/01/28/7442.html 前言 我们都知道使用const关键字限定一个变量为只读,但它是真正意义上的只读吗?实际中又该如何 ...
- Python开发【第一篇】基础题目一
1.求1-2+3-4+5.....99的所有数的和 n = 1 s = 0 while n<100: temp = n%2 if temp == 0: #偶数 s = s-n else: s = ...
- Logging 日志配置格式模板
import osBASE_DIR = os.path.dirname(os.path.dirname(__file__))DB_PATH = os.path.join(BASE_DIR, 'db') ...
- nginx上配置phpmyadmin
Nginx配置phpmyadmin流程如下: 一.准备软件和环境(这里我以ubuntu16.04为例) 1.安装php7.1 sudo LC_ALL=C.UTF- add-apt-repository ...
- 2-STM32带你入坑系列(点亮一个灯--Keil)
1-STM32带你入坑系列(STM32介绍) 首先是安装软件 这一节用Kei来实现,需要安装MDK4.7这个软件,怎么安装,自己百度哈.都学习32的人了,不会连个软件都不会安装吧....还是那句话 没 ...
- Label Encoding vs One Hot Encoding
最近在刷kaggle的时候碰到了两种处理类别型特征的方法:label encoding和one hot encoding.我从stackexchange, quora等网上搜索了相关的问题,总结如下. ...
- Scrapy框架基本用法讲解
目标站点:http://quotes.toscrape.com/ (scrape官方练习站点) 这边为了区别Python3.5 和 Python3.7 我修改了scrapy的可执行文件 创建项目文件: ...
- (PAT)L2-012 关于堆的判断 (最小堆)
题目链接:https://www.patest.cn/contests/gplt/L2-012 将一系列给定数字顺序插入一个初始为空的小顶堆H[].随后判断一系列相关命题是否为真.命题分下列几种: “ ...