zoukankan      html  css  js  c++  java
  • 简单的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或者哨兵

     
     
     
     
  • 相关阅读:
    iphone数据存储之-- Core Data的使用
    Object-c 中的数据类型
    Object-C 中各数据类型转换 NSData转NSString,Byte,UIImage
    iOS开发系列--Objective-C之KVC、KVO
    【C语言】-返回指针的函数与指向函数的指针
    【C语言】-指向一维数组元素的指针
    【C语言】-指针和字符串
    【C语言】-指针
    OC总结 【OC基础语法相关知识】
    swift与OC混编之调用函数
  • 原文地址:https://www.cnblogs.com/user-sunli/p/14755797.html
Copyright © 2011-2022 走看看