欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

monit 详细配置(monitrc)

最编程 2024-03-01 18:19:42
...

monitrc是Monit的主配置文件(控制文件)。
monitrc的内容主要分为全局(golbal)和服务(services)两个部分。
默认情况下monitrc文件在/etc/monit目录下。

###############################################################################
## 配置内容书写规范
###############################################################################
# 注释以“#”开头并延伸到行尾
# 关键字不区分大小写
# 所有路径必须完全限定路径,以“/”开头

###############################################################################
## Global section 全局部分
###############################################################################
  set daemon 120
  # 设置以守护进程的方式运行Monit,每隔2分钟检查一次服务
  #   with start delay 240    
  # 第一次启动时延迟检查4分钟(默认情况下,Monit启动后立即进行检查)
  set logfile /var/log/monit.log
  # 设置系统日志记录。如果要改为记录到独立的日志文件,请指定日志文件的完整路径
  # set pidfile /var/run/monit.pid
  # 设置Monit实例的PID文件路径,PID文件记录了Monit实例进程的进程编号(PID),默认情况下,文件放置在
  # $HOME/.monit.pid
  set idfile /var/lib/monit/id
  # 设置Monit实例的id文件路径。id文件记录了Monit实例的唯一ID(标识),id在第一次Monit启动时生成并存储。默# 认情况下,文件放置在$HOME/.monit.id
  set statefile /var/lib/monit/state
  # 设置在每个周期中保存监视状态的Monit状态文件的位置。默认情况下,文件放在$HOME/.monit.state. 如果状态文
  # 件存储在持久文件系统中,Monit在重新启动时将恢复监视状态。如果它在临时文件系统上,状态将在重新启动时丢
  # 失。

  # set limits {
  #     programOutput:     512 B,      # 检查程序输出截断限制
  #     sendExpectBuffer:  256 B,      # send/expect协议测试限制
  #     fileContentBuffer: 512 B,      # 文件内容缓冲区限制
  #     httpContentBuffer: 1 MB,       # HTTP内容缓冲区限制
  #     networkTimeout:    5 seconds   # 网络I/O超时限制
  #     programTimeout:    300 seconds # 检查程序超时限制
  #     stopTimeout:       30 seconds  # 服务停止超时限制
  #     startTimeout:      30 seconds  # 服务启动超时限制
  #     restartTimeout:    30 seconds  # 服务重启超时限制
  # }
  # 设置各种限制。以上示例显示了默认值。

  # set ssl {
  #     verify     : enable, # 验证SSL证书(默认禁用,但强烈建议)
  #     selfsigned : allow   # 允许自签名SSL证书(默认情况下拒绝)
  # }
  # 设置全局SSL选项

  # set mailserver mail.bar.baz,               # 主邮件服务器
  #                backup.bar.baz port 10025,  # 备邮件服务器 on port 10025
  #                localhost                   # 如果没有邮件服务器就将警报发送到本地
  # 设置要传递警报的邮件服务器列表。可以使用逗号分隔符指定多个服务器。如果第一个邮件服务器发生故障,Monit
  # 将使用列表中的第二个邮件服务器,依此类推。默认情况下,Monit可以使用port选项覆盖它

  set eventqueue
      basedir /var/lib/monit/events # 设置存储事件的基本目录
      slots 100                     # 可选择限制队列大小
  # 默认情况下,如果没有可用的邮件服务器,Monit将删除警报事件。如果要保留警报以便以后重试传递,可以使
  # 用"eventqueue"语句。存储未送达警报的基本目录由"basedir"选项指定。您可以使用"slots"选项来限制队列大小
  # (如果省略,队列将受到后端文件系统中可用空间的限制)

  # set mmonit http://monit:monit@192.168.1.10:8080/collector
  #     # with timeout 30 seconds              # 默认超时5秒
  #     # and register without credentials     # 不注册凭据
  # 设置与M/Monit通信,向M/Monit发送状态和事件(有关M/Monit的更多信息,请参阅http://mminit.com/). 默认情
  # 况下,Monit使用M/Monit注册凭据,以便M/Monit可以顺利地与Monit通信,并且您不必在M/Monit中手动注册Monit
  # 凭据。可以使用下面的注释掉选项禁用凭证注册。但是,如果安全是一个问题,我们建议在与M/Monit通信时使用
  # https,并加密发送凭据。一般不使用。

  # 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
  # }
  # 设置邮件格式,默认情况下,如果缺少邮件格式"mail-format"语,Monit将使用以上格式发送警报。

  # set alert sysadm@foo.bar                                     # 接受所有警报
  # set alert your-name@your.domain not on { instance, action }  # 不接受筛选器{}中的的警报
  # 设置警报关联的邮箱和筛选器,如果不设置任何筛选器则关联邮箱接受所有警报。
  # 当Monit启动、停止或执行用户启动的操作时,不要发出警报。建议使用上面第二个筛选器,以避免在一般情况下收
  # 到警报。

  # set httpd port 2812 and
  #     use address localhost  # 仅接受本地主机的连接
  #     allow localhost        # 允许从localhost访问HTTP接口
  #     allow admin:monit      # 当管理者通过WEB访问时,需要使用账号密码验证身份"admin:monit"
  # Monit有一个嵌入式HTTP接口,可用于从WEB界面查看所监视服务的状态和管理服务。如果要从命令行发出Monit命
  # 令,例如“monit status”或“monit restart service”,则也需要HTTP接口。原因是Monit客户端使用HTTP接口
  # 将这些命令发送到正在运行的Monit守护程序。如果要为HTTP接口启用SSL,请参阅monitwiki。

