2010 5月 4

NRPEとは、Nagios Remote Plugin Executerの略で、監視対象サーバにインストールされた監視プラグインをリモート実行するためのアドオンだ。
今回は、このNagiosの監視プラグインをリモート実行するためのアドオンであるNRPEのインストール方法を紹介する。
NRPEは、Nagiosと監視対象サーバ間の通信を暗号化できるという機能を持つ。
ZABBIXにも、プロキシというNRPEと同じような機能があるようだが、現時点では通信の暗号化はできないようだ。
また、NRPEには以下の2通りの利用方法がある。

1.監視対象サーバにインストールされた監視プラグインのリモート実行
2.監視中継サーバの構築

1番目の利用方法は、NRPEの本道だ。
Nagios側にインストールしたcheck_nrpeで、監視対象サーバにインストールしたnrpeを通して、監視対象サーバの監視プラグインをリモート実行する。

Nagios(check_nrpe) → 監視対象サーバ(nrpe ⇒ 監視プラグイン)

2番目の利用方法は、Nagiosの代わりに監視を行うための監視中継サーバを構築する方法だ。
Nagios側にインストールしたcheck_nrpeで、監視中継サーバにインストールしたnrpeを通して、監視中継サーバのcheck_nrpeをリモート実行し、さらに監視対象サーバにインストールしたnrpeを通して、監視対象サーバの監視プラグインをリモート実行する。

Nagios(check_nrpe) → 監視中継サーバ(nrpe ⇒ check_nrpe) → 監視対象サーバ(nrpe ⇒ 監視プラグイン)

監視中継サーバは、監視対象サーバにインストールされた監視プラグインのリモート実行だけでなく、HTTP監視(check_http)などの他の監視も全て行うサーバだ。

Nagios(check_nrpe) → 監視中継サーバ(nrpe ⇒ check_http) → 監視対象サーバ

監視中継サーバは、他の監視システムでは、監視エンジンや情報収集サーバと呼ばれるものだ。
この構成では、Nagiosは監視スケジューラ、監視結果表示、アラート通知などの監視マネージャ機能のみを担当することになるため、負荷の軽減になる。
この利用方法では、監視対象がFWの内部にあるような場合、監視中継サーバを内部におくことで、FWは外部のNagiosと監視中継サーバ間のポートを開けるだけすむため、セキュリティリスクの軽減につながる。
このブログを書いている現在時点でのNRPEの最新版は2.12 だ。
以前、インストールしたNagios(3.1.0)にインストールを行う。
サーバOSは、CentOS 5.3 である。
 


 

ダウンロード

今回必要なものは以下の通りだ。
 
●NRPE : nrpe-2.12.tar.gz (本家Nagiosサイトのダウンロードページ
 
ダウンロードしたtarballは、/usr/local/src に置くものとする。
 

インストールマニュアル

NRPEのインストールマニュアルは、ダウンロードしたtarballに含まれている。
tarballを、解凍すると以下にインストールマニュアルがある。

./nrpe-2.12/docs/NRPE.pdf
 
また、全ての作業は特に断りがない限りrootアカウントで行うものとする。
 

システム要求

特になし。
 

NRPEのインストール

NRPEのインストールには、以下の2つがある。

1.Nagios側へのcheck_nrpeのインストール
2.監視中継サーバ、監視対象サーバへのnrpeデーモンのインストール

1のインストールは実に簡単だ。
 

# cd /usr/local/src
# tar xzvf nrpe-2.12.tar.gz
# cd nrpe-2.12
# ./configure --enable-command-args

<省略>

*** Configuration summary for nrpe 2.12 03-10-2008 ***:

General Options:
-------------------------
NRPE port: 5666
NRPE user: nagios
NRPE group: nagios
Nagios user: nagios
Nagios group: nagios
 
 
Review the options above for accuracy. If they look okay,
type 'make all' to compile the NRPE daemon and client.

# make all

<省略>

*** Compile finished ***

If the NRPE daemon and client compiled without any errors, you
can continue with the installation or upgrade process.

Read the PDF documentation (NRPE.pdf) for information on the next
steps you should take to complete the installation or upgrade.

# make install-plugin

 
2のインストールには、nagiosアカウントの作成が必要だ。
また、NRPEはxinetdの配下で動かすこともできるのだが、Jラボ環境では頻繁にxinetdのエラーが発生したため、NRPEをxinetdの下で実行させず、単独のデーモンとして起動させた。
今回も同様に単独のデーモンとして起動するようインストールする。
 

# useradd -d /usr/local/nagios -m -s /bin/bash nagios
# cd /usr/local/src
# tar xzvf nrpe-2.12.tar.gz
# cd nrpe-2.12
# ./configure --enable-command-args

<省略>

*** Configuration summary for nrpe 2.12 03-10-2008 ***:

General Options:
-------------------------
NRPE port: 5666
NRPE user: nagios
NRPE group: nagios
Nagios user: nagios
Nagios group: nagios
 
 
Review the options above for accuracy. If they look okay,
type 'make all' to compile the NRPE daemon and client.

# make all

<省略>

*** Compile finished ***

If the NRPE daemon and client compiled without any errors, you
can continue with the installation or upgrade process.

Read the PDF documentation (NRPE.pdf) for information on the next
steps you should take to complete the installation or upgrade.

# make install-plugin
# make install-daemon
# make install-daemon-config

NRPEデーモンをサービスに登録する。
7880行目に追加した。
 

# vi /etc/services

7880 nrpe            5666/tcp                        # NRPE

起動スクリプトを作成し、chkconfigへ登録する。
以下の起動スクリプトは、SSLなし(-n)で起動するためのものだ。
OPTIONS=”-n -c $CONF –daemon” となっている部分を OPTIONS=”-c $CONF –daemon” とすることでSSLモードで起動するようになる。
 

# vi /etc/init.d/nrpe

-----------------------------------------------------------------------------------
#!/bin/sh
#
# chkconfig: 345 99 01
# description: NRPE (Nagios Remote Process Executer)
#
# File : nrpe
#


NRPE=/usr/local/nagios/bin/nrpe
CONF=/usr/local/nagios/etc/nrpe.cfg

/usr/bin/test -f $NRPE || exit 0

# Check for conf file, if there isn't one there bomb out
/usr/bin/test -f $CONF || exit 0

OPTIONS="-n -c $CONF --daemon"

cd /

case "$1" in
start)
        if [ -x $NRPE ]
        then
            /usr/bin/env - $NRPE $OPTIONS
        fi
        ;;

stop)
        if [ -x /usr/bin/pkill ]
        then
            /usr/bin/pkill -x -u nagios nrpe
        else
            pid=`/usr/bin/ps -e |
              /usr/bin/grep -w nrpe |
              /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
            [ "$pid" != "" ] && kill $pid
        fi
        ;;

*)
        echo "Usage: $0 {start|stop}"
        exit 1
        ;;
esac

exit 0
-----------------------------------------------------------------------------------

# chmod 755 /etc/init.d/nrpe
# chkconfig --add nrpe
# chkconfig --list nrpe

nrpe            0:off   1:off   2:off   3:on    4:on    5:on    6:off

 

Nagiosとの連携

次にNagiosとの連携を考慮して、NRPEの設定ファイルを変更する。
変更方針は以下の通り。
1)NRPEを実行できるのはNagiosサーバに限定する。
  ・79行目のallowed_hostsにNagiosサーバのIPアドレスを追加
2)Nagios側で監視の閾値を指定できるようにする。
  ・95行目のdont_blame_nrpeを1に変更
  ・199~203行目のコマンド設定の閾値を引数指定できるようにする
 

# cd /usr/local/nagios/etc
# cp nrpe.cfg nrpe.cfg.org
# vi nrpe.cfg

<省略>

77 # NOTE: This option is ignored if NRPE is running under either inetd or xinetd
78
79 allowed_hosts=127.0.0.1,192.168.xxx.xxx

<中略>

93 # Values: 0=do not allow arguments, 1=allow command arguments
94
95 dont_blame_nrpe=1

<中略>

199 command[check_users]=/usr/local/nagios/libexec/check_users -w $ARG1$ -c $ARG2$
200 command[check_load]=/usr/local/nagios/libexec/check_load -w $ARG1$ -c $ARG2$
201 command[check_hda1]=/usr/local/nagios/libexec/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
202 command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w $ARG1$ -c $ARG2$ -s Z
203 command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w $ARG1$ -c $ARG2$

 

NRPEの起動と確認

次にNRPEの起動と確認を行う。
 

# service nrpe start
# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12

 
 
 

 


Categories: Nagios ,NRPE


Leave a Reply