Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7401826
  • 博文数量: 1756
  • 博客积分: 18684
  • 博客等级: 上将
  • 技术积分: 16232
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-02 10:28
个人简介

啥也没写

文章分类

全部博文(1756)

文章存档

2024年(2)

2023年(44)

2022年(39)

2021年(46)

2020年(43)

2019年(27)

2018年(44)

2017年(50)

2016年(47)

2015年(15)

2014年(21)

2013年(43)

2012年(143)

2011年(228)

2010年(263)

2009年(384)

2008年(246)

2007年(30)

2006年(38)

2005年(2)

2004年(1)

分类: LINUX

2011-01-21 10:42:18

Monit 是一个用来监测系统状态的工具,不但可以用来监视进程、服务、文件、目录、文件系统,还可以在服务 down 掉的时候自动重启服务或者当某个进程占用过多的资源的时候自动停掉进程,并且支持 Email 报警功能、远程服务器监测、web 管理界面等,功能很多很强大。VPSee 用 monit 来监测多个 VPS 和独立服务器,如果某个 VPS down 了、某个服务器资源紧张,就能第一时间知道,而且某个服务停了的话可以自动重启服务。

安装 monit
在 CentOS 下安装和配置文件:

  1. # wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm   
  2. # rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm   
  3.   
  4. # yum install monit   
  5.   
  6. # vi /etc/monit.conf  

配置 monit
修改 monit 的配置文件,/etc/monit.conf(CentOS)或者 /etc/monit/monitrc(Debian),每隔120秒检查一次系统,如果 httpd/mysql/sshd 服务停掉了就重新启动相应服务。对于 httpd 服务器,当发现 CPU/MEM 占用过大、loadavg 太高时就执行相应的报警、重启服务指令。如果使用 Email 报警功能,需要配置 Email 地址、邮件服务器等信息:

  1. set daemon  120   
  2.   
  3. check process sshd with pidfile /var/run/sshd.pid   
  4.    start program  “/etc/init.d/sshd start”  
  5.    stop program  “/etc/init.d/sshd stop”  
  6.    if failed port 22 protocol ssh then restart   
  7.    if 5 restarts within 5 cycles then timeout   
  8.   
  9. check process mysql with pidfile /var/run/mysqld/mysqld.pid   
  10.    group database   
  11.    start program = “/etc/init.d/mysqld start”  
  12.    stop program = “/etc/init.d/mysqld stop”  
  13.    if failed host 127.0.0.1 port 3306 then restart   
  14.    if 5 restarts within 5 cycles then timeout   
  15.   
  16.  check process nginx with pidfile /var/run/nginx.pid   
  17.     start program = “/etc/init.d/nginx start”  
  18.     stop program  = “/etc/init.d/nginx stop”  
  19.     if failed host    
  20.        then restart   
  21.   
  22.  check process php_cgi with pidfile /var/run/php_cgi.pid   
  23.     start program = “/etc/init.d/php_cgi start”  
  24.     stop program  = “/etc/init.d/php_cgi stop”  
  25.     if failed host 127.0.0.1 port 9000 then restart   
  26.     if 5 restarts within 5 cycles then timeout   
  27.   
  28. check process apache with pidfile /var/run/httpd.pid   
  29.    group www   
  30.    start program = “/etc/init.d/httpd start”  
  31.    stop program  = “/etc/init.d/httpd stop”  
  32.    if failed host    
  33.       then restart   
  34.    if cpu is greater than 80% for 2 cycles then alert   
  35.    if cpu > 80% for 5 cycles then restart   
  36.    if totalmem > 512 MB for 5 cycles then restart   
  37.    if children > 200 then restart   
  38.    if loadavg(5min) greater than 10 for 8 cycles then stop   
  39.    if 3 restarts within 5 cycles then timeout   

更多详细信息可以参考配置文件,里面注释写得很详细。

启动 monit
在 CentOS 下启动并加入到系统启动脚本:

  1. # /etc/init.d/monit start   
  2.   
  3. # /sbin/chkconfig monit on   

转:http://blog.phpsoho.com/?p=372

阅读(1734) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~