NRPE(Nagios監視ツール) のインストール

2021-06-18

概要

監視ツールして、nagios をインストールしました
その時にインストール時のメモです。

構成情報

OS

  • CentOS5.5

ミドルウェア

  • Nagios 3.2.3
  • apache 2.2.3-43

※上記の環境を、VirtualBOXで構築しています

HOST

+-----------------------------------------------------------------+
| HOSTNAME | IP [eth0] | 役割、起動サービスなど
+-----------------------------------------------------------------+
| ex-www01 | 192.168.0.110 | nagios サーバ
| ex-ns1 | 192.168.0.100 | 監視対象サーバー
+-----------------------------------------------------------------+

【作業内容】

  • nrpe のダウンロード:Nagiosサーバー側
  • nrpe のインストール:監視対象サーバー側
  • nagios-plugins のインストール:監視対象サーバー側
  • nrpe の設定:監視対象サーバー側
  • nrpe の設定:Nagiosサーバー側

nrpe のダウンロード:Nagiosサーバー側

(1)OPEN SSLがインストールされていないとエラーとなるのでopensslをインストール

# yum -y install openssl openssl-devel

(2)nrpe ダウンロード及びインストール

# cd /usr/local/src
# wget http://jaist.dl.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
# tar zxvf nrpe-2.12.tar.gz
# cd nrpe-2.12
# ./configure
# make all
# make install

nrpe のインストール:監視対象サーバー側
監視対象サーバー(192.168.0.100)に、nrpe をインストールします

(1)xinetd openssl-develをインストール

# yum -y install xinetd openssl-devel

(2)nagiosを追加します。また、Nagiosサーバー側 のuid/gidと同じにします

# groupadd -g 1001 nagios
# useradd -d /usr/local/nagios/ -u 1001 -g 1001 nagios

# ls -l /usr/local|grep nagios
drwx------ 2 nagios nagios 4096 5月 28 16:58 nagios

(3)nrpe ダウンロード及びインストール

# cd /usr/local/src
# wget http://jaist.dl.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
# tar zxvf nrpe-2.12.tar.gz
# cd nrpe-2.12
# ./configure
# make all
# make install

(4)nrpe の起動スクリプトの設定及び自動起動の設定

# cp -p init-script /etc/rc.d/init.d/nrpe
# chmod 755 /etc/rc.d/init.d/nrpe
# chkconfig --add nrpe
# chkconfig nrpe on
# chkconfig --list nrpe
nrpe 0:off 1:off 2:on 3:on 4:on 5:on 6:off

(5)nrpe 設定ファイルを配置します

# mkdir /usr/local/nagios/etc
# cp -p sample-config/nrpe.cfg /usr/local/nagios/etc
# chown nagios:nagios /usr/local/nagios/etc
# chown nagios:nagios /usr/local/nagios/etc/nrpe.cfg

nagios-plugins のインストール:監視対象サーバー側

nagios-plugins をインストールします

# cd /usr/local/src
# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
# tar zxvf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins-1.4.15
# ./configure --prefix=/usr/local/nagios
# make all
# make install

nrpe の設定:監視対象サーバー側

(1)check_procs の動作確認

nagiosのプラグインの動作確認をおこないます、今回は、check_procsでテストします

# /usr/local/nagios/libexec/check_procs -c 1: -C named
PROCS OK: 1 process with command name 'named'
# /usr/local/nagios/libexec/check_procs -c 1: -C sshd
PROCS OK: 3 processes with command name 'sshd

(2)nrpe.cfg の設定

nrpe.cfg を以下のように編集

# vi /usr/local/nagios/etc/nrpe.cfg
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=192.168.0.110 # nagosサーバのIPアドレスを指定

dont_blame_nrpe=0
debug=0
command_timeout=60
connection_timeout=300
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_crond]=/usr/local/nagios/libexec/check_procs -c 1: -C crond
command[check_sshd]=/usr/local/nagios/libexec/check_procs -c 1: -C sshd
command[check_named]=/usr/local/nagios/libexec/check_procs -c 1: -C named

(3)nrpe の起動び自動起動の設定

# service nrpe start
# chkconfig --add nrpe
# chkconfig nrpe on

(4)tcp 5666がLISTNしているか確認

# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 25726/nrpe
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1684/portmap
tcp 0 0 192.168.0.100:53 0.0.0.0:* LISTEN 1655/named
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 1655/named
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2060/sshd
tcp 0 0 0.0.0.0:630 0.0.0.0:* LISTEN 1720/rpc.statd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2076/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2126/sendmail: acce
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 1655/named

nrpe の設定:Nagiosサーバー側

(1)5666ポートをNRPEで使用するポートに設定します

/etc/services に以下の内容を追加する。

# vi /etc/services
nrpe 5666/TCP # NRPE

(2)commands.cfg に以下の内容を追加する。

# vi /usr/local/nagios/etc/objects/commands.cfg
# check nrpe
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

(3)check_nrpeのテスト

設定したコマンドが正しく動作しているか確認します

# /usr/local/nagios/libexec/check_nrpe -H 192.168.0.100 -c check_crond
PROCS OK: 1 process with command name 'crond'

# /usr/local/nagios/libexec/check_nrpe -H 192.168.0.100 -c check_named
PROCS OK: 1 process with command name 'named'

(4)監視用テンプレート の追加

実際に監視する内容(プロセス監視とか)を設定します

# vi /usr/local/nagios/etc/servers/ex-ns1.cfg
define host{
use linux-server
host_name ex-ns1
alias ex-ns1
address 192.168.0.100
}

# crond
define service{
use generic-service
host_name ex-ns1
service_description CRON
check_command check_nrpe!check_crond
}

# sshd
define service{
use generic-service
host_name ex-ns1
service_description SSH
check_command check_nrpe!check_sshd
}

# named
define service{
use generic-service
host_name ex-ns1
service_description DNS
check_command check_nrpe!check_named
}

define service{
use generic-service
host_name ex-ns1
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}

(5)nagios を再起動します

すべての設定が終わると、Nagiosを再起動します

# /etc/rc.d/init.d/nagios restart

スポンサーリンク

0
0

LinuxCentOS 6,Linux,nagios

Posted by admin