Redis Sentinel--运维管理

本文涉及的产品
云数据库 Redis 版,标准版 2GB
推荐场景:
搭建游戏排行榜
云原生内存数据库 Tair,内存型 2GB
简介: 上一篇博客我们介绍了Redis Sentinel的安装配置,详情可参考链接:Redis Sentinel--安装配置,今天主要做几个简单的测试CaseRedis Sentinel APIping 正常会返回pongsentinel masters  返回被监视的所有...

上一篇博客我们介绍了Redis Sentinel的安装配置,详情可参考链接:Redis Sentinel--安装配置,今天主要做几个简单的测试Case


Redis Sentinel API

ping 正常会返回pong
sentinel masters  返回被监视的所有master及状态
sentinel master <master name> 返回指定的master及状态
setntinel slaves <master name> 返回slave及状态
sentinel sentinels <master name> 返回sentinel及状态
sentinel get-master-addr-by-name mymaster 返回现在的master IP和Port
sentinel reset * 清理已经移除的master-slave或者sentinel信息
sentinel failover <master name>手动执行故障转移
sentinel ckquorum <master name> 返回(OK 3 usable Sentinels. Quorum and failover authorization can be reached)
sentinel flushconfig 如果sentinel.conf丢失,可以使用这个命令生成新的配置文件


添加Sentinel

增加一个sentinel很简单,直接配置好sentinel.conf文件,开启一个sentinel即可;

添加时最好一个添加结束后,再添加另外一个,不要同时添加,可以每隔30秒添加一个sentinel;

通过SENTINEL MASTER mastername中的num-other-sentinels来查看是否成功添加sentinel。


[root@sht-sgmhadoopdn-04 redis]# cat sentinel.conf
daemonize yes
port 26379
logfile "sentinel.log"
dir "/usr/local/redis"
protected-mode no
sentinel myid 79393e76e002cb64db92fb8bcb88d79f2d85a82b
sentinel monitor mymaster 172.16.101.59 6379 2

[root@sht-sgmhadoopdn-04 redis]# src/redis-sentinel sentinel.conf

172.16.101.54:26379> sentinel master mymaster
33) "num-other-sentinels"
34) "3"


移除Sentinel

删除一个sentinel稍微复杂一点,sentinel永远不会删除一个已经存在过的sentinel,即使它已经与组织失去联系

Step:

(1) Stop the Sentinel process of the Sentinel you want to remove.


(2) Send a SENTINEL RESET * command to all the other Sentinel instances (instead of * you can use the exact master name if you want to reset just a single master). One after the other, waiting at least 30 seconds between instances.


(3) Check that all the Sentinels agree about the number of Sentinels currently active, by inspecting the output of SENTINEL MASTER mastername of every Sentinel.


[root@sht-sgmhadoopdn-04 redis]# ps -ef|grep redis
root     17510     1  0 18:34 ?        00:00:03 src/redis-sentinel *:26379 [sentinel]
[root@sht-sgmhadoopdn-04 redis]# kill -9 17510

在其他的每个sentinel节点上,每个隔30s执行

172.16.101.54:26379> sentinel reset *
172.16.101.55:26379> sentinel reset *
172.16.101.56:26379> sentinel reset *
172.16.101.54:26379> sentinel master mymaster
33) "num-other-sentinels"
34) "2"


移除一个老的master或不可用的slave

[root@sht-sgmhadoopdn-01 redis]# ps -ef|grep redis
root     15261     1  0 Aug05 ?        00:05:55 src/redis-server 172.16.101.58:6379
root     19768 19394  0 21:09 pts/2    00:00:00 grep --color=auto redis
[root@sht-sgmhadoopdn-01 redis]# kill -9 15261
172.16.101.54:26379> sentinel masters
   31) "num-slaves"
   32) "2"


在每个sentinel节点上,每个隔30s执行

172.16.101.54:26379> sentinel reset mymaster
172.16.101.55:26379> sentinel reset mymaster
172.16.101.56:26379> sentinel reset mymaster

172.16.101.54:26379> sentinel masters
   31) "num-slaves"
   32) "1"



相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
4月前
|
NoSQL Java Redis
SpringBoot2.0整合Redis高可用之Sentinel哨兵
本篇博文分享的是一主二从三哨兵模式。至于为什么用三个哨兵,同第一段。本文是模拟环境,都是一个服务器上面。
209 0
|
3月前
|
运维 监控 NoSQL
Redis Sentinel哨兵模式部署
Redis Sentinel哨兵模式部署
83 2
|
20天前
|
运维 监控 NoSQL
【Redis】哨兵(Sentinel)原理与实战全解~炒鸡简单啊
Redis 的哨兵模式(Sentinel)是一种用于实现高可用性的机制。它通过监控主节点和从节点,并在主节点故障时自动进行切换,确保集群持续提供服务。哨兵模式包括主节点、从节点和哨兵实例,具备监控、通知、自动故障转移等功能,能显著提高系统的稳定性和可靠性。本文详细介绍了哨兵模式的组成、功能、工作机制以及其优势和局限性,并提供了单实例的安装和配置步骤,包括系统优化、安装、配置、启停管理和性能监控等。此外,还介绍了如何配置主从复制和哨兵,确保在故障时能够自动切换并恢复服务。
|
4月前
|
监控 NoSQL Redis
Redis - 主从复制那些事与高可用sentinel
Redis - 主从复制那些事与高可用sentinel
55 0
|
4月前
|
监控 NoSQL 程序员
Redis 高可用篇:你管这叫 Sentinel 哨兵集群原理
Redis 高可用篇:你管这叫 Sentinel 哨兵集群原理
109 5
|
4月前
|
NoSQL Linux Redis
Redis 6.X Sentinel 哨兵集群搭建
Redis 6.X Sentinel 哨兵集群搭建
63 5
|
9月前
|
NoSQL Redis Docker
使用bitnamiredis-sentinel部署Redis 哨兵模式
使用bitnamiredis-sentinel部署Redis 哨兵模式
367 0
|
监控 NoSQL Redis
|
监控 NoSQL Redis
基于Docker的Redis高可用集群搭建(redis-sentinel)
前言   之前介绍了用docker来搭建redis主从环境,但这只是对数据添加了从库备份(主从复制),当主库down掉的时候,从库是不会自动升级为主库的,也就是说,该redis主从集群并非是高可用的。
7502 1
|
NoSQL 数据可视化 Redis
Redis高可用Sentinel哨兵模式环境搭建
Redis高可用Sentinel哨兵模式环境搭建
469 0