利用monit对tomcat进行监控,在服务不可用的时候对tomcat进行重启。
1.安装monit
# apt-get install monit
2.配置monit
在/etc/monit/conf.d目录下面,创建一个tomcatrc的文件,写入如下内容
check host all with address localhost
start program = "/home/ubuntu/webservice/apache-tomcat-8.0.30/bin/startup.sh " with timeout 60 seconds
stop program = "/home/ubuntu/webservice/apache-tomcat-8.0.30/bin/shutdown.sh"
# if cpu > 60% for 2 cycles then alert
# if cpu > 80% for 5 cycles then restart
# if totalmem > 200.0 MB for 5 cycles then restart
# if children > 250 then restart
# if loadavg(5min) greater than 10 for 8 cycles then stop
if failed host localhost port 80 protocol http
and request "/auto/health"
then restart
# if failed port 443 type tcpssl protocol http
# with timeout 15 seconds
# then restart
# if 3 restarts within 5 cycles then timeout
# depends on apache_bin
# group server
上面主要是监控tomcat的服务,如果 /auto/health无法获得有效的数据,那么monit就会对服务进行重启。
3.启动、停止monit
# /etc/init.d/monit start | stop