Directory
Configure redis master-slave replication
- ##Use the ping command to check whether it is started
- View link information on the master node
- Start deploying sentinel node
- Deploy sentinel
- Start sentinel
- Demonstrate failover
- Verify whether the main node of redis has changed
- This is the end of the introduction to sentinel, not enough Corrections are welcome.
- ##View the node information currently monitored by sentinel
Use the ping command to check whether it is started
redis-cli -h 127.0.0.1 -p 6379 ping
As follows, return PONG to indicate that all three redis services have been started Startup completed
One master node:
Two slave nodes:
View the link information on the master node
查看6379的连接信息 命令:info replication 可以发现6379的角色是master,有两个从节点,也就是端口为6380,6381的从节点(redis)
同样在6380 从节点中,该节点的角色是slave(从节点),与主节点的连接状态为up(master_link_status),通过这个命令可以方便的查看各个节点的连接状态等信息。

除了用info replication命令外,如下命令也可以快速查看链接信息 redis-cli -h 127.0.0.1 -p 6381 info replication 看个人喜好用哪个命令。

Start deploying the sentinel node
Deploy sentinel
进入安装redis的目录下的配置目录,我的本地是/etc/redis
我这边就直接使用原本的sentinel.conf配置,来作为第一个sentinel节点。我们可以进入sentinel.conf配置看下里面到底有啥配置信息: sentinel monitor mymaster 127.0.0.1 6379 2 //监控的主节点IP和端口,其中mymaster是该节点的别名,2表示判断主节点失败至少需要两个节点同意 sentinel down-after-milliseconds mymaster 30000 //通过ping命令,各个sentinel节点向redis节点是否可达,超过30000毫秒,就判定不可达 sentinel failover-timeout mymaster 180000 //故障转移超时时间为180000毫秒 如果还有其它的配置,可以自己在探索下

启动命令: sudo redis-sentinel sentinel.conf --sentinel
查看sentinel启动情况 redis-cli -h 127.0.0.1 -p 26379 INFO Sentinel 可以看出与查看redis启动的情况命令类似,截图中可以看到此时sentinel监控redis节点是端口为6379的服务,6379有两个从节点,状态为OK,别名是mymaster

继续再配置两个sentinel节点, sudo cp sentinel.conf sentinel2.conf sudo cp sentinel.conf sentinel3.conf 修改两个配置的端口为26380, 26381,其它配置可以不用修改 修改完后,分别启动 sudo redis-sentinel sentinel2.conf --sentinel sudo redis-sentinel sentinel3.conf --sentinel

启动后再次查看sentinel.conf的配置,可以发现配置中多了两个从节点的信息,截图如下:

##Demo failover
查看26379端口的Sentinel节点监控的主节点信息
查看目前redis的进程ps -ef | grep redis
Interrupt redis master node
之前我们sentinel监控的主节点是6379这个端口,这时候我们kill这个端口的进程,或者使用shutdown命令: redis-cli -h 127.0.0.1 -p 6379 shutdown 过了30秒之后查看26379端口的Sentinel节点监控的主节点信息,发现主节点信息变成了6380端口的redis(之前的从节点)
Verification Whether the main node of redis changes
验证6380端口的redis变成主节点,此时我们在6380 的redis上设置一个key值,在6381端口的redis上验证是否能获取到该key值
此时发现,6380变成了主节点,6381从节点没有变化,还是从节点。 下面我再次启动6379端口的redis
发现原先的主节点6379已经变成了从节点,而它的主节点变成了6380。此时我们再回过头看下26379的监控节点变化,还是6380端口。
To this point sentinel That’s it for the introduction. Any shortcomings are welcome to be corrected.
The above is the detailed content of Redis Detailed Introduction to Sentinel. For more information, please follow other related articles on the PHP Chinese website!

Redis是现在最热门的key-value数据库,Redis的最大特点是key-value存储所带来的简单和高性能;相较于MongoDB和Redis,晚一年发布的ES可能知名度要低一些,ES的特点是搜索,ES是围绕搜索设计的。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了关于redis的一些优势和特点,Redis 是一个开源的使用ANSI C语言编写、遵守 BSD 协议、支持网络、可基于内存、分布式存储数据库,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了Redis Cluster集群收缩主从节点的相关问题,包括了Cluster集群收缩概念、将6390主节点从集群中收缩、验证数据迁移过程是否导致数据异常等,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了Redis实现排行榜及相同积分按时间排序,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了关于原子操作中命令原子性的相关问题,包括了处理并发的方案、编程模型、多IO线程以及单命令的相关内容,下面一起看一下,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了bitmap问题,Redis 为我们提供了位图这一数据结构,位图数据结构其实并不是一个全新的玩意,我们可以简单的认为就是个数组,只是里面的内容只能为0或1而已,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了Redis实现排行榜及相同积分按时间排序,本文通过实例代码给大家介绍的非常详细,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了关于实现秒杀的相关内容,包括了秒杀逻辑、存在的链接超时、超卖和库存遗留的问题,下面一起来看一下,希望对大家有帮助。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
