|
Monit是一个Linux/UNIX系统上开源的进程、文件、目录和文件系统监控和管理工具。官网:http://mmonit.com/。这里系统为CentOS6.2,监控机IP为192.168.1.100,被监控机IP为192.168.1.200。
一、被监控机安装monit
选择相应的系统下载:
set httpd port 2812 and
use address localhost # only accept connection from localhost
allow localhost # allow localhost to connect to the server and
allow admin:monit # require user 'admin' with password 'monit'
allow @monit # allow users of group 'monit' to connect (rw)
allow @users readonly # allow users of group 'users' to connect readonly
set eventqueue basedir /var/monit/ slots 1000
set mmonit http://monit:monit@192.168.1.100:8080/collector
set httpd port 2812 and
use address 192.168.1.200
allow localhost
allow admin:monit
allow 192.168.1.100
5、在/etc/monit.d目录内添加监控脚本
监控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 port 22 protocol ssh then restart if 5 restarts within 5 cycles then timeout
check process apache with pidfile /var/run/httpd/httpd.pid
group www
start program = "/etc/init.d/httpd start"
stop program = "/etc/init.d/httpd stop"
if failed host www.example.com port 80 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
7、启动monit
参考资料: |
