监控软件Monit安装与配置

监控软件Monit安装与配置
监控软件Monit安装与配置

一、Monit简介 (1)

二、安装与配置 (1)

1、软件包依赖 (1)

2、下载 (1)

3、安装 (1)

4、配置文件 (1)

5、注册init守护进程 (1)

6、配置实例 (1)

7、检查配置 (4)

8、开始监控 (4)

一、Monit简介

Monit是一款功能非常丰富的进程、文件、目录和设备的监测软件,用于Unix平台。它可以自动修复那些已经停止运作的程序,特使适合处理那些由于多种原因导致的软件错误。

二、安装与配置

1、软件包依赖

apache

2、下载

https://www.360docs.net/doc/5116582144.html,/monit/

3、安装

#tar monit-5.2.3.tar.gz

#cd monit-5.2.3

#./configure /前面有个点儿

#make

#make install

4、配置文件

复制/monit-5.2.3目录下的monitrc文件至/etc目录下

5、注册init守护进程

#vi /etc/inittab

添加下面一行:

mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monirc

6、配置实例

###############################################################

#Global section #全局配置

###############################################################

set daemon 120 with start delay 240 #设置monit为后台进程,没2分钟为一个检查周期,首

次启动后4分钟开始第一次检查

###############################################################

set logfile syslog facility log_daemon #设置系统日志,这是默认设定,可以手动配置指定日志文件

###############################################################

set idfile /var/.monit.id #设置monit对象实例,其实这里的对象就是指本机###############################################################

set statefile /var/.monit.state #设置状态报告文件

###############################################################

set mailserver https://www.360docs.net/doc/5116582144.html, #设置邮件服务器,通过它来发送邮件警告

###############################################################

set eventqueue

basedir /var/monit #设置事件报告,每个事件对应的文件最大大小为100KB

slots 100

###############################################################

##Monit by default uses the following alert mail format:

##--8<--

##From: monit@$host

##Subject: monit alert -- $EVENT $SERVICE

##$EVENT Service $SERVICE

##Date: $DATE

##Action: $ACTION #邮件格式,此处忽略

##Host: $HOST

##Description: $DESCRIPTION

##Your faithful employee,

##Monit

##--8<--

###############################################################

set alert 244032545@https://www.360docs.net/doc/5116582144.html, #设置警告要发往的邮箱

set alert 244032545@https://www.360docs.net/doc/5116582144.html, only on { timeout } #当警告发送失败时要发往的另一个邮箱###############################################################

set httpd port 2812 and use address localhost #设定http访问端口,只允许本机访问allow localhost

allow admin:monit #本地访问凭证,用户admin,密码monit

allow @monit

allow @users readonly

###############################################################

##Services #服务的定义

###############################################################

check system myhost.mydomain.tld

if loadavg (1min) > 4 then alert

if loadavg (5min) > 2 then alert

if memory usage > 75% then alert #检查负载

if swap usage > 25% then alert

if cpu usage (user) > 70% then alert

if cpu usage (system) > 30% then alert

if cpu usage (wait) > 20% then alert

###############################################################

check file apache_bin with path /usr/local/apache/bin/httpd

if failed checksum and expect the sum 8f7f419955cefa0b33a2ba316cba3659 then unmonitor if failed permission 755 then unmonitor

if failed uid root then unmonitor #apache权限检查

if failed gid root then unmonitor

alert 244032545@https://www.360docs.net/doc/5116582144.html, on {checksum, permission, uid, gid} with the mail-format { subject: Alarm! }

group server

###############################################################

check process apache with pidfile /usr/local/apache/logs/httpd.pid

start program = "/etc/init.d/httpd start" with timeout 60 seconds

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

if cpu > 60% for 2 cycles then alert

if cpu > 80% for 5 cycles then restart

if totalmem > 200.0 MB for 5 cycles then restart #检查apache服务器负载

if children > 250 then restart

if loadavg(5min) greater than 10 for 8 cycles then stop

if failed host https://www.360docs.net/doc/5116582144.html, port 80 protocol http and request "/somefile.html" then restart

if failed port 443 type tcpssl protocol http with timeout 15 seconds then restart if 3 restarts within 5 cycles then timeout depends on apache_bin

group server

###############################################################

check filesystem datafs with path /dev/sdb1

start program = "/bin/mount /data"

stop program = "/bin/umount /data"

if failed permission 660 then unmonitor

if failed uid root then unmonitor #检查磁盘使用情况

if failed gid disk then unmonitor

if space usage > 80% for 5 times within 15 cycles then alert

if space usage > 99% then stop

if inode usage > 30000 then alert

if inode usage > 99% then stop

group server

###############################################################

check file database with path /data/mydatabase.db

if failed permission 700 then alert

if failed uid 0 then alert

if failed gid 0 then alert #数据库

if timestamp > 15 minutes then alert

#if size > 100 MB then exec "/my/cleanup/script" as uid dba and gid dba

###############################################################

check directory bin with path /bin

if failed permission 755 then unmonitor #检查某个目录,这里是/bin if failed uid 0 then unmonitor

if failed gid 0 then unmonitor

###############################################################

##以下设置对一台远程主机的监控

###############################################################

#Check a remote host availability by issuing a ping test and check the

# content of a response from a web server. Up to three pings are sent and #connection to a port and an application level network check is performed.

# check host myserver with address 192.168.1.1

# if failed icmp type echo count 3 with timeout 3 seconds then alert

# if failed port 3306 protocol mysql with timeout 15 seconds then alert

# if failed url http://user:password@www.foo.bar:8080/?querystring

# and content == 'action="j_security_check"' then alert

###############################################################

##配置包含文件,这样管理起来可能更方便些,不至于主配置文件代码太多

###############################################################

#Includes

#It is possible to include additional configuration parts from other

#files or directories.

#include /etc/monit.d/*

###############################################################

7、检查配置

#/usr/local/bin/monit -t

8、开始监控

用一下方式启动Monit

#telinit q

相关主题
相关文档
最新文档