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的哨 ...
随机推荐
- LeetCode算法题-Sum of Square Numbers(Java实现)
这是悦乐书的第276次更新,第292篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第144题(顺位题号是633).给定一个非负整数c,判断是否存在两个整数a和b,使得a的 ...
- 【English】20190321
Keep in mind记住[kip ɪn maɪnd] maintenance维护[ˈmentənəns] Also Keep in mind that table maintenance use ...
- ssr
使用Nuxt.js改造已有项目的方法 https://www.jb51.net/article/145203.htm
- git 忽略 .idea文件
多人开发时,会出现明明在gitignore中忽略了.idea文件夹,但是提交时仍旧会出现.idea内文件变动的情况 原因.idea已经被git跟踪,之后再加入.gitignore后是没有作用的 解决办 ...
- Django-CRM项目学习(七)-权限组件的设置以及权限组件的应用
开始今日份整理 1.利用自定制标签,增加展示权限,权限分级设定 1.1 在权限组件中创建自定义标签 使用自定义标签的目的,使各个数据进行分离 1.2 导入自定义标签包 自定义标签复习(自定义标签有三种 ...
- Mango 基础知识
1 mongdb和python交互的模块 pymongo 提供了mongdb和python交互的所有方法 安装方式: pip install pymongo 2 使用pymongo 1. 导入pymo ...
- ubuntu安装docker{ubuntu16.04下安装docker}
一.开始安装 第一步: 由于apt官方库里的docker版本可能比较旧,所以先卸载可能存在的旧版本: $ sudo apt-get remove docker docker-engine d ...
- multiset的erase()操作中出现跳过元素的问题
昨天,我写了一个multiset去重,让tt指向it的后面第一个元素,若重复则删除这2个元素,并令it=tt,it++:来使it指向tt的下一个元素(我想指向原it的后面第2个元素,并认为tt的下一个 ...
- Text Mining and Analytics WEEK1
第一周目标 解释自然语言处理中的一些基本概念 解释不同的方式来表示文本数据 解释的两种基本的词联想以及如何从文本数据挖掘聚合关系 尝试回答以下问题 为了理解一个自然语言句子,计算机必须做些什么? 什么 ...
- 微信小程序遍历Echarts图表,实现多个饼图
如何在微信小程序中使用Echarts可以看我的另一个教程:点击查看 首先看一个简单的例子 1.wxml文件 <view style='width:100%;height:200rpx'> ...