• 简单的Redis及哨兵监控报警


    简单的Redis及哨兵监控报警

     前段时间给第三方客户部署了redis主从+读写分离+哨兵的集群,需要简单配置一个报警(毕竟人家服务器不好意思装zabbix)

    一、配置Linux服务器从第三方 SMTP 服务器外发邮件

    1、确保postfix服务运行

    # systemctl status postfix

    2、安装mailx

    # yum install -y mailx

    3、配置smtp服务器

        修改/etc/mail.rc文件,在文件中添加以下内容
    # vim /etc/mail.rc
    set from=user_sunli@sina.com
    set smtp=smtp.sina.com
    set smtp-port=465
    set smtp-auth-user=user_sunli@sina.com
    set smtp-auth-password=xxxxxxxxxxxx
    set smtp-auth=login
     

    4、测试

    # echo "邮件内容" |mail -s "邮件标题" 公网邮箱
    # echo "hello" |mail -s "hehehe" sunli@bdszh.vip
     

    二、监控脚本及定时任务

    安装nc

    yum -y install nc

    编写脚本

    vim /data/scripts/redis_mail.sh
    #!/bin/bash
    local_ip=`hostname -I|awk '{print $1}'`
    netstat -tnlp|grep 56379
    [ `echo $?` != 0 ] && systemctl restart redis.service && echo "Please check $local_ip redis " |mail -s "redis is down" sunli@bdszh.vip
    netstat -tnlp|grep 46379
    [ `echo $?` != 0 ] && systemctl restart sentinel.service && echo "Please check $local_ip sentinel " |mail -s "sentinel is down" sunli@bdszh.vip
    nc -zvw3 10.0.36.132 56379
    [ `echo $?` != 0 ] && ansible 10.0.36.132 -m systemd -a "name=redis state=restarted" && echo "Please check 10.0.36.132 redis " |mail -s "redis is down" sunli@bdszh.vip
    nc -zvw3 10.0.36.132 46379
    [ `echo $?` != 0 ] && ansible 10.0.36.132 -m systemd -a "name=sentinel state=restarted" && echo "Please check 10.0.36.132 sentinel " |mail -s "sentinel is down" sunli@bdszh.vip
    nc -zvw3 10.0.36.134 56379
    [ `echo $?` != 0 ] && ansible 10.0.36.134 -m systemd -a "name=redis state=restarted" && echo "Please check 10.0.36.134 redis " |mail -s "redis is down" sunli@bdszh.vip
    nc -zvw3 10.0.36.134 46379
    [ `echo $?` != 0 ] && ansible 10.0.36.134 -m systemd -a "name=sentinel state=restarted" && echo "Please check 10.0.36.134 sentinel " |mail -s "sentinel is down" sunli@bdszh.vip
     

     定时任务

    在linux中 crontab的最小执行单位是分钟,没法直接实现单位秒的运行,所以得通过其他方式来处理。
    思路:假如每5秒运行一次,那就运行一次后睡眠5秒,5秒后再睡眠5秒,依次类推
    # crontab -e
    */1 * * * *           /bin/bash -x /data/scripts/redis_mail.sh > /dev/null 2>&1
    */1 * * * * sleep 5;  /bin/bash -x /data/scripts/redis_mail.sh > /dev/null 2>&1
    */1 * * * * sleep 10; /bin/bash -x /data/scripts/redis_mail.sh > /dev/null 2>&1
    */1 * * * * sleep 15; /bin/bash -x /data/scripts/redis_mail.sh > /dev/null 2>&1
    */1 * * * * sleep 20; /bin/bash -x /data/scripts/redis_mail.sh > /dev/null 2>&1
    */1 * * * * sleep 25; /bin/bash -x /data/scripts/redis_mail.sh > /dev/null 2>&1
    */1 * * * * sleep 30; /bin/bash -x /data/scripts/redis_mail.sh > /dev/null 2>&1
    */1 * * * * sleep 35; /bin/bash -x /data/scripts/redis_mail.sh > /dev/null 2>&1
    */1 * * * * sleep 40; /bin/bash -x /data/scripts/redis_mail.sh > /dev/null 2>&1
    */1 * * * * sleep 45; /bin/bash -x /data/scripts/redis_mail.sh > /dev/null 2>&1
    */1 * * * * sleep 50; /bin/bash -x /data/scripts/redis_mail.sh > /dev/null 2>&1
    */1 * * * * sleep 55; /bin/bash -x /data/scripts/redis_mail.sh > /dev/null 2>&1

    三、模拟故障情况

    自行停止redis或者哨兵

     
     
     
     
  • 相关阅读:
    struts 数据验证指定方法(使用xml文件)
    struts2.0简单页面 (不带拦截器和带拦截器案例)
    tomcat启动流程 和 struts 详解
    代理类Proxy------ WeakHashMap----ReferenceQueue---- Reference
    java 文件上传 struts2.0实现
    java struts xml文件设置----自定义日期转换器(局部,及全局类型转换器类)
    java request,response解析及中文编码 , jsp注释 xml中文编码,getsession()使用方法
    java jsp自定义标签
    Java 通讯录contact
    [Machine Learning for Trading] {ud501} Lesson 3: 01-02 Working with multiple stocks
  • 原文地址:https://www.cnblogs.com/user-sunli/p/14755797.html
Copyright © 2020-2023  润新知