Monit初期インストール

6627 ワード

monitは強力なシステム状態、プロセス、ファイル、ディレクトリ、デバイスの監視ソフトウェアであり、*nixプラットフォームに使用され、すでに掛けられたプログラムを自動的に再起動することができ、nginx、apache、mysql、cpu占有率など、システムの重要なプロセスとリソースを監視するのに非常に適しています.一方、Pythonプロセスのモニタリング管理は、supervisorが一般的であり、後で別途紹介します.
monitのインストール、構成、起動について説明します.
インストール
Step 1 M/Monitライブラリの作成
/usr/local/mysql/bin/mysqladmin create mmonit -uUSER -pPASSWD
/usr/local/mysql/bin/mysql -f -h localhost -uUSER -pPASSWD -e "use mysql; grant all privileges on mmonit.* to mmonit@localhost identified by 'mmonit';"
/usr/local/mysql/bin/mysql -f -h localhost -uUSER -pPASSWD -e "use mysql; flush privileges;"
データベースの表示
mysql> show databases;+--------------------+| Database |+--------------------+| mmonit | | mysql | | test | +--------------------+
Step 2 tarパッケージを取り付ける
monitソースパッケージのダウンロードhttp://mmonit.com/download/
tar zxf monit-5.1.1.tar.gz
cd monit-5.1.1
/monit-5.1.1]# ./configure
/monit-5.1.1]# gmake
/monit-5.1.1]# gmake install
/usr/bin/install -c -m 755 -d/usr/local/bin || exit 1/usr/bin/install -c -m 755 -d/usr/local/share/man/man1 || exit 1/usr/bin/install -c -m 555 -s monit/usr/local/bin || exit 1/usr/bin/install -c -m 444 monit.1/usr/local/share/man/man1/monit.1 || exit 1
Step 3プロファイルのコピー
/monit-5.1.1]# cp monitrc/etc/
/mmonit-2.3.4/conf]# vi server.xml

コンフィギュレーション
vi/etc/monitrc
#     ,   2  ,     90 
set daemon 90
# with start delay 240 #      ,        4  (         monit          ) 
#     

set logfile/var/log/monit.log
# monit        

set idfile/var/.monit.id
#monit状態ファイル
set statefile/var/.monit.state
#        
set mailserver 119.254.72.233 
#          
set mail-format { from: [email protected] }
set mail-format { Subject: alert $HOST $SERVICE $DESCRIPTION }
#          。    gmail,      
set alert [email protected] # receive all alerts
set alert [email protected] # receive all alerts
# set alert [email protected]{timeout}#監視されたサービスがタイムアウトした場合にのみ、そのメールアドレスにメール通知が送信されます.
set httpd port 2812 and#httpモニタページのポートを設定
use address 119.254.72.48#httpモニタページのIPまたはドメイン名
allow localhost#ローカルへのアクセスを許可
allow 203.86.46.224/29#このIPセグメントへのアクセスを許可
allow 203.86.63.133#このIPアクセスを許可
allow USER:PASWD#アクセス可能なユーザー名パスワード
#############################################################################
## Services
###############################################################################
#
#           ,      ,       
#     ,   IP   

check system 119.254.72.248
if loadavg (1min) > 4 then alert
if loadavg (5min) > 2 then alert
if memory usage > 75% then alert
if cpu usage (user) > 70% then alert
if cpu usage (system) > 30% then alert
if cpu usage (wait) > 20% then alert
#-------------------->Http<----------------------#
check process apache with pidfile/usr/local/apache/logs/httpd.pid
start program = "/usr/local/apache/bin/apachectl start"with timeout 60 seconds
stop program = "/usr/local/apache/bin/apachectl stop"
if failed host 119.254.72.248 port 80 protocol http then restart
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if children > 140 then restart
#-------------------->Http_post<----------------------#
check process httpd with pidfile/usr/local/http_post/logs/httpd.pid
start program = "/usr/local/http_post/bin/apachectl start"with timeout 60 seconds
stop program = "/usr/local/http_post/bin/apachectl stop"
if failed host 119.254.72.248 port 8080 protocol http then restart
#-------------------->Nginx<----------------------#
check process nginx with pidfile/usr/local/nginx/logs/nginx.pid
start program = "/usr/local/nginx/sbin/nginx start"with timeout 60 seconds
stop program = "/usr/local/nginx/sbin/nginx stop"
if failed host 119.254.72.248 port 81 protocol http then restart
#-------------------->Mysql<----------------------#
check process mysqld with pidfile/usr/local/mysql/var/m-g3.dns.com.cn.pid
start program = "/usr/local/mysql/bin/mysqlctl start 3306"with timeout 60 seconds
stop program = "/usr/local/mysql/bin/mysqlctl stop 3306"
if failed host 119.254.72.248 port 3306 protocol then restart
#-------------------->Nfs<----------------------#
check process nfsd with pidfile/var/run/mountd.pid
start program = "/etc/rc.d/nfsd start"with timeout 60 seconds
stop program = "/etc/rc.d/nfsd stop"
if failed host 119.254.72.248 port 2049 protocol nfsd then restart
#-------------------->Spam<----------------------#
check process Spamd with pidfile/var/run/spamd.pid
start program = "/usr/local/sbin/spamctl start"with timeout 60 seconds
stop program = "/usr/local/sbin/spamctl stop"
if 5 restarts within 5 cycles then timeout
if cpu usage > 99% for 5 cycles then alert
if mem usage > 99% for 5 cycles then alert
#ディスク領域
check filesystem root with path/
if space usage > 70% then alert
if inode usage > 85% then alert
check filesystem home with path/home
if space usage > 50% for 5 times within 15 cycles then alert
if inode usage > 85% then alert
check filesystem usr with path/usr
if space usage > 70% then alert
if inode usage > 85% then alert
check filesystem var with path/var
if space usage > 70% then alert
if inode usage > 85% then alert
----------------------------------------------------------------
私の生産ニーズに応じて、今までに配置が完了しました.
開始
#/usr/local/bin/monit -c/etc/monitrc monit: generated unique Monit id 3fc046bad3fc56f8959f6b0fe6d9267d and stored to '/var/.monit.id'Starting monit daemon with http interface at [119.254.72.248:2812]
# ps -aux |grep monitroot 78633 0.0 0.1 6360 2836 ?? S 2:49PM 0:00.01/usr/local/bin/monit
------------------------------------------------------------
monitのweb構成は次編を参照