前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >monit介绍和配置 原

monit介绍和配置 原

作者头像
拓荒者
修改2019-04-23 17:39:26
7030
修改2019-04-23 17:39:26
举报
文章被收录于专栏:运维经验分享运维经验分享

1.介绍

    monit监控和管理进程、程序、文件、目录和Unix系统的文件的工具。可以进行自动维护和修理,在错误的情况下执行有意义的因果关系的行动。比如,某个进程没有运行启动它;没有响应重启它;占用太多资源停止该进程等等。也可以用来监控文件、目录或系统文件的变化,如时间戳的改变,检验和的改变或大小的改变

2.安装:(需先装epel源)

    yum install monit -y  

 3.配置

    3.1 monit 的配置文件monit.conf

        set daemon  30   监控检查的时间间隔

         set logfile syslog   默认日志为syslog,还可以设置为自定义路径下的文件

        set pidfile /var/run/monit.pid  设置pid文件的位置        

        set idfile /var/.monit.id  设置监控项目唯一ID的文件位置  默认在$HOME/.monit.id

        set statefile /var/.monit.state    默认存储每个周期内monitorinig 状态的文件

         set mailserver   mail.bar.baz    主的邮件服务器

                              backup.bar.baz port 10025    备的邮件服务器

mailserver 支持格式为:

SET MAILSERVER <hostname|ip-address [PORT number] [USERNAME string] [PASSWORD string] [using SSLAUTO|SSLV2|SSLV3|TLSV1|TLSV11|TLSV12] [CERTMD5 checksum]>, ...

                [with TIMEOUT X SECONDS]

                [using HOSTNAME hostname]

    set eventqueue         #默认当邮件服务器不可用时使用eventqueue存储报警事件

         basedir /var/monit  

         slots 100            #限制队列大小

 set mail-format {     设置邮件告警的格式

      from: monit@$HOST

   subject: monit alert --  $EVENT $SERVICE

   message: $EVENT Service $SERVICE

               Date:        $DATE

                Action:      $ACTION

                Host:        $HOST

                 Description: $DESCRIPTION

           Your faithful employee,

          Monit

}

set alert sysadm@foo.bar   设置接收告警的邮箱

以上是全局的配置,具体的services监控语法后面会介绍

   3.2  进程监控

        在 /etc/monit.d/下创建 nginx ,,并重启monit。内容如下

代码语言:javascript
复制
check process nginx with pidfile /usr/local/xywy/nginx/run/nginx.pid
start program = "/usr/local/xywy/nginx/sbin/nginx" with timeout 30 seconds
stop program = "/usr/local/xywy/nginx/sbin/nginx -s stop"

    3.3 监控文件

        在/etc/monit.d/下创建monit_test ,并重启monit,内容如下

代码语言:javascript
复制
check file monit.conf path /etc/monit.conf
group system
if changed sha1 checksum
then exec "/usr/local/bin/monit -c /etc/monit.conf reload"

  3.4  监控文件设备

代码语言:javascript
复制
check device VAR_LOG with path /var/log
if space usage > 85% then alert

check filesystem tmpfs with path /var
if space usage > 80% then alert

下面是配置综合案例

复制代码
复制代码
代码语言:javascript
复制
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 port 22 protocol ssh then restart
   if 5 restarts within 5 cycles then timeout

check process mysql with pidfile /var/run/mysqld/mysqld.pid
   group database
   start program = "/etc/init.d/mysqld start"
   stop program = "/etc/init.d/mysqld stop"
   if failed host 127.0.0.1 port 3306 then restart
   if 5 restarts within 5 cycles then timeout

 check process nginx with pidfile /var/run/nginx.pid
    start program = "/etc/init.d/nginx start"
    stop program  = "/etc/init.d/nginx stop"
    if failed host www.vpsee.com port 80 protocol http
       then restart

 check process php_cgi with pidfile /var/run/php_cgi.pid
    start program = "/etc/init.d/php_cgi start"
    stop program  = "/etc/init.d/php_cgi stop"
    if failed host 127.0.0.1 port 9000 then restart
    if 5 restarts within 5 cycles then timeout

check process apache with pidfile /var/run/httpd.pid
   group www
   start program = "/etc/init.d/httpd start"
   stop program  = "/etc/init.d/httpd stop"
   if failed host www.vpsee.com port 8080 protocol http
      then restart
   if cpu is greater than 80% for 2 cycles then alert
   if cpu > 80% for 5 cycles then restart
   if totalmem > 512 MB for 5 cycles then restart
   if children > 200 then restart
   if loadavg(5min) greater than 10 for 8 cycles then stop
   if 3 restarts within 5 cycles then timeout
复制代码
复制代码

3.5 monit命令使用

-c  指定配置文件

-d  后台运行

-l    指定logfile

-p  指定pid file

-s  指定statefile

<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
SSL 证书
腾讯云 SSL 证书(SSL Certificates)为您提供 SSL 证书的申请、管理、部署等服务,为您提供一站式 HTTPS 解决方案。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档