使用monit工具对thin进程的监控

monit可以对服务器进程进行监控,如果发现服务器进程挂掉,则能根据配置进行重启。

下载地址

http://mmonit.com/monit/download/ ,大小为612K.

 

现在完成后进行安装

chmod 775 monit-5.1.1.tar.gz

tar -zxf monit-5.1.1.tar.gz

cd monit-5.1.1

./configure

make

make install

 

安装完成,然后拷贝配置文件到etc目录下

cp monitrc /etc/monitrc


进入到etc目录

打开monitrc文件,可以找到一些配置的例子

 

我测试的配置如下

set daemon  60       #设置monit检查的间隔时间,单位是秒。

with start delay 10 #monit进程启动10秒后才进行监控
set httpd port 2812 and  #设置访问的端口号,即使用浏览器访问的端口
     use address localhost  # only accept connection from localhost
     allow localhost        # 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/monitrc_thin #将thin的monit配置包含进来, 也可以直接写在此配置文中. monitrc_thin是我新建的文件。

 

monitrc_thin的文件内容如下

  check process thin3000 with pidfile /root/www/lbs/tmp/pids/thin.3000.pid
    start program = "/usr/local/bin/thin start -c /root/www/lbs -e production -p 3000 -d -s 1" with timeout 60 seconds
    stop program  = "/usr/local/bin/thin stop -c /root/www/lbs -s 1 -p 3000" with timeout 60 seconds
    if failed port 3000 protocol http 
         and request "/"
         with timeout 30 seconds
       then restart
     group thin
  check process thin3001 with pidfile /root/www/lbs/tmp/pids/thin.3001.pid
    start program = "/usr/local/bin/thin start -c /root/www/lbs -e production -p 3001 -d -s 1" with timeout 60 seconds
    stop program  = "/usr/local/bin/thin stop -c /root/www/lbs -s 1 -p 3001" with timeout 60 seconds
    if failed port 3001 protocol http 
         and request "/"
         with timeout 30 seconds
       then restart
     group thin

 

这里我是用两个thin进程进行的尝试。

 

对配置的文件正确性进行测试

monit -t

如果配置有误,则根据提示进行更改。直到显示配置OK为止

 

下面启动monit对进程进行监控

进入rails的项目根路径,我这里为root/www/lbs

启动thin进程:   thin start -s 2 -p 3000 -e production  # 也可跳过此步,由monit监控进行启动

启动monit:   monit

 

打来浏览器访问,  localhost:2812 .  输入用户名admin和密码monit, 可以查看被监控的进程的状态,以及内存和cpu使用率等。

 

随便kill一个被监控的thin 的进程,然后观察 localhost:2812 的进程的状态变化。 看配置是否生效。

 

注意:即使monit -t 没有显示错误,但不代表配置文件一定没有问题,只是说monit可以执行此配置文件而已,对配置文件中配置的start和stop命令是否能执行成功不做判断,

 

其他monit的使用教程

http://www.sucai.com/Tech/List5/21082.htm

 

补充:

1.with start delay 10 #monit进程启动10秒后才进行监控, 这个默认好像是240秒. 如果你想启动monit后立即能访问上面的localhost:2812怎把这项设置为1

2.localhost:2812无法访问,参考下面配置

本机访问

set httpd port 2812 and  #设置访问的端口号,即使用浏览器访问的端口
     use address localhost  # 如果这里的值为localhost则只允许本机访问
     allow localhost        #允许本机访问,使用localhost:2812进行访问
     allow admin:monit      # require user 'admin' with password 'monit'

局域网访问

set httpd port 2812 and  #设置访问的端口号,即使用浏览器访问的端口
     use address 192.168.1.11# 此处填写本机的局域网ip
     allow localhost        # 允许本机访问,使用localhost:2812进行访问

     allow 192.168.1.22  #允许局域网内ip为192.168.1.22的机器访问,访问地址为192.168.1.11:2812

     allow 192.168.1.88  #允许局域网内ip为192.168.1.88的机器访问,访问地址同上

     allow 192.168.1.1/255.255.255.0 # 允许局域网内所有机器访问
     allow admin:monit      # require user 'admin' with password 'monit'
外网访问

set httpd port 2812 and  #设置访问的端口号,即使用浏览器访问的端口
     use address 12.12.12.12# 此处填写本机的外网ip

     allow 11.11.11.11#允许外网ip为11.11.11.11的机器访问,访问地址为12.12.12.12:2812
     allow admin:monit      # require user 'admin' with password 'monit'

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值