雑なメモ(無保証)

monit -- プロセス監視


●プロセスが停止した時に強制的に再起動させる

1) ダウンロードとインストール
cd /usr/local/src
wget http://packages.sw.be/monit/monit-5.2-1.el5.rf.i386.rpm
rpm -uvh monit-5.2-1.el5.rf.i386.rpm


2) monitメイン設定
vi /etc/monit.conf

# 監視間隔(s)設定
set daemon  60
# ログファイル設定
set logfile /var/log/monit.log
# アラートメール送信に使用するSMTPサーバ設定
set mailserver mail.example.co.jp
# アラートメールフォーマット設定
set mail-format {
        from: admin@$HOST
        subject: Alert-- $EVENT $SERVICE  @$HOST

        message: $EVENT Service $SERVICE

                Date:        $DATE
                Action:      $ACTION
                Host:        $HOST
                Description: $DESCRIPTION
}

# アラートメール送信先メールアドレス設定(ACTION:監視状態の変更、INSTANCE:monitデーモンの挙動)
set alert exam@example.co.jp not on { ACTION , INSTANCE }

# monitのWEB画面設定
set httpd port 2812
        allow localhost


3) プロセス監視設定
各監視詳細設定は、/etc/monit.d/*** に設定を記載する

3-1) ハードディスク監視
ハードディスク使用容量が指定した%を超えたらアラートメールを送信する
vi /etc/monit.d/sda2

check device_sda2 rootfs with path /dev/sda2
 if space usage > 60% 5 times within 15 cycles then alert
 else if passed for 10 cycles then alert
 if space usage > 80% for 5 cycles then alert
 else if passed for 10 cycles then alert

vi /etc/monit.d/sda3

check device_sda3 rootfs with path /dev/sda2
 if space usage > 60% 5 times within 15 cycles then alert
 else if passed for 10 cycles then alert
 if space usage > 80% for 5 cycles then alert
 else if passed for 10 cycles then alert

3-2) apache監視
# localhostの80ポートへ接続できなければ再起動する
# 5回再起動しても起動できなければ諦める。unmonitor状態になる

vi /etc/monit.d/httpd

check process httpd with pidfile /var/run/httpd.pid
        start program = "/etc/rc.d/init.d/httpd start"
        stop program = "/etc/rc.d/init.d/httpd stop"
        if failed host localhost port 80 then restart
        if 5 restarts within 5 cycles then timeout
        group apache

 


3-3) mysql監視
# localhostの3306ポートへ接続できなければ再起動する
# 5回再起動しても起動できなければ諦める。unmonitor状態になる

vi /etc/monit.d/mysqld

check process mysqld with pidfile /var/run/mysqld/mysqld.pid
        start program "/etc/rc.d/init.d/mysqld start"
        stop program "/etc/rc.d/init.d/mysqld stop"
        if failed host localhost port 3306 protocol mysql then restart
        if 5 restarts within 5 cycles then timeout


4) monitをinitから起動
monit自体が停止しないようにinitに登録する


vi /etc/monit.conf
# inittab設定
set init

# respawn設定
vi /etc.inittab
mo:2345:respawn:/usr/bin/monit -Ic /etc/monit.conf


#inittab更新
telinit q


5) unmonitor解除設定
unmonitor状態だと、ずっと再起動されないので、1時間に一回unmonitor状態を解除して、
再起動を試みる。

crontab -e
0 */1 * * * /usr/bin/monit monitor all

 


最終更新 2011/05/20 14:52:13 - llinfo_arp
(2011/05/20 14:48:46 作成)


Amazon