###############################################################################
## Services 服务部分
###############################################################################
# 以下是一些配置示例。

  #  check system $HOST
  #    if loadavg (1min) > 4 then alert
  #    if loadavg (5min) > 2 then alert
  #    if cpu usage > 95% for 10 cycles then alert
  #    if memory usage > 75% then alert
  #    if swap usage > 25% then alert
  # 检查一般系统资源,如平均负载、cpu和内存使用情况。每个测试都指定一个资源、条件和测试失败时要执行的操
  # 作。

  #  check file apache_bin with path /usr/local/apache/bin/httpd
  #    if failed checksum and 
  #       expect the sum 8f7f419955cefa0b33a2ba316cba3659 then unmonitor
  #    if failed permission 755 then unmonitor
  #    if failed uid root then unmonitor
  #    if failed gid root then unmonitor
  #    alert security@foo.bar on {
  #           checksum, permission, uid, gid, unmonitor
  #        } with the mail-format { subject: Alarm! }
  #    group server
  # 检查文件是否存在、校验和、权限、uid和gid。除了全局部分中的警报收件人外,还可以通过指定本地警报处理程
  # 序将自定义警报发送到其他收件人。可以使用GROUP选项对服务进行分组。可以通过重复“group name”语句指定多
  # 个组。

  #  check process apache with pidfile /usr/local/apache/logs/httpd.pid
  #    start program = "/etc/init.d/httpd start" with timeout 60 seconds
  #    stop program  = "/etc/init.d/httpd stop"
  #    if cpu > 60% for 2 cycles then alert
  #    if cpu > 80% for 5 cycles then restart
  #    if totalmem > 200.0 MB for 5 cycles then restart
  #    if children > 250 then restart
  #    if loadavg(5min) greater than 10 for 8 cycles then stop
  #    if failed host www.tildeslash.com port 80 protocol http 
  #       and request "/somefile.html"
  #    then restart
  #    if failed port 443 protocol https with timeout 15 seconds then restart
  #    if 3 restarts within 5 cycles then unmonitor
  #    depends on apache_bin
  #    group server
  # 检查进程是否正在运行(在本例中为Apache),以及它是否响应HTTP和HTTPS请求。检查其资源使用情况,如cpu和
  # 内存,以及子进程的数量。如果进程没有运行,Monit将在默认情况下重新启动它。如果服务经常重新启动而问题仍
  # 然存在,可以使用"unmonitor"语句禁用监视。此服务依赖于上面定义的另一个服务(apache_bin)

  #  check filesystem datafs with path /dev/sdb1
  #    start program  = "/bin/mount /data"
  #    stop program  = "/bin/umount /data"
  #    if failed permission 660 then unmonitor
  #    if failed uid root then unmonitor
  #    if failed gid disk then unmonitor
  #    if space usage > 80% for 5 times within 15 cycles then alert
  #    if space usage > 99% then stop
  #    if inode usage > 30000 then alert
  #    if inode usage > 99% then stop
  #    group server
  # 检查文件系统权限、uid、gid、空间和inode使用情况。其他服务(如数据库)可能依赖于此资源,在文件系统变满
  # 和数据丢失之前,可能会向这些服务级联自动优雅的停止。

  #  check file database with path /data/mydatabase.db
  #    if failed permission 700 then alert
  #    if failed uid data then alert
  #    if failed gid data then alert
  #    if timestamp > 15 minutes then alert
  #    if size > 100 MB then exec "/my/cleanup/script" as uid dba and gid dba
  # 检查文件的时间戳。在这个例子中,我们测试一个文件是否超过15分钟,如果它没有被更新,我们会假设它有问
  # 题。另外,如果文件大小超过给定的限制,请执行脚本

  #  check directory bin with path /bin
  #    if failed permission 755 then unmonitor
  #    if failed uid 0 then unmonitor
  #    if failed gid 0 then unmonitor
  # 检查目录权限、uid和gid。如果目录不属于uid为0且gid为0的用户,则会触发事件。

  #  check host myserver with address 192.168.1.1
  #    if failed ping then alert
  #    if failed port 3306 protocol mysql with timeout 15 seconds then alert
  #    if failed port 80 protocol http
  #       and request /some/path with content = "a string"
  #    then alert
  # 通过发出ping测试检查远程主机的可用性,并检查来自web服务器的响应的内容。最多发送三个ping,并执行到端口
  # 的连接和应用程序级网络检查

  #  check network public with interface eth0
  #    if failed link then alert
  #    if changed link then alert
  #    if saturation > 90% then alert
  #    if download > 10 MB/s then alert
  #    if total upload > 1 GB in last hour then alert
  # 检查网络链路状态(上/下)、链路容量变化、饱和和带宽使用情况.

  #  check program myscript with path /usr/local/bin/myscript.sh
  #    if status != 0 then alert
  # 检查自定义程序状态输出,执行脚本"/usr/local/bin/myscript.sh",如果脚本执行完成后系统的状态值不等于0,
  # 则报警

###############################################################################
## Includes 附加部分
###############################################################################
# 可以使用"include"包含来自其他文件或目录的附加配置文件,将部分配置独立一个配置文件,便于管理。
   include /etc/monit/conf.d/*
   include /etc/monit/conf-enabled/*