monit监控服务进程

monit监控服务进程

用户2398817发表于python3订阅

112

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文件,是无法使用的。

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于 2018-08-02

其他

转载于:https://my.oschina.net/u/3367404/blog/3037934

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值