SYONテクニカル

Nagiosでのネットワーク監視

2006/04/25
サイオンコミュニケーションズ株式会社
大城 智博

1.はじめに

仕事上ネットワークの監視を行う必要があるため、いろいろな監視ツールをインストールして、
試しています。
今回は「Nagios」を試してみる事にしました。

 

2.マシン環境

今回、設定するマシン環境は次のとおりです。

FreeBSD 6.0-RELEASE-p6
nagios-2.2
apache-2.0.55_4

 

3.Nagiosの設定と起動

3.1 Nagiosのインストール

portsにてNagiosをインストール

# cd /usr/ports/net-mgmt/nagios/
    # make

    [ ] EMBEDDED_PERL  Enable embedded Perl [requires Perl 5.8+]
    [ ] NANOSLEEP      Use nanosleep in event timing

                      [OK]         Cancel

今回はそのまま、「OK」にて継続します。

# make install

    [ ] QSTAT    Game server query support
    [X] FPING    Support for non-flooding fast ping
    [ ] NETSNMP  SNMP support
    [ ] RADIUS   Radius support
    [ ] MYSQL    MySQL support
    [ ] PGSQL    PostgreSQL support
    [ ] LDAP     OpenLDAP support
    [ ] IPV6     IPV6 support

                      [OK]         Cancel

pluginの設定を行います。

 

3.2 Nagiosの設定

Nagiosが起動するように、rc.confファイルに設定を追加

# vi /etc/rc.conf
    nagios_enable="YES"

サンプルファイルをコピーして、使用可能にします。

# cd /usr/local/etc/nagios/
    # cp nagios.cfg-sample nagios.cfg
    # cp cgi.cfg-sample cgi.cfg
    # cp checkcommands.cfg-sample checkcommands.cfg
    # cp minimal.cfg-sample minimal.cfg
    # cp misccommands.cfg-sample misccommands.cfg
    # cp resource.cfg-sample resource.cfg

Nagiosの設定は複数のファイルに分散していますので、核となるnagios.cfgにて
使用するファイルの設定をします。

# vi nagios.cfg
    #cfg_file=/usr/local/etc/nagios/checkcommands.cfg
    #cfg_file=/usr/local/etc/nagios/misccommands.cfg
    cfg_file=/usr/local/etc/nagios/hosts.cfg
    cfg_file=/usr/local/etc/nagios/hostgroups.cfg
    cfg_file=/usr/local/etc/nagios/contacts.cfg
    cfg_file=/usr/local/etc/nagios/contactgroups.cfg
    cfg_file=/usr/local/etc/nagios/services.cfg

監視するホストの設定

# vi hosts.cfg
    define host{
        name                      template-name      ;テンプレート名
        max_check_attempts        5                  ;最大リトライ数
        contact_groups            contact-groups     ;contactグループ名
        notification_interval     60                 ;通知する間隔
        register                  0                  ;この設定をテンプレートとする
    }
    define host{
        use                       template-name      ;使用するテンプレート名
        host_name                 router-name        ;ホスト名
        alias                     Router Name        ;ホスト名の別名
        address                   192.168.0.1        ;IPアドレス
    }
    define host{
        use                       template-name
        host_name                 host-name
        alias                     Host Name
        address                   172.16.0.2
        parents                   router-name        ;親となるホスト
    }

ホストのグループ設定

# vi hostgroups.cfg
    define hostgroup{
        hostgroup_name            group-name                ;グループ名
        alias                     Group-Name                ;グループ名の別名
        members                   router-name,host-name     ;グループに含まれるホスト
    }

通知に関する設定

# vi contacts.cfg
    define contact{
        contact_name                  contact-name         ;contact名
        alias                         Contact Name         ;contacの別名
        service_notification_period   24x7                 ;通知時間帯(サービス監視)
        host_notification_period      24x7                 ;通知時間帯(ホスト監視)
        service_notification_options  w,u,c,r              ;通知する状態(サービス監視)
        host_notification_options     d,u,r                ;通知する状態(ホスト監視)
        service_notification_commands notify-by-email      ;通知コマンド名(サービス監視)
        host_notification_commands    host-notify-by-email ;通知コマンド名(ホスト監視)
        email                         admin@example.com    ;E-Mailアドレス
        pager                         keitai@example.ne.jp ;携帯用E-Mailアドレス
    }

contactのグループ設定

# vi contactgroups.cfg
    define contactgroup{
        contactgroup_name               contact-groups    ;contactグループ名
        alias                           Contact Groups    ;contactグループの別名
        members                         contact-name      ;グループに含まれるcontact
    }

監視方法の設定

# vi services.cfg
    define service{
        name                            ping-check        ;テンプレート名
        service_description             PING              ;説明
        check_command                   check_ping        ;監視方法(ping)
        max_check_attempts              5                 ;最大リトライ数
        normal_check_interval           5                 ;監視間隔
        retry_check_interval            3                 ;リトライ時の間隔
        check_period                    24x7              ;監視時間帯(サービス監視)
        notification_interval           30                ;通知の間隔
        notification_period             24x7              ;監視時間帯(ホスト監視)
        notification_options            w,c,r             ;通知する状態
        contact_groups                  contact-groups    ;contactグループ名
        register                        0                 ;この設定をテンプレートとする
    }
    define service{
        use                             ping-check        ;使用するテンプレート名
        hostgroup_name                  group-name        ;監視対象
    }

cgi.cfgの設定(Basic認証機能をoffに設定)

# vi cgi.cfg
    use_authentication=0

設定が正常であることを確認し、サービスの起動

# /usr/local/bin/nagios -v /usr/local/etc/nagios/nagios.cfg
       :
    Total Warnings: 0
    Total Errors:   0

    Things look okay - No serious problems were detected during the pre-flight check

    # /usr/local/etc/rc.d/nagios.sh start
    Performing sanity check of nagios configuration: OK
    Starting nagios.

 

4.Apacheを設定し、ブラウザにて確認

# vi /usr/local/etc/apache2/httpd.conf
    <Directory /usr/local/www/nagios>
      Order allow,deny
      Allow from all
    </Directory>

    <Directory /usr/local/www/nagios/cgi-bin>

      Options ExecCGI
    </Directory>

    # apachectl restart

ブラウザにて、状態の確認を行ってください。

http://IPアドレス/nagios/index.html

 

5.最後に

「Nagios」は多機能な監視ツールですが、機能の一つにネットワーク階層化があります。
この機能により、ルータなどを挟んで遠隔地にサーバが複数がある環境で、ルータに障害が発生した時は一通のメールで済みます。

Copyright 1999-2008 SYON Communications, Co. All rights reserved