今日はリモートのリソースをnagiosで監視する手順です。
nrpeというプラグインを監視サーバとクライアントの双方にインストールします。

・サーバ側

[root@test01 ~]# rpm -qa | grep openssl-devel
openssl-devel-0.9.8e-22.el5_8.4

opensslがインストールされていることを確認します。

[root@test01 ~]# cd /usr/local/src/
[root@test01 src]# wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz/download

[root@test01 src]# tar zxf nrpe-2.15.tar.gz
[root@test01 src]# cd nrpe-2.15

[root@test01 nrpe-2.15]# ./configure
[root@test01 nrpe-2.15]# make
[root@test01 nrpe-2.15]# make install 

nrpeのプラグインをダウンロードしてきて、解凍、コンパイル、インストールを行ないます。

[root@test01 nrpe-2.15]# ls /usr/local/nagios/libexec/check_nrpe
/usr/local/nagios/libexec/check_nrpe

無事、プラグインがサーバ側にインストールされました。

・クライアント側

[root@localhost ~]# rpm -qa | grep openssl-devel
openssl-devel-1.0.0-20.el6.x86_64

同じようにopensslがインストールされていることをクライアント側でも確認します。

[root@localhost ~]# useradd -d /usr/local/naios/ -M nagios
[root@localhost ~]# mkdir /usr/local/nagios
[root@localhost ~]# chown nagios:nagios /usr/local/nagios/

nagios用のユーザー、グループ、パスを作成します。

[root@localhost src]# wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz/download
[root@localhost src]# tar xvf nrpe-2.15.tar.gz
[root@localhost src]# cd nrpe-2.15
[root@localhost nrpe-2.15]# ./configure
[root@localhost nrpe-2.15]# make nrpe
[root@localhost nrpe-2.15]# make install-daemon
[root@localhost nrpe-2.15]# make install-daemon-config

nrpeのダウンロード、解凍、コンパイル、インストールを行ないます。

[root@localhost src]# wget http://www.nagios-plugins.org/download/nagios-plugins-2.0.2.tar.gz
[root@localhost src]# tar zxvf nagios-plugins-2.0.2.tar.gz
[root@localhost src]# cd nagios-plugins-2.0.2
[root@localhost nagios-plugins-2.0.2]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@localhost nagios-plugins-2.0.2]# make
[root@localhost nagios-plugins-2.0.2]# make install

同じようにnagios-pluginもダウンロード、解凍、コンパイル、インストールを行ないます。

[root@localhost nagios-plugins-2.0.2]# vi /usr/local/nagios/etc/nrpe.cfg

allowed_hosts=127.0.0.1,172.17.9.104 

nrpeのコンフィグファイルを開き、許可ホストに監視サーバを追加します。

[root@localhost ~]# cp /usr/local/src/nrpe-2.15/init-script /etc/rc.d/init.d/nrpe
[root@localhost ~]# chmod 755 /etc/rc.d/init.d/nrpe
[root@localhost ~]# chkconfig --add nrpe
[root@localhost ~]# chkconfig nrpe on
[root@localhost ~]# chkconfig --list nrpe
[root@localhost ~]# service nrpe start
Starting nrpe:                                             [  OK  ]

サービス起動スクリプトを解凍フォルダからコピーして、起動時のサービスとして登録します。

[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% マウント位置
/dev/mapper/VolGroup-lv_root
                       12G  2.3G  8.6G  22% /
tmpfs                1004M     0 1004M   0% /dev/shm
/dev/sda1             485M   32M  428M   7% /boot

今回はディスクスペース監視を行なってみたいので、dfでデバイス名を確認します。

[root@localhost ~]# vi /usr/local/nagios/etc/nrpe.cfg

command[check_root]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/mapper/VolGroup-lv_root

nrpeのcfgファイルを開き、ディスクスペースの監視コマンドを登録します。
このコマンドをサーバ側から呼び出します。

・サーバ側

[root@test01 ~]# vi /usr/local/nagios/etc/objects/commands.cfg

define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }

[root@test01 ~]# vi /usr/local/nagios/etc/servers/redhat.cfg

define service{
        use                     local-service
        host_name               redhat
        service_description     Disk check root
        check_command           check_nrpe!check_root
        }

サーバ側に戻り、クライアント側で作成したコマンドを呼び出すコマンドの定義、およびに監視項目の追加を行ないます。

[root@test01 ~]# service nagios restart
Running configuration check...
Stopping nagios: done.
Starting nagios: done.

サービスを再起動し、設定を有効にします。

1

nagiosのWEB画面を開き、監視項目が追加されていることを確認します。