发布时间:2017-11-14 21:18:25编辑:admin阅读(4023)
Monit是一款功能非常丰富的进程、文件、目录和设备的监测软件,适用于Linux/Unix平台。 它可以自动修复那些已经停止运作的程序,特使适合处理那些由于多种原因导致的软件错误.
安装monit,最好使用yum安装,使用编码包编译有问题
yum install -y monit
编辑配置文件
vim /etc/monit.conf
修改检查时间为3秒以及id文件路径和开启日志
set daemon 3 # check services at 2-minute intervals
set idfile /tmp/id
# set logfile syslog facility log_daemon
set logfile /var/log/monit.log
mkdir /var/monit
chmod -R 750 /var/monit/
然后启动monit
/etc/init.d/monit start
进入配置目录
cd /etc/monit.d/
添加mysql服务监控
vi mysql
check process mysql with pidfile /usr/local/mysql/var/test.kuaidihelp.com.pid
start program = "/etc/init.d/mysqld start"
stop program = "/etc/init.d/mysqld stop"
if failed host 127.0.0.1 port 3306 then restart
注意以上粗体字部分,是需要修改的。
添加http服务监控
vi http
check process http 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 127.0.0.1 port 80 then restart
重启服务
/etc/init.d/monit restart
测试关闭进程,然后查看进程是否启动
如果需要监控tomcat,需要开启tomcat的pid文件,默认是没有的
修改脚本,添加蓝色部分
vi /usr/local/tomcat/bin/catalina.sh
# CATALINA_PID (Optional) Path of the file which should contains the pid
# of catalina startup java process, when start (fork) is used
CATALINA_PID=/usr/local/tomcat/tomcat.pid
重启tomcat
/usr/local/tomcat/bin/shutdown.sh
/usr/local/tomcat/bin/startup.sh
vi /etc/monit.d/tomcat
check process java with pidfile /usr/local/tomcat/tomcat.pid
start program = "/usr/local/tomcat/bin/startup.sh"
stop program = "/usr/local/tomcat/bin/shutdown.sh"
if failed host 127.0.0.1 port 8080 then restart
重启monit
/etc/init.d/monit restart
测试关闭tomcat,查看tomcat是否启动
否则服务可能没有停止命令,比如rsync,那么只能kill掉,注意不要用killall,用pkill比较好一点。
vi /etc/monit.d/rsync
check process rsync with pidfile /var/run/rsync.pid
start program = "/usr/bin/rsync --daemon"
stop program = "/usr/bin/pkill rsync"
if failed host 127.0.0.1 port 873 then restart
重启monit,注意观察输出的信息,没有Warning信息就说明配置正确。
/etc/init.d/monit restart
注意:
Monit是是根据被监控的进程的pid文件来检测的,如果没有pid文件,是无法使用的。
上一篇: Rinetd安装
下一篇: python调用ip查询接口
47745
46235
37110
34627
29229
25886
24745
19863
19417
17908
5716°
6315°
5835°
5888°
6984°
5829°
5846°
6361°
6316°
7673°