redis哨兵常用命令和监控示例详解

 更新时间:2021年05月26日 16:54:20   作者:knowledge-is-power  
哨兵模式是一种特殊的模式,首先Redis提供了哨兵的命令,哨兵是一个独立的进程,作为进程,它会独立运行,接下来通过本文给大家讲解redis哨兵常用命令和监控知识,感兴趣的朋友一起学习吧

sentinel monitor advertise 192.168.0.5 28001 2
sentinel set advertise client-reconfig-script /etc/redis/reconfig.sh
sentinel flushconfig

sentinel启动后需要手动将配置文件对应的调整为sentinel deny-scripts-reconfig no,否则不支持命令行runtime修改client-reconfig-script
# SECURITY
#
# By default SENTINEL SET will not be able to change the notification-script
# and client-reconfig-script at runtime. This avoids a trivial security issue
# where clients can set the script to anything and trigger a failover in order
# to get the program executed.

#sentinel deny-scripts-reconfig yes

role命令
查看sentinel monitor的master names名字

sentinel masters
查看所有监控master及其配置信息

sentinel master monitor_name
查看指定监控master及其配置信息

sentinel failover monitor_name
手动进行swithover切换主从,如果有多个slave会选择哪个slave做为新的master,待测试?

sentinel moniotr <name> <ip> <port> <quorum>
添加监视的master

sentinel remove monitor_name
将监视的为name的master移除监视

sentinel set <mastername> [<option> <value>]
修改监视的master的一些属性
down-after-milliseconds 过了这个时间考虑master go down
failover-timeout 刷新故障转移状态的最大时间
parallel-syncs slave同时reconfigure的个数
notification-script 设置通知脚本
client-reconfig-script 设置通知脚本
auth-pass 执行auth的密码
quorum 修改master的quorum

sentinel flushconfig

将sentinel信息写入到配置文件中

sentinel配置文件示例:

daemonize yes
pidfile "/home/redis/sentinel/25000/redis.pid"
loglevel notice
protected-mode yes
bind 192.168.100.5
logfile "/home/redis/sentinel/25000/redis.log"
port 25000
dir "/home/redis/sentinel/25000"
# Generated by CONFIG REWRITE
sentinel myid 0338c4ceb7cf39a8037a22fa17d0f7a76923b5a0
sentinel deny-scripts-reconfig no
sentinel monitor advertise 192.168.100.5 28001 2
sentinel client-reconfig-script advertise /etc/redis/reconfig.sh
sentinel config-epoch advertise 4
sentinel leader-epoch advertise 4
sentinel known-replica advertise 192.168.100.6 28001
sentinel known-sentinel advertise 192.168.100.7 25000 06f937e1d35496dc66d2899e3b25e286ff91d658
sentinel known-sentinel advertise 192.168.100.6 25000 ede86ac0b7d2ff7b532d0e5352ba6e33dd36670e
 
sentinel monitor mymaster1 192.168.100.6 28002 2
sentinel client-reconfig-script mymaster1 /etc/redis/reconfig.sh
sentinel config-epoch mymaster1 5
sentinel leader-epoch mymaster1 1
sentinel known-replica mymaster1 192.168.100.5 28002
sentinel known-sentinel mymaster1 192.168.100.7 25000 06f937e1d35496dc66d2899e3b25e286ff91d658
sentinel known-sentinel mymaster1 192.168.100.6 25000 ede86ac0b7d2ff7b532d0e5352ba6e33dd36670e
sentinel current-epoch 5

sentinel client-reconfig-script脚本示例

#!/bin/bash
 
check_time=$(date +"%F-%T")
master_name="$1"
from_ip="$4"
from_port="$5"
to_ip="$6"
to_port="$7"
 
 
#填写自己正确的机器人链接
curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxx' \
   -H 'Content-Type: application/json' \
   -d '
   {
        "msgtype": "text",
        "text": {
            "content": "【'$check_time' '$master_name' redis failover】\nfrom\n'$from_ip:$from_port'\nto\n'$to_ip:$to_port'",
            "mentioned_list":["xiaodongl"]
        }
   }'

以上就是redis哨兵常用命令和监控的详细内容,更多关于redis哨兵常用命令的资料请关注脚本之家其它相关文章!

相关文章

  • 深度解析Redis 数据淘汰策略

    深度解析Redis 数据淘汰策略

    本文将深入剖析8种淘汰策略的机制,并结合Java代码演示生产环境的最佳实践,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习吧
    2025-04-04
  • redis调用二维码时的不断刷新排查分析

    redis调用二维码时的不断刷新排查分析

    这篇文章主要为大家介绍了redis调用二维码时不断刷新排查分析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步早日升职加薪
    2022-04-04
  • 排查Redis大key的方法总结

    排查Redis大key的方法总结

    这篇文章主要介绍了排查Redis大key的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面跟着小编来一起学习学习吧
    2024-08-08
  • 深入理解Redis被覆写后的失效时间

    深入理解Redis被覆写后的失效时间

    Redis覆写已存在的键会导致其旧的失效时间被新的键值对所取代,本文详细解析了在键被覆写时,其失效时间的变化,具有一定的参考价值,感兴趣的可以了解一下
    2024-09-09
  • Redis高性能Key-Value存储与缓存利器常见解决方案

    Redis高性能Key-Value存储与缓存利器常见解决方案

    Redis是高性能内存Key-Value存储系统,支持丰富数据类型与持久化方案(RDB/AOF),本文给大家介绍Redis高性能Key-Value存储与缓存利器常见解决方案,感兴趣的朋友一起看看吧
    2025-09-09
  • 拦截Redis命令导致的Lua脚本执行失败的问题解决

    拦截Redis命令导致的Lua脚本执行失败的问题解决

    本文主要介绍了拦截Redis命令导致的Lua脚本执行失败的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-06-06
  • 使用Spring Boot实现Redis键过期回调功能示例详解

    使用Spring Boot实现Redis键过期回调功能示例详解

    这篇文章主要介绍了使用Spring Boot实现Redis键过期回调功能,就是一个实现Redis键过期回调功能的Spring Boot应用的示例,代码简单易懂,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-07-07
  • Redis实现布隆过滤器的代码详解

    Redis实现布隆过滤器的代码详解

    布隆过滤器(Bloom Filter)是Redis 4.0版本提供的新功能,它被作为插件加载到Redis服务器中,给Redis提供强大的去重功能,本文将给大家详细介绍一下Redis布隆过滤器,文中有相关的代码示例,需要的朋友可以参考下
    2023-07-07
  • springboot +redis 实现点赞、浏览、收藏、评论等数量的增减操作

    springboot +redis 实现点赞、浏览、收藏、评论等数量的增减操作

    这篇文章主要介绍了springboot +redis 实现点赞、浏览、收藏、评论等数量的增减操作,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-09-09
  • 详解Redis的慢查询日志

    详解Redis的慢查询日志

    这篇文章主要介绍了Redis的慢查询日志的相关资料,帮助大家更好的理解和学习Redis数据库,感兴趣的朋友可以了解下
    2020-08-08

最新评论