RIGHT:[[フリーソフトウェアのコンパイル]]

*インストール,初期設定 [#db383e70]
 # yum --enablerepo=epel install nagios nagios-plugins-all
 
 # vi /etc/nagios/objects/contacts.cfg
define contact{ ディレクティブの email の部分を変更
 email          admin@example.com;

 # vi /etc/httpd/conf.d/nagios.conf
~<Directory "/usr/lib64/nagios/cgi-bin/"> ディレクティブの
Order 行,Deny, Allow 行を適宜編集
(デフォルトのままだと,認証を通ったユーザならどこからでもアクセス可能)

BASIC 認証で試用するユーザのパスワードをつける
 # htpasswd /etc/nagios/passwd nagiosadmin

デーモン起動(あわせて,OS 起動時に自動起動するよう設定)
 # /etc/init.d/nagios start
 # chkconfig nagios on

*サーバ監視の設定 [#cccfcc55]
/etc/nagios/nagios.cfg 内の
 cfg_file=/etc/nagios/objects/localhost.cfg
の行をコメントアウトし,変わりに
 cfg_file=/etc/nagios/objects/myservers.cfg
を追加する.

 # cp /etc/nagios/objects/localhost.cfg /etc/nagios/objects/myservers.cfg
として
 # vi /etc/nagios/objects/myservers.cfg
で編集.

記述内容の詳細は,探せばたくさんあるので記述しないが,注意点だけ.

**host ディレクティブ [#ffab6326]
***max_check_attempts [#z3d5376b]
テンプレートとして,linux-server を使う場合,
  max_check_attempts
の値を小さな数字にしておかないと,
notification mail がなかなか来ない.
(テンプレートでは 10となっているので 5 にした)

***notification_period [#b2426947]
テンプレートとして,linux-server を使う場合,
デフォルトは
 notification_period workhours
となっているので,
 notification_period 24x7
と変更する.

***parents [#uce56445]
host ディレクティブで
 parents      myswitch
などとして,スイッチなど上位の機器を指定して,
依存関係を記述できる.
(上記の場合,myswitch が down していれば,
その向こう側にあるこのホストが down しているとは受け取られない.)

もっと複雑な依存関係を設定するなら,ホスト依存定義(hostdependency)をする.

***アイコン [#c7b07cf9]
マップに表示されるアイコンを
 statusmap_image
で指定する.

アイコンファイルの実体は,
 /usr/share/nagios/html/images/logos/
に置く.

***notification_interval [#b5a24fb7]
notification_interval をちょっと長めに指定しておかないと,
ダウンしている際に,何回もメールが飛んできてうっとおしい.

本当は,エスカレーションの設定(hostescalation,serviceescalation)の設定をしたほうがいい.

**service ディレクティブ [#bd7f849e]
***http [#z461b665]
http で特定のページにアクセスして,死活を監視する場合,
以下のように指定する.
 check_command       check_http!-u /robots.txt

***mysql [#o5f2c430]
mysql の死活監視設定例
 define service{
        use                   generic-service
        host_name             dbsrv
        service_description   MYSQL
        check_command         check_mysql!root!password
        notifications_enabled 1
        }

check_command の引数は "!" に続けて指定する.

また,後述する check コマンド設定を追加する.

***NFS [#ea674891]
NFS の死活監視設定例
 define service{
        use                   generic-service
        host_name             nfssrv
        service_description   NFS
        check_command         check_rpc!nfs
        notifications_enabled 1
        }

check_command の引数は "!" に続けて指定する.

また,後述する check コマンド設定を追加する.

*スイッチ,LB監視の設定例 [#geb33677]
/etc/nagios/nagios.cfg 内の
 # cfg_file=/etc/nagios/objects/switch.cfg
の行をアンコメントする.

 # vi /etc/nagios/objects/switch.cfg
記述内容の詳細は,探せばたくさんあるので記述しない.

----
*check コマンドの設定追加 [#k3e9405f]
/usr/lib64/nagios/plugins にあるプラグインを実行して,
利用方法を確認.
引数は,"!"のあとに続けて書く.

 # vi /etc/nagios/objects/commands.cfg

 # 'check_mysql' command definition
 define command{
         command_name   check_mysql
         command_line   $USER1$/check_mysql -H $HOSTADDRESS$ -u $ARG1$ -p $ARG2\
$
         }

 # 'check_rpc' command definition
 define command{
         command_name   check_rpc
         command_line   $USER1$/check_rpc -H $HOSTADDRESS$ -C $ARG1$
         }
----
*メールの差出人を変更する [#e5a936be]
**標準モジュールだけで行うなら [#tb92c9c1]
設定ファイル(/etc/nagios/objects/commands.cfg)に以下のような変更を加える.
(mail コマンドの "-r" オプションンに差出人を書く)
 define command{
         command_name   notify-host-by-email
         command_line   /usr/bin/printf "%b" "***** Nagios *****\n\nNotificatio\
n
  Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOS\
TA
 DDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "**\
 $
 NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -r 差出人アドレス \
$CONTACTEMAIL$
         }

**Flexible Notifications for Nagios を使う [#o7b04321]
これを使うことで,日本語でのメールが送れたり,
HTML などのリッチコンテンツでのメールを送ることができる.
-http://nagios.frank4dd.com/howto/nagios-flexible-notifications.htm
-http://umiushi.dip.jp/wordpress/?p=217

/usr/lib64/nagios/plugins/ に frank4dd という名で
ディレクトリを作成する.
その中にダウンロードしたファイルをコピーする.
 # ls -l /usr/lib64/nagios/plugins/frank4dd/
 合計 92
 -rwxr-xr-x. 1 root root 43972  9月 24 17:34 2013 nagios_send_host_mail.pl
 -rwxr-xr-x. 1 root root 45249  9月 24 17:35 2013 nagios_send_service_mail.pl

コピーしたそれぞれのファイルを編集し,
 my $mail_sender        = "Nagios Monitoring <nagios\@frank4dd.com>";
 my $domain             = "\@example.com";
の部分を,送信者のアドレスに変更する.


設定ファイル(/etc/nagios/objects/commands.cfg)に以下のような行を加える.
# notify mail in Japanese
 define command{
         command_name    email-html-host-jp
         command_line    $USER1$/frank4dd/nagios_send_host_mail.pl \
                         -H 127.0.0.1 -f text -l jp
         }
 
 define command{
         command_name    email-html-service-jp
         command_line    $USER1$/frank4dd/nagios_send_service_mail.pl \
                         -H 127.0.0.1 -f text -l jp
         }

/etc/nagios/objects/contacts.cfg を編集し,
host_notification_commands と service_notification_commands を
以下のようにオーバーライドする.

        host_notification_commands      email-html-host-jp
        service_notification_commands   email-html-service-jp

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS