File last modified 2004/03/27 15:19
Nagiosによるネットワーク監視
UNIX USER 2002年8月号特集に紹介されているNagiosをSolarisに導入したインストール記録です。
ここではSolarisにインストールしたときのポイントのみ紹介します。
とりあえず使えるようにしただけで、内容はぜんぜん詳しくありません。
まずは、Document のAdvice for Beginnersを読んでみてください^^;
更新履歴
2002年11月30日 nagios-1.0 nagios-plugins-1.3.0-beta2 がリリースされています
2002年11月23日 Database Support(MySQL)を追加
2002年11月10日 check_smtp.cの修正(CVSから入手)
2002年09月07日 External Command を使えるようにした。
Nagiosの入手先は本家のページhttp://www.nagios.org/よりダウンロードします。
11月30日時点の最新バージョンは以下のとおり
本体 nagios-1.0
プラグイン Plugins v1.3.0 Beta2
ダウンロードは本家のページよりリンクがあります。
ユーザーとグループの作成
rootユーザになりグループとユーザーを作成します
# groupadd nagios
# groupadd nagiocmd
# useradd -d /usr/local/nagios -g nagios nagios
ユーザーnagiosとapacheの実行ユーザーnobodyにnagiocmdの実行権を与える
# usermod -G nagiocmd nagios
# usermod -G nagiocmd nobody
本体インストール
$ tar xvzf nagios-1.0.tar.gz
$ cd nagios-1.0
$ LDFLAGS="-R/usr/local/lib" \
> ./configure --with-command-grp=nagiocmd --with-gd-lib=/usr/local/lib --with-gd-inc=/usr/local/include
(コマンド実行グループ、GDのインストール先指定)
$ make all
$ su
# make install install-init install-commandmode install-config
プラグインインストール
nagiosplug-1.3-beta1にはいくつかのbugがあるようです。
うちではWindows系のSMTPサーバー監視が失敗するという問題がありましたが
CVSのページより入手したcheck_smtp.cを使い解決しています。
$ tar xvzf nagios-plugins-1.3.0-beta2.tar.gz
$ cd nagios-plugins-1.3.0-beta2
$ LDFLAGS="-R/usr/local/lib" \
> ./configure
$ make all
$ su
# make install
以上で/usr/local/nagios配下に必要なファイル、
起動スクリプトは/etc/init.dにインストールされる
| /usr/local/nagios/ |
bin |
実行ファイル |
|
etc |
設定ファイル |
|
libexec |
プラグイン |
|
sbin |
cgiファイル |
|
share |
htmlファイル |
|
images |
イメージ |
|
var |
ログなど |
| /etc/init.d/nagios |
|
起動スクリプト |
必要に応じて、起動時にnagiosが起動するように
/etc/rc2.dにリンクを作る
# ln -s /etc/init.d/nagios /etc/rc2.d/S99nagios
# ln -s /etc/init.d/nagios /etc/rc2.d/K60nagios
Apacheの設定
nagiosはブラウザより監視状態を表示しますので、Apacheの設定を先にしておきます。
・hpptd.confの設定
ScriptAlias /nagios/cgi-bin/ /usr/local/nagios/sbin/
<Directory /usr/local/nagios/sbin>
AllowOverride AuthConfig
order allow,deny
allow from all
Options ExecCGI
</Directory>
Alias /nagios/ /usr/local/nagios/share/
<Directory /usr/local/nagios/share>
AllowOverride AuthConfig
order allow,deny
allow from all
</Directory>
.htaccess ファイルを/usr/local/nagios/sbin ディレクトリ /usr/local/nagios/shareに作成
パスワードファイルは /use/local/nagios/etc に配置します
.htaccess
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
require valid-user
パスワードファイル作成
userは任意で
# /usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users
nagiosadmin
# /usr/local/apache/bin/htpasswd /usr/local/nagios/etc/htpasswd.users <username>
# /usr/local/apache/bin/htpasswd /usr/local/nagios/etc/htpasswd.users guest
※忘れずにApacheの再起動。
Nagiosの設定ファイル
さて、ここまでは前準備でしたがこれから肝心なNagiosの設定に入ります。
/usr/local/nagios/etc にサンプルファイルがありますので、
必要なものはそのままコピーし、編集します。
|
|
設定ファイル |
|
サンプルファイル |
| 編集 |
|
nagios.cfg |
|
nagios.cfg-sample |
| サンプルのまま |
|
cgi.cfg |
|
cgi.cfg-sample |
| 新規作成 |
|
hosts.cfg |
|
hosts.cfg-sample |
| 新規作成 |
|
contacts.cfg |
|
contacts.cfg-sample |
| 新規作成 |
|
services.cfg |
|
services.cfg-sample |
| サンプルのまま |
|
checkcommands.cfg |
|
checkcommands.cfg-sample |
| サンプルのまま |
|
misccommands.cfg |
|
misccommands.cfg-sample |
| サンプルのまま |
|
resource.cfg |
|
resource.cfg-sample |
| サンプルのまま |
|
timeperiods.cfg |
|
timeperiods.cfg |
| 未使用 |
|
|
|
contactgroups.cfg-sample |
| 未使用 |
|
|
|
hostgroups.cfg-sample |
| 未使用 |
|
|
|
dependencies.cfg-sample |
| 未使用 |
|
|
|
escalations.cfg-sample |
nagios.cfg 編集
上記の構成の設定ですので、未使用のファイルをコメントアウトする
nagios.cfg の一部
(一部)
# cfg_file=/usr/local/nagios/etc/contactgroups.cfg
cfg_file=/usr/local/nagios/etc/contacts.cfg
# cfg_file=/usr/local/nagios/etc/dependencies.cfg
# cfg_file=/usr/local/nagios/etc/escalations.cfg
# cfg_file=/usr/local/nagios/etc/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/hosts.cfg
cfg_file=/usr/local/nagios/etc/services.cfg
cfg_file=/usr/local/nagios/etc/timeperiods.cfg
# external commandsを有効に
check_external_commands=1
cgi.cfg
Apacheの設定時に、アクセス可能なユーザーを作成したが
nagiosadmin,guest,user
の各ユーザーのアクセス権限等を設定する。
(一部)
authorized_for_system_information=nagiosadmin,user 以下、個々にアクセス権を与えるユーザーを追加
authorized_for_system_information=nagiosadmin
authorized_for_configuration_information=nagiosadmin
authorized_for_system_commands=nagiosadmin
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin
hosts.cfg 作成
# /usr/local/nagios/etc/hosts.cfg
define host{
name generic-host ;テンプレート名
notifications_enabled 1 ;通知の有無
event_handler_enabled 1 ;イベントハンドラの有無
flap_detection_enabled 1 ;状態反転の検出
process_perf_data 1 ;パフォーマンス統計
retain_status_information 1 ;状態情報の保存
retain_nonstatus_information 1 ; 状態以外の情報の保存
check_command check-host-alive
max_check_attempts 10 ;最大リトライ回数
notification_interval 120 ;通知間隔
notification_period 24x7 ;通知時間帯
notification_options d,u,r ;通知オプション
register 0 ;このオプションにてtemplateと認識させる
}
define host{
use generic-host ;使用するテンプレート名
host_name b-dash1 ;ホスト名
alias b-dash1 ;エイリアス
address 192.168.1.1 ;IPアドレス
}
define host{
use generic-host ;使用するテンプレート名
host_name b-dash2 ;ホスト名
alias b-dash2 ;エイリアス
address 192.168.1.2 ;IPアドレス
parents b-dash1 ;親子関係
}
##今回はhostgroup.cfgを使わず、host.cfgにまとめる
define hostgroup{
hostgroup_name b-dash-hostgroup
alias b-dash-hostgroup
contact_groups b-dash-contactgroup
members b-dash1,b-dash2
}
contact.cfg 作成
#/usr/local/nagios/etc/contact.cfg
define contact{
name generic-contact
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r ;Warning Unknown Critical Recover None
host_notification_options d,u,r ;Down Unreachable recover
service_notification_commands notify-by-email,notify-by-epager
host_notification_commands host-notify-by-email,host-notify-by-epager
register 0
}
define contact{
use generic-contact
contact_name admin
alias admin
email hogehoge@b-dash.net <---必ず書き換えて
pager pager@b-dash.net <---下さい
}
##今回はcontactgroup.cfgを使わず、contact.cfgにまとめる
define contactgroup{
contactgroup_name b-dash-contactgroup
alias b-dash-contactgroup
members admin
}
service.cfg 作成
# /usr/local/nagios/etc/service.cfg
define service{
name generic-service
check_period 24x7
max_check_attempts 3 ;リトライ回数
normal_check_interval 10 ;検知間隔
retry_check_interval 1 ;リトライ間隔
notification_interval 120 ; 通知間隔
notification_period 24x7
notification_options w,u,c,r ;Warning Unknown Critical Recover None
register 0
# contact_groups admins ;今回はホストごとに設定する
}
define service{
use generic-service
host_name b-dash2
service_description HTTP
check_command check_http
contact_groups b-dash-contactgroup
}
define service{
use generic-service
host_name b-dash1
service_description PING
check_command check_ping!100.0,20%!500.0,60%
contact_groups b-dash-contactgroup
}
ここまで、終わったら設定ファイルを確認してみる。
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
(省略)
Checking misc settings...
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
エラーが出たら、設定ファイルを再度確認してください。
確認が終わったら起動します。
# /etc/init.d/nagios start
Starting network monitor: nagios
PID TTY TIME CMD
4445 ? 0:00 nagios
ブラウザで確認
http://<userserver>/nagios/
認証画面が出ますので、apacheの設定で作成したnagiosadminでログインし、確認します。
※3D-Status Map表示には、VRML用プラグインが必要…らしい^^;
送信メールのカスタマイズ(qmail使用)
さて、Nagiosの起動まではうまくいきましたが、デフォルトのメール送信の設定は
/usr/bin/mailの使用を想定しています。
misccommands.cfgのcommand_lineのメール送信の部分
command_line /usr/bin/printf "%b" "***** Nagios 1.0b4 *****\n\n
Notification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\n
Host: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\n
Date/Time: $DATETIME$\n\nAdditional Info:\n\n$OUTPUT$"
| /usr/bin/mail -s "** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$
is $SERVICESTATE$ **" $CONTACTEMAIL$
うちの環境ではSMTPにqmailを使っていますのでqmail-injectを使い送信するように、
以下のように編集しました、
(From:とReturn-Path:を追加、すべて一行につなげて下さい)
command_line /usr/bin/printf "Return-Path: <hogehoge@hoge.net>\n
From: hogehoge@hoge.net\nTo: $CONTACTEMAIL$\nSubject: ** $NOTIFICAT
IONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **\n\n
***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n
\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$
\nState: $SERVICESTATE$\n\nDate/Time: $DATETIME$\n\nAdditional Info
:\n\n$OUTPUT$\n" | /var/qmail/bin/qmail-inject
そのほかのメール送信部分(全部で4箇所)も上記を参考に変更します。
|