监控☞monit

阅读量: zyh 2020-09-27 14:27:54
Categories: > Tags:

安装

yum install monit -y

主配置

# vim /etc/monitrc
set daemon  10 # 调整周期

⭐️官方配置文档: https://mmonit.com/monit/documentation/monit.html

程序保活配置

默认存放位置: /etc/monit.d/

这里以 pidfile 检测方式为例

nginx的配置:

check process nginx with pidfile /var/run/nginx.pid
  start program = "/usr/sbin/nginx"
  stop program = "/usr/bin/killall nginx"
if changed pid then alert

上述nginx配置的意思:

  1. 检测方式: pidfile

  2. 开关程序路径

  3. 发现pid改变,则触发动作: 预警

tomcat的配置:

check process tomcat-8080 with pidfile /opt/tomcat/tomcat-8080/bin/tomcat.pid
  start program = "/usr/bin/bash /opt/tomcat/tomcat-8080/bin/startup.sh"
    as uid "root" and gid "root"
  stop program = "/usr/bin/ps aux | /usr/bin/grep '/opt/tomcat/tomcat-8080/bin/bootstrap.jar' | /usr/bin/awk '{print "kill -9 "$2}' | /usr/bin/bash"
    as uid "root" and gid "root"
if failed port 8080 then alert

上述tomcat配置的意思:

  1. 检测方式: pidfile
  2. 开关程序路径, 并且执行的时候需要以 root 权限执行
  3. 发现 8080 不通, 则触发动作: 预警

🌟需要注意的是, 所有的文件路径都需要是绝对路径, 包括命令.

启动/关闭

systemctl start/stop/reload monit

🌟当monit启动之后, 它就会加载保活配置, 并进行检测.

日志

/var/log/monit.log