ふと思いついてさくらVPSのDebianのMonit設定をしました
サーバのリソース監視や死活監視ってしっかりやらないと・・・と思ってなかなか重い腰があがらなかったのですが、15分で始めるmonitによるサーバ監視というのを以前に読んでいたのと、ここ最近資料作りばっかりやっていて違う作業をしたくなったので、今朝取り組んで見ました
自分の環境&インストール
cat /etc/debian_version 6.0.2 sudo apt-get install monit
基本設定
前述の株式会社シャノン技術ブログさんの環境はCentOSなので適宜読み替える必要ありました。
上記のCentOSでのconfigは/etc/monit.confのようですが、Debianの環境ですと/etc/monit配下になるようです。
monitrcで共通設定となるものを記述
set daemon 30 with start delay 240 # optional: delay the first check by 4-minutes (by set logfile syslog facility log_daemon set idfile /var/.monit.id set statefile /var/.monit.state include /etc/monit/conf.d/*
include /etc/monit/conf.d/* を上記記述しているのでmoniti起動時にconf.d配下の個別の設定を読み取ってくれるようです
ひとまずこんな感じでしょうかね。
個別設定
ひとまずApacheの設定と、アラートメールの確認をするだけのメール設定の2つを設定してみました。
ディレクトリ構成はこんな感じです
hoyamada@xxxxx:~$ tree /etc/monit /etc/monit ├── conf.d │ ├── alert.conf │ └── apache2.conf └── monitrc
Apache
シャノンさんのブログではサンプル無かったですが、ひとまず自分がやりたかったApacheの監視をするものをhttp://server-setting.info/centos/monit_apache_1.html:title=を参考にして取り組んでみました。
こちらのブログもCentOS利用を想定しているので、適宜読み替える必要ありました。といっても、CentOSの場合には/etc/init.d/httpdとなっているのが、Debianでは/etc/init.d/apache2とするだけでOKでした
最終的にはapache2.confに以下を記述しました
check process apache2 with pidfile /var/run/apache2.pid start program = "/etc/init.d/apache2 start" stop program = "/etc/init.d/apache2 stop" if failed host xxxxxxxx port 80 protocol HTTP request /xxxxx then restart group apache2
Alertメール確認
Apacheの設定を参考にしたブログの別エントリでこんな感じで自分がやりたいことがまとまっていたので、これをほぼそのまま流用しました
alert.confは以下のようになりました
set alert mygmail@gmail.com with mail-format { from: mygmail@gmail.com subject: $SERVICE $EVENT at $DATE message: Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION. Yours sincerely, monit } set mailserver smtp.gmail.com port 587 username "mygmail@gmail.com" password "password" using tlsv1
動作確認
monit実行時に管理者権限でないと実行できないみたいなので
sudo monit -t
Control file syntax OK
として、設定ファイルの記述ミスが無いのを確認して
sudo monit Starting monit daemon Monit start delay set -- pause for 240s
と出て、自分のGmailのアドレス宛てに
Monit start xxxxxxx at Tue, 28 Aug 2012 08:03:48 +0900 on xxxxxxx: Monit started.
Yours sincerely,
monit
というメールが届いてました。
ごく初歩的な設定はこれでOKかと思うのですが、特にCPUやメモリ等のシステムリソース確認の設定を気が向いたら(具体的には資料作成やコード書いてて気分転換したくなった時)にやろうかと思います