zoukankan      html  css  js  c++  java
  • monit 监控并自动重启服务

    Monit是一款功能非常丰富的进程、文件、目录和设备的监测软件,用于Unix平台。 它可以自动修复那些已经停止运作的程序,特使适合处理那些由于多种原因导致的软件错误。monit运行于应用层
    安装很简单,三部曲
    #./configure
    #make
    #make install
     
    复制配置文件
    # cp monitrc /etc/monitrc
     
    接下来我们根据实际情况来修改这个配置文件
    set daemon 120 # Poll at 2-minute intervals//每2分钟检查一次
    set logfile /home/monit/log/monit.log          //monit的日志文件
    set alert zhouwei@chinabank.com.cn with reminder on 1 cycle  //出现1次错误的时候发报警邮件到指定的邮箱
    #set mailserver mail.tildeslash.com, mail.foo.bar port 10025, localhost with tim
    eout 15 seconds
    set mailserver 10.10.9.109    //设置邮件服务器
    set httpd port 2812 and use address 10.10.8.2 //设置http监控页面的端口和ip
        allow localhost   # Allow localhost to connect //允许本机访问
        allow 10.10.8.0/24                                            //允许此IP段访问
        allow admin:nishiwode # Allow Basic Auth   //认证的用户名和密码
    # all system                                                         //平均负载.内存使用率,cpu使用率
    check system 10.10.8.2
       if loadavg (1min) > 4 then alert
       if loadavg (5min) > 2 then alert
       if memory usage > 75% then alert
       if cpu usage (user) > 70% then alert
       if cpu usage (system) > 30% then alert
       if cpu usage (wait) > 20% then alert
    # all disk                                                              //磁盘空间使用率
    check device data with path /dev/sda2
       if space usage > 90% then alert
       if inode usage > 85% then alert
    check device home with path /dev/sda3
       if space usage > 85% then alert
       if inode usage > 85% then alert
    # all rsync
    #10.10.8.2
    check process sshd with pidfile /var/run/sshd.pid
    start program "/etc/init.d/sshd start"
    stop program "/etc/init.d/sshd stop"
    if failed host 127.0.0.1 port 22 protocol ssh then restart
    if 5 restarts within 5 cycles then timeout
    //监控ssh服务
    check process httpd with pidfile /var/run/httpd.pid
    group apache
    start program = "/etc/init.d/httpd start"
    stop program = "/etc/init.d/httpd stop"
    if failed host 127.0.0.1 port 80
    protocol http then restart
    if 5 restarts within 5 cycles then timeout
    //监控http服务
    
    //监控自定义服务
    check process web_lb with pidfile /data/v20/server/web_lb/httpd.pid
        start program = "/data/v20/bin/lb.sh"  //启动脚本
        stop  program = "/data/v20/bin/lb_stop.sh" //停止脚本
        if failed host 10.10.8.2 port 16101 proto http then restart
        if failed host 10.10.8.2 port 16101 proto http for 5 times within 5 cycles t
    hen exec "/data/v20/bin/lb_pay.sh"
        if failed host 10.10.8.2 port 16102 type TCPSSL proto http then restart
        if failed host 10.10.8.2 port 16102 type TCPSSL proto http for 5 times withi
    n 5 cycles then exec "/data/v20/bin/lb_pay.sh
    
    RHEL可以用如下方法启动monit
    # vi /etc/inittab
    添加:
    mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc
    Now start monit:
    # init -q或者# telinit -q
    You can verify that monit is started from /var/log/message log file:
    # tail -f /var/log/message
    如果正常启动能看到如下输出: 
    Nov 21 04:39:21 server monit[8759]: Starting monit daemon
    Nov 21 04:39:21 server monit[8759]: Monit started
    

      

    实际应用:

    yum install -y monit EOF # add by zhangzizhao cat > /etc/monitrc << EOF set daemon 30 set logfile syslog facility log_daemon set pidfile /var/run/monit.pid set httpd port 30000 allow 127.0.0.1 check process tangible with pidfile /tangible_dev/tangible.pid start program "/tangible_dev/tangible" stop program "/bin/bash -c '/usr/bin/kill -9 \`/bin/cat /tangible_dev/tangible.pid\`'" EOF monit -d 1 monit start tangible

      

  • 相关阅读:
    GTK+ 3.6.2 发布,小的 bug 修复版本
    RunJS 新增 Echo Ajax 测试功能
    Mozilla 发布 Popcorn Maker,在线创作视频
    Sina微博OAuth2框架解密
    Mina状态机State Machine
    Mozilla 发布 Shumway —— 纯JS的SWF解析器
    Code Browser 4.5 发布,代码浏览器
    ROSA 2012 "Enterprise Linux Server" 发布
    ltrace 0.7.0 发布,程序调试工具
    Artifactory 2.6.5 发布,Maven 扩展工具
  • 原文地址:https://www.cnblogs.com/8899man/p/5363257.html
Copyright © 2011-2022 走看看