您的位置:首页 > 运维架构 > Linux

Monit - Linux系统进程、文件、目录和设备的监测软件

2014-05-28 11:13 330 查看
Monit是一款功能非常丰富的进程、文件、目录和设备的监测软件,适用于Linux/Unix平台。 它可以自动修复那些已经停止运作的程序,特使适合处理那些由于多种原因导致的软件错误,同时Monit 包含一个内嵌的 HTTP(S) Web 界面,你可以使用浏览器方便地查看 Monit 所监视的服务器。
Monit官网:http://mmonit.com/monit/

1、安装Monit

CentOS可以到:http://pkgs.repoforge.org/monit/ 下载对应位数rpm包安装。
32位:wget -c http://pkgs.repoforge.org/monit/monit-5.2.5-1.el5.rf.i386.rpm;rpm -ivh monit-5.2.5-1.el5.rf.i386.rpm
64位:wget -c http://pkgs.repoforge.org/monit/monit-5.2.5-1.el5.rf.x86_64.rpm;rpm -ivh monit-5.2.5-1.el5.rf.x86_64.rpm
Debian可以直接:apt-get install monit 安装。

2、修改配置文件

CentOS用RPM包安装的话配置文件在: /etc/monit.conf;Debian apt-get安装的话配置文件在:/etc/monit/monitrc;
下面是一个简单的例子,配置文件中已经包含了大量的例子,可以看配置文件参考。
set daemon  120        #设置检测时间
set logfile /var/log/monit.log        #monit日志
set alert www@vpser.net with reminder on 1 cycle  #出现1次错误的时候发报警邮件到指定的邮箱
set mailserver mail.vpser.net     #设置邮件服务器
set httpd port 2812 and            # 设置http监控页面的端口
use address 74.207.246.99   # http监控页面的IP
allow localhost               # 允许本地访问
allow 123.23.45.0/24           # 允许此IP段访问
#allow 0.0.0.0/0.0.0.0       # 允许所有IP访问
allow username:password     #设置访问用户名密码

#检测sshd服务
check process sshd with pidfile /var/run/sshd.pid
start program  "/etc/init.d/sshd start"
stop program  "/etc/init.d/sshd stop"
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout

#检测mysql服务
check process mysql with pidfile /usr/local/mysql/var/vpser.pid
group database
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout

#检测nginx服务
check process nginx with pidfile /usr/local/nginx/logs/nginx.pid
start program = "/etc/init.d/nginx start"
stop program  = "/etc/init.d/nginx stop"
if failed host www.vpser.net port 80 protocol http
then restart
配置中的pid及启动、关闭脚本的路径一定要是全路径,且参数一定要正确否则会造成无法正常检测或正常启动。
看了一下php-fpm貌似用Monit还不是很好监控。
如果添加了http可以直接使用http://ip:2812 进行管理。

3、启动/停止Monit

CentOS:

chkconfig monit on //加入开机启动
/etc/init.d/monit {start|stop|restart|force-reload|syntax}

Debian:

编辑:/etc/default/monit 文件,查找 startup=0 ,将0改为1,保存。
update-rc.d -f monit defaults
/etc/init.d/monit {start|stop|restart|force-reload|syntax}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: