Nagios 設定 · 1 min read · Oct 18, 2025

Debian Lenny に Nagios をインストールし、Debian Lenny サーバーを監視する - ページ 2

7. server1 からモニターサーバーへのローカルサービスの導入

新しいサービスを監視するために、ステップ 5 で作成した hostconfig を変更する必要があります。

monitor:~# nano /etc/nagios3/conf.d/server1_nagios2.cfg

ファイルの最後にこれを追加します:

define service{
        use                     generic-service
        host_name               server1
        service_description     Current Load
        check_command           check_nrpe_1arg!check_load
}
define service{
        use                     generic-service
        host_name               server1
        service_description     Current Users
        check_command           check_nrpe_1arg!check_users
}
define service{
        use                     generic-service
        host_name               server1
        service_description     Disk Space
        check_command           check_nrpe_1arg!check_hda1
}
define service{
        use                     generic-service
        host_name               server1
        service_description     Total Processes
        check_command           check_nrpe_1arg!check_total_procs
}

nagios サービスを再起動します:

monitor:~# /etc/init.d/nagios3 restart

ウェブサービスでは、追加されたサービスが表示されるはずで、徐々にそれらが取得されるはずです。そのうちの一つ、ディスクスペースのチェックは、/dev/hda1 パーティションやデバイスがないため、失敗する可能性が高いです。

monitor1 サーバーでこのチェックを変更して、実際に確認したいパーティションを反映させます。私の場合、マシンは xen によってホストされる仮想サーバー上にあり、server1 で次のコマンドを使用して使用されているパーティションを特定できます:

server1:~# df -h
Filesystem            Size  Used Avail Use% Mounted on  
 /dev/mapper/iscsi1-root  
                     7.3G  714M  6.2G  11% /  
 tmpfs                 137M     0  137M   0% /lib/init/rw  
 udev                  10M  568K  9.5M   6% /dev  
 tmpfs                 137M     0  137M   0% /dev/shm  
 /dev/xvda1          228M  9.5M  207M   5% /boot

これにより、パーティションとそのマウントポイントが表示されます。私の場合、実際の ‘root’ パーティションは /dev/mapper/iscsi1-root であり、マウントポイント ‘/‘ を探すことでこれを発見しました。

これで、チェックが機能するようにサーバー上の nrpe 設定を変更し続けることができます。これには、再度 nrpe.cfg ファイルを開きます:

server1:~# nano /etc/nagios/nrpe.cfg

次に、(デフォルトでは 201 行目)を含む行に移動します:

command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1

そして、次のように変更します:

command[check_iscsi1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/iscsi1-root

Nagios サーバーの hostconfig を変更して、これらの変更を反映させます:

monitor:~# nano /etc/nagios3/conf.d/server1_nagios2.cfg

次のように:

define service{
        use                     generic-service
        host_name               server1
        service_description     Disk Space
        check_command           check_nrpe_1arg!check_hda1
}

から:

define service{
        use                     generic-service
        host_name               server1
        service_description     Disk Space
        check_command           check_nrpe_1arg!check_iscsi1
}

両方のサービスを再起動します。

server1:~# /etc/init.d/nagios-nrpe-server restart  
 monitor:~# /etc/init.d/nagios3 restart
 

8. メールによる通知の設定

サービスがクリティカルな状態になると、メールで通知を受け取りたいと思います。したがって、nagiosadmin ユーザーのメールアドレスを設定する必要があります。

ファイル /etc/nagios3/conf.d/contacts_nagios2.cfg に移動し、メールアドレスを自分のものに変更します。さらにユーザーを追加したい場合は、’define contact’ セクションをコピーし、それを使用して 2 番目のものを作成し、下の contactgroup にユーザーを追加します。

define contact{
        contact_name                    root
        alias                           Root
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,r
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
        email                           [email protected]
        }
        
define contact{
        contact_name                    example
        alias                           example
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,r
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
        email                           [email protected]
        }
define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 root,example
        }

シンプルなメール通知を有効にするには、Debian システムの smtp トランスポートを有効にする必要があります。Nagios が行うことは、メッセージを Linux パイプを介して標準プログラム /usr/bin/mail に渡すことだけです。

Postfix をインストールし、Nagios サーバーが自分自身でメールを送信できるように基本的な設定を行う必要があります。

monitor:~# apt-get install postfix mailx

次に、Postfix を「インターネットサイト」として設定し、Nagios メールが送信されるドメインを設定します。

その後、再起動し、テストサーバーで apache サービスを停止します:

monitor:~# /etc/init.d/nagios3 restart  
 server1:~# /etc/init.d/apache2 stop

これにより、contacts_nagios2.cfg ファイルにメールアドレスを設定していれば、通知メッセージが作成され、受信されるはずです。

雑記: Icinga について

Icinga は、より大きな開発者コミュニティを持つ Nagios のフォークであり、将来的には使用されるソフトウェアになる可能性が高いです。Icinga に関するハウツーは HowtoForge で見つけることができ、Nagios プラグインを使用することができるように、カスタムプラグインを Icinga で再利用できます。

誰にでも Nagios と Icinga を使って遊んでみることをお勧めします。

Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。