如何设置monit.conf文件?Monit配置文件示例说明

Monit配置文件示例说明

本文是 LINUX 系统的 MONIT监控程序的配置文件示例说明,你只需修改域名、“xxx”、pidfile的路经,即可立即套用。

##
## 陈沩亮博客示例monit配置文件,说明:
## 1. 域名以www.etufo.org为例。
## 2. 后面带xxx的均是举例用的名字,需要根据自己的需要修改。
##
################################################## #############################
## Monit control file
################################################## #############################
#
# 检查周期,默认为2分钟,对于网站来说有点长,可以根据需要自行调节,这改成30秒。
set daemon 30

# 日志文件
set logfile /var/log/monit.log

#
# 邮件通知服务器
#
#set mailserver mail.example.com
set mailserver localhost

#
# 通知邮件的格式设置,下面是默认格式供参考
#
## Monit by default uses the following alert mail format:
##
## --8<--
## From: [email protected]$HOST # sender
## Subject: monit alert -- $EVENT $SERVICE # subject
##
## $EVENT Service $SERVICE #
## #
## Date: $DATE #
## Action: $ACTION #
## Host: $HOST # body
## Description: $DESCRIPTION #
## #
## Your faithful employee, #
## monit #
## --8<--
##
## You can override the alert message format or its parts such as subject
## or sender using the MAIL-FORMAT statement. Macros such as $DATE, etc.
## are expanded on runtime. For example to override the sender:
#
# 简单的,这只改了一下发送人,有需要可以自己修改其它内容。
set mail-format { from: [email protected] }

# 设置邮件通知接收者。建议发到gmail,方便邮件过滤。
set alert [email protected]

set httpd port 2812 and #设置http监控页面的端口
use address www.etufo.org # http监控页面的IP或域名
##allow localhost # 允许本地访问
##allow 203.82.90.239 # 允许指定IP访问
allow user:password # 访问用户名密码

################################################## #############################
## Services
################################################## #############################
#
# 系统整体运行状况监控,默认的就可以,可以自己去微调
#
# 系统名称,可以是IP或域名
#check system www.etufo.org
# 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
# 可选的ssl端口的监控,如果有的话
# if failed port 443 type tcpssl protocol http
# with timeout 15 seconds
# then restart

#
# 监控apache
#
check process apache with pidfile /usr/local/apache/logs/httpd.pid
start program = "/etc/init.d/httpd start"
stop program = "/etc/init.d/httpd stop"
if failed host www.etufo.org port 80 protocol http then restart
if 3 restarts within 5 cycles then timeout
group server

#
#mysql
#
check process mysql with pidfile /var/lib/mysql/centos-ufo.pid
#mysql系统进程的pidfile文件
start program = "/etc/init.d/mysqld start" 
stop program = "/etc/init.d/mysqld stop" 
if failed host localhost port 3306 for 3 times within 4 cycles then alert
#若在四个周期内,三次 3306(我的Mysql)端口都无法连通,则邮件通知
if 5 restarts within 5 cycles then timeout 
#
#监控mysql(1)
#

Monit监控配置Apache和监控MySQL,需要分别Monitor配置文件中Apache和MySQL的进程文件路径和名字。

查看Apache进程:

find / -name httpd.pid

查看MySQL进程:

ps -ef|grep mysqld

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注