Monit 是用于对系统中的进程、文件、目录、以及设备等进行监视和管理的工具。当你所指定的server宕机或者没有反应,monit会将该进程杀死并重启该server。并通过邮件进行通知。Monit 包含一个内嵌的 HTTP(S) Web 界面,你可以使用浏览器方便地查看 Monit 所监视的服务器。
如图:
Monit的官方网站:
下面将介绍monit在CentOS5.3上的安装和配置:
download:
shell > tar xzvf monit-5.1.1.tar.gz
shell> cd monit-5.*
shell>./configure
shell>make
shell> make install
shell> rm /etc/monitrc
shell> cp monitrc /etc/
在inittab文件中添加下面这句话,使init守护monit进程!!
shell> vi /etc/inittab
mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc
现在安装完成了,是不是超简单!!
接下来就是配置了!!
Monitrc文件###############################################################################set daemon 120 #设置monit检查的间隔时间,单位是秒!!
set logfile syslog facility log_daemon #用syslog来记录log
set logfile /var/logs/monit.log #设置日志路径
set idfile /var/.monit.id #设置PID文件的位置
set mailserver 192.168.0.21, # primary mailserver 邮件服务器的IP
set mail-format { from: } #设置你的邮件从哪个账号发出
set alert #发到我的139邮箱,用139邮箱是因为139有一个邮件到达通知功能
set httpd port 2812 and #设置monit监听的端口号
use address 192.168.0.21 # 设置monit服务器的IP,可以让你方便的http访问
allow admin:pass #设置用户名和密码################################################################################# Services ################################################################################监控服务器的磁盘使用情况
check device system with path /dev/mapper/VolGroup00-LogVol00
if space usage > 85% for 5 times within 15 cycles then alert
if space usage > 95% then stop
if inode usage > 85% then alert
if inode usage > 95% then stop
######################################################
#sshd 监控sshd进程
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 then restart
if 5 restarts within 5 cycles then timeout
#######################################################
#cron 监控crontab进程
check process cron with pidfile /var/run/crond.pid
group system
start program = "/etc/init.d/crond start"
stop program = "/etc/init.d/crond stop"
if 5 restarts within 5 cycles then timeout depends on cron_rc
############################################################################################################
#scripts 监控的日志切割脚本文件
check file cut_nginx_log.sh with path /scripts/cut_nginx_log.sh
group scripts
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor
#############################################################################################################
#systemfile 监控passwd文件和group文件
check file passwd with path /etc/passwd
group system
if failed checksum then unmonitor
if failed permission 644 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor
check file group with path /etc/group
group system
if failed checksum then unmonitor
if failed permission 644 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor
############################################################################################################
# 监控本机的25,110端口号
check host localhost with address 127.0.0.1
if failed port 25 with timeout 15 seconds then exec "/usr/bin/ctl restart"
if failed port 110 protocol pop with timeout 15 seconds then exec "/usr/bin/vpopmailctl restart"
基本的配置就是这样子,剩下的就是根据各自的实际情况进行修改!!!,配置好从浏览器登录查看下是否成功,接下来就是轻松的喝喝茶,逛逛论坛了!! 哈哈
本文出自“”博客,请务必保留此出处
阅读(839) | 评论(0) | 转发(0) |