linux jar运行监控 mo,linux使用monit监控服务运行状态

monit类似于supervisor,supervisor可以运行一些后台服务,在服务崩溃(crash)的时候重启服务。这两个服务都是非常好用的监控程序,这篇blog记录使用monit的基本方法。

关于monit的优点可以参考这里http://stackoverflow.com/questions/12156434/what-is-the-advantage-of-using-supervisord-over-monit

1.下载编译

monit的官网地址http://mmonit.com/monit/ ,运行如下命令下载编译

请自行安装linux的编译环境。monit安装过程中需要pam的依赖,先安装pam

centos运行如下命令安装

yum install pam-devel

ubuntu运行如下命令安装

apt-get install libpam0g-dev

wget http://mmonit.com/monit/dist/monit-5.10.tar.gz

tar xvf monit-5.10.tar.gz

cd monit-5.10

./bootstrap

./configure

make

make install

2.配置文件和init文件

复制文件到指定目录

cp monitrc /etc

cp system/startup/rc.monit /etc/init.d/monit

chmod +x /etc/init.d/monit

chkconfig monit on

修改/etc/init.d/monit文件MONIT=/usr/bin/monit为程序运行目录(使用which monit查看路径)

修改/etc/monitrc文件,主要配置循环周期,web管理密码和端口,开启include。修改点如下

set daemon  30

set logfile /var/log/monit.log

set httpd port 2812 and

use address 192.168.163.36  # only accept connection from localhost

allow 0.0.0.0/0.0.0.0        # 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

include /etc/monit.d/*

3.添加监控实例

以opensips服务为例,新建/etc/monit.d/opensips文件

mkdir /etc/monit.d

vi /etc/monit.d/opensips

添加如下内容

[root@localhost monit.d]# cat opensips

check process opensips with pidfile /var/run/opensips.pid

group opensips

start program = "/etc/init.d/opensips start"

stop program = "/etc/init.d/opensips stop"

if failed host 192.168.163.36 port 5060 then restart

if 5 restarts within 5 cycles then timeout

运行monit

service monit start

上述配置的含义为监听192.168.163.36 5060 端口,如果失败,则重启opensips。在重启5次失败后不再重试,避免无限循环。这样,即使在终端运行killall opensips后,在30秒内,monit会自动重启opensips服务。monit的log被配置在/var/log/monit.log文件,可以通过192.168.163.36:2812访问web控制台(需要关闭iptables或添加例外,如配置文件中,用户名为admin密码monit)。

monit同时还可以配置崩溃时发送邮件的功能,需要后台开启一个邮件服务器。

web控制界面截图如下:

04520ed8ab3f12f5253d5d40d0c4f068.png

4337a1461269b46a53e762752a00585f.png

3d96324246f669382d8abb78b368d58d.png

2861f65f398c82a73ebd3a84213bfee7.png

73036a6aa8ddf297cc50dbde017954f5.png

783a02986a193cd00e78a94321db3ca5.png

参考链接 http://blog.chinaunix.net/uid-26249914-id-3836126.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值