harumaki.net

インフラ屋の覚書や、ラーメン食べある記とか。

GNU/Linux infra サーバー監視 運用

monitインストール[RHEL3]

投稿日:2005年11月2日

Last Updated on 2022年3月13日 by かんりにん

[pukiwiki]
 
システムマネージメントツールmonitのインストール
監視ツールの発展版といえる、デーモン監視と異常時の再起動などを行う便利ツール。
既にnagiosやzabbixをインストールしているので監視系は整備できているが、異常発生時のデーモンのアクションを指定できるあたりが便利そうなので、ぜひ試してみる。
(Webインターフェース有り)

【本家サイト】
http://www.tildeslash.com/monit/

【ダウンロード元】
http://dag.wieers.com/packages/monit/

【参照サイト】お世話になっています。
設定が良くわからなくてはまっていた時に参照しました。

パソコンおやじさんのサイト
http://www.aconus.com/~oyaji/suse9.3/monit.htm

**1)ダウンロード(RPM版)

今回はRHEL3.0版がRPMで用意されていたのでそのままインストール。
sudoが面倒だったのでrootで作業してしまった(汗

[root@example i386]# pwd
/usr/src/redhat/RPMS/i386
[root@example i386]# wget http://dag.wieers.com/packages/monit/monit-4.4-1.1.el3.dag.i386.rpm
–14:14:36– http://dag.wieers.com/packages/monit/monit-4.4-1.1.el3.dag.i386.rpm
=> `monit-4.4-1.1.el3.dag.i386.rpm’
dag.wieers.com をDNSに問いあわせています… 完了しました。
dag.wieers.com[217.22.63.77]:80 に接続しています… 接続しました。
HTTP による接続要求を送信しました、応答を待っています… 302 Found
場所: http://apt.sw.be/packages/monit/monit-4.4-1.1.el3.dag.i386.rpm [続く]
–14:14:36– http://apt.sw.be/packages/monit/monit-4.4-1.1.el3.dag.i386.rpm
=> `monit-4.4-1.1.el3.dag.i386.rpm’
apt.sw.be をDNSに問いあわせています… 完了しました。
apt.sw.be[193.1.193.67]:80 に接続しています… 接続しました。
HTTP による接続要求を送信しました、応答を待っています… 200 OK
長さ: 179,721 [application/x-redhat-package-manager]

100%[====================================>] 179,721 103.12K/s ETA 00:00

14:14:39 (103.12 KB/s) – `monit-4.4-1.1.el3.dag.i386.rpm’ を保存しました [179721/179721]

**2)インストール

GPG-KEYが無いので警告が出るが進めてOK。

[root@example i386]# rpm -iv monit-4.4-1.1.el3.dag.i386.rpm
警告: monit-4.4-1.1.el3.dag.i386.rpm: V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing packages for installation…
monit-4.4-1.1.el3.dag
[root@example i386]#

パッケージを確認。

[root@example i386]# rpm -qa | grep monit
gnome-system-monitor-2.0.5-2
monit-4.4-1.1.el3.dag
[root@example i386]#

**3)設定

RedHatの場合設定ファイルは/etc/monit.confとなるが
これは全てコメントアウトされた状態。
監視可能プロセスはたくさんあるが、サンプルファイルをみながら自分の環境に合わせて
編集していく。設定対象が増えるとnagios的にずらずらと追加していく。
以下は設定例。

***基本設定

-デーモンの監視間隔
ディレクティブ:”set daemon ”
set daemon 120
-ログファイルの指定
ディレクティブ:”set logfile ”
set logfile syslog facility log_daemon
-アラートメール転送先の指定
ディレクティブ:”set mailserver ”
set mailserver mail.example.com, mail.hogehoge.jp,localhost with timeout 15 seconds
-アラートメールフォーマットの設定
ディレクティブ:”set mail-format ”
下記は一例。
set mail-format {
from: monit@localhost
subject: $SERVICE $EVENT at $DATE
message: Monit $ACTION $SERVICE at $DATE on $HOST.
Yours sincerely,
monit
}

-アラートメールの送信先
ディレクティブ:”set alert ”
set alert user@example.com

-管理用Webページの設定。
ポート指定とアクセス元制限、ログインパスワードの設定を行う
デーモンの停止/再起動までブラウザから実行できるのでアクセス制限は要注意。
ディレクティブ:”set httpd port”
set httpd port 2812 (and use address localhost)
allow localhost
allow 10.10.1.0/24
allow user:hogehoge
他にもSSLの設定があるが、今回はやってないので割愛。

***監視対象デーモン別

-”crond”
# System Services
#
# Cron (program timer)
#
# When used with Solaris the init.d script needs a modification. Add the
# following line after start of cron according to the Monit FAQ:
# /usr/bin/pgrep -x -u 0 -P 1 cron > /var/run/cron.pid
check process cron with pidfile /var/run/crond.pid
group system
start program = “/etc/init.d/crond start”
stop program = “/etc/init.d/crond stop”
if 5 restarts within 5 cycles then timeout
alert user@example.com
alert user@example.com on { timeout }
depends on cron_rc

check file cron_rc with path /etc/init.d/crond
group system
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor
alert user@example.com

-”inetd”
# Inetd (internet service manager)
check process inetd with pidfile /var/run/xinetd.pid
start program = “/etc/init.d/xinetd start”
stop program = “/etc/init.d/xinetd stop”
if failed host 192.168.1.1 port 25 protocol smtp then restart # e.g. exim
if failed host 192.168.1.1 port 515 then restart # e.g. cups-lpd
if failed host 192.168.1.1 port 113 then restart # e.g. ident
if 5 restarts within 5 cycles then timeout
alert user@example.com
alert user@example.com on { timeout }

-”snmpd”
# Net-SNMP (SNMP agent)

check process snmpd with pidfile /var/run/snmpd
start program = “/etc/init.d/snmpd start”
stop program = “/etc/init.d/snmpd stop”
if failed host 192.168.1.1 port 161 type udp then restart
if failed host 192.168.1.1 port 199 type tcp then restart
if 5 restarts within 5 cycles then timeout
alert user@example.com
alert user@example.com on { timeout }

-”NTP”
# NTP (time server)

check process ntpd with pidfile /var/run/ntpd.pid
start program = “/etc/init.d/ntpd start”
stop program = “/etc/init.d/ntpd stop”
if failed host 127.0.0.1 port 123 type udp then alert
if 5 restarts within 5 cycles then timeout

-”sshd”
#Login Services

# 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
alert user@example.com
alert user@example.com on { timeout }

-”httpd(apache) ”
#WWW Services
#
# Apache (web server)

# Hint: It is recommended to use a “token” file (an empty file) for
# monit to request. That way, it is easy to filter out all the requests
# made by monit in the httpd access log file. Here’s a trick shared by
# Marco Ermini, place the following in httpd.conf to stop apache from
# loggin any requests done by monit:
# SetEnvIf Request_URI “^\/monit\/token$” dontlog
# CustomLog logs/access.log common env=!dontlog

# In some cases init scripts for apache and apache-ssl are separated,
# e.g. Debian Linux.
check process apache with pidfile /var/run/httpd.pid
group www
start program = “/etc/init.d/httpd start”
stop program = “/etc/init.d/httpd stop”
if failed host 192.168.1.1 port 80
protocol HTTP request /index.html then restart
if failed host 192.168.1.1 port 443 type TCPSSL
# certmd5 12-34-56-78-90-AB-CD-EF-12-34-56-78-90-AB-CD-EF
protocol HTTP request /index.html then restart
if 5 restarts within 5 cycles then timeout
alert user@example.com
alert user@example.com on { timeout }
# depends on apache_bin
# depends on apache_rc

# check file apache_bin with path /opt/apache/bin/httpd
# group www
# if failed checksum then unmonitor
# if failed permission 755 then unmonitor
# if failed uid root then unmonitor
# if failed gid root then unmonitor
# alert user@example.com

check file apache_rc with path /etc/init.d/httpd
group www
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor
alert user@example.com

-”smtp(postfix)”
#Mail Services
#
# Postfix (mail server)
#
check process postfix with pidfile /var/spool/postfix/pid/master.pid
group mail
start program = “/etc/init.d/postfix start”
stop program = “/etc/init.d/postfix stop”
if failed port 25 protocol smtp then restart
if 5 restarts within 5 cycles then timeout
alert user@example.com
alert user@example.com on { timeout }
depends on postfix_rc
#
check file postfix_rc with path /etc/init.d/postfix
group mail
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor
alert user@example.com

-”database(MySQL)”
※今回はMysqlのデーモンは起動していないので未確認。
動作保証はありません。
#Database Services

# MySQL Server
#
# The name of the pidfile consists usually of the fully quallified
# domainname and pidfile as extension.
check process mysql with pidfile /opt/mysql/data/myserver.mydomain.pid
group database
start program = “/etc/init.d/mysqdl start”
stop program = “/etc/init.d/mysql stop”
if failed host 192.168.1.1 port 3306 protocol mysql then restart
if 5 restarts within 5 cycles then timeout
alert user@example.com
alert user@example.com on { timeout }
depends on mysql_bin
depends on mysql_rc

# check file mysql_bin with path /opt/mysql/bin/mysqld
# group database
# if failed checksum then unmonitor
# if failed permission 755 then unmonitor
# if failed uid root then unmonitor
# if failed gid root then unmonitor
# alert user@example.com

check file mysql_rc with path /etc/init.d/mysqld
group database
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor
alert user@example.com

**4)monitデーモン起動

設定が完了したら起動スクリプトから起動。

[root@example etc]# /etc/init.d/monit start
Starting Process Monitor (monit): [ OK ]
[root@example etc]#

**5)ブラウザから管理画面へアクセス

ブラウザから上記の基本設定で設定したポート2812番へアクセスすると
認証ダイアログが表示され、認証後アクセス可能となる。

例:http://www.example.com:2812

ブラウザからは監視対象デーモンの現在のステータスが確認でき、
デーモンの起動/停止/再起動/監視の開始/停止が可能。

[/pukiwiki]

-GNU/Linux, infra, サーバー監視, 運用
-

執筆者:


comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


関連記事

no image

phpmyfaq​のインストール

[pukiwiki] *phpmyfaqインストール [#q624bdca] 社内イントラ用にテストとして導入したFAQシステム”phpmyfaq”のインストール。 ごく簡単だ …

no image

[juniper] SRX(JunOS) ルーティング不具合修正(非対称ルートへの対応)

  SSGシリーズからSRX220にリプレイスを行った際に、VPNを経由したリモートオフィスとのLAN通信がうまくいかない事象が起きたので、トラブルシュート。 ・社内LANにおいてゲートウェイが複数あ …

no image

[MySQL] ZRM(Zmanda Recovery Manager) コマンドをいろいろ

“Zmanda Recovery Manager / ZRM”のRPM版にて一緒にインストールされるコマンドをいろいろ探ってみたので、メモをいろいろと。 ▼参考:お世話になって …

[AWS] EC2からS3へのファイル転送時間をコマンド別に軽くレポート

  本日までに試した、EC2→S3へのファイル転送時間をコマンド別にそれぞれ簡単に比較・テストしてみたので、以下にまとめ。 それぞれ5回試してみたうちの、速度がもっとも速かったものを以下に記載。今後の …

no image

CentOS4

[pukiwiki] *CentOS4.* 自宅サーバをRedHat9からCentOS4へリプレースしました。 CentOS4.*でのサーバー構築ドキュメントやノウハウなどを 箇条書きでざっくりまとめ …

宅麺