当前位置: 首页 > OpenSource > 正文

monit 一个小巧的linux下监控/故障恢复工具

http://mmonit.com/
官方文档 http://mmonit.com/monit/documentation/monit.html

本文以监控squid为例子,主要是想实现故障检测及自动恢复的功能。

安装
yum install pam-devel
wget http://mmonit.com/monit/dist/monit-5.6.tar.gz
tar zxvf monit-5.6.tar.gz
cd monit-5.6
./configure && make && make install


测试配置文件:
monit -t
monit: Cannot find the control file at ~/.monitrc, /etc/monitrc, /usr/local/etc/monitrc, /usr/local/etc/monitrc or at ./monitrc

启动(监控间隔3秒)
monit -c /usr/local/etc/monitrc -d 3

配置文件:
cat /usr/local/etcmonitrc

set alert admin@2hei.net
set logfile /var/log/monit.log
check program testsquid with path "/usr/local/bin/testsquid.sh" with timeout 10 seconds
if status != 0 then exec "/usr/local/bin/restart_something.sh"
as uid nobody and gid nobody

squid监控脚本
# cat /usr/local/bin/testsquid.sh

#!/bin/bash
/usr/bin/curl -I http://www.2hei.net --proxy http://127.0.0.1:3128
exit $?

故障恢复脚本(Just a test)
# cat /usr/local/bin/restart_something.sh

#!/bin/bash
D=`date +%Y%m%d-%H:%M:%S`
echo "running scrip on : $D" >> /tmp/monit_check.log
#you can restart squid here.

其他更多的功能可以看runbook。

本文固定链接: https://www.2hei.net/2013/11/18/monit-maintenance-and-recovery-tool/ | 2hei.net

该日志由 u2 于2013年11月18日发表在 OpenSource 分类下,
原创文章转载请注明: monit 一个小巧的linux下监控/故障恢复工具 | 2hei.net
关键字:

报歉!评论已关闭.