All about unix linux freebsd and FAQ for Packetlove.com Web hosting , Mail hosting , VoIP + IP PBX server > all application on unix knowledges by golfreeze

Install nrpe and nagios-plugin in remote host and nrpe on monitoring server

(1/5) > >>

golfreeze:
ถ้าท่านใช้งาน nagios เป็นตัวเชค status service บน server อยู่
อยากแนะนำ tool ของ nagios อีกตัวคือ nrpe ครับ สามารถช่วยให้การ monitoring ละเอียดและสบายขึ้นครับ

ฝั่ง client ลงสองตัวนะครับ nrpe กับ nagios-plugin
ฝั่ง monitoring server ลง nrpe + nagios (ลงไว้อยู่แล้ว)

##download nrpe new version
https://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz

##Download nagios-plugin new version
http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz

Install nrpe and nagios-plugin in remote host and nrpe on monitoring server

I. Overview

II. 6 steps to install Nagios plugin and NRPE on remote host.

Download Nagios Plugins and NRPE Add-on
Create nagios account
Install Nagios Plugins
Install NRPE
Setup NRPE to run as daemon
Modify the /usr/local/nagios/etc/nrpe.cfg
III. 4 Configuration steps on the Nagios monitoring server to monitor remote host:

Download NRPE Add-on
Install check_nrpe
Create host and service definition for remote host
Restart the nagios service

I. Overview:

Following three steps will happen on a very high level when Nagios (installed on the nagios-servers) monitors a service (for e.g. disk space usage) on the remote Linux host.
 
Nagios will execute check_nrpe command on nagios-server and request it to monitor disk usage
on remote host using check_disk command.
The check_nrpe on the nagios-server will contact the NRPE daemon on remote host
and request it to execute the check_disk on remote host.
The results of the check_disk command will be returned back by NRPE daemon to the check_nrpe on nagios-server.

Following flow summarizes the above explanation:

Nagios Server (check_nrpe) —–> Remote host (NRPE deamon) —–> check_disk

Nagios Server (check_nrpe) <—– Remote host (NRPE deamon) <—– check_disk (returns disk space usage)

II. 7 steps to install Nagios Plugins and NRPE on the remote host

1. ทำการ Download Nagios Plugins และ NRPE Add-on มาไว้ในเครื่อง remotehost

Download following files from Nagios.org and move to /home/downloads:

 nagios-plugins-2.1.1.tar.gz
 nrpe-2.15.tar.gz

2. Create nagios account
[remotehost]# useradd nagios
[remotehost]# passwd nagios

3. Install nagios-plugin
[remotehost]# cd /home/downloads
[remotehost]# tar xvfz nagios-plugins-2.1.1.tar.gz
[remotehost]# cd nagios-plugins-2.1.1
[remotehost]# export LDFLAGS=-ldl
[remotehost]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround
[remotehost]# make
[remotehost]# make install

ทำการเปลี่ยนสิทธิ์ของ folder nagios
[remotehost]# chown nagios:nagios /usr/local/nagios
[remotehost]# chown -R nagios:nagios /usr/local/nagios/libexec/

Note: On Red Hat, For me the ./configure command was hanging with the the message: “checking for redhat spopen problem…”. Add --enable-redhat-pthread-workaround to the ./configure command as a work-around for the above problem.

4. Install NRPE

[remotehost]# cd /home/downloads
[remotehost]# tar xvfz nrpe-2.15.tar.gz
[remotehost]# cd nrpe-2.15

[remotehost]# ./configure

####ถ้าเจอ error ssl header ใน centos ตอน configure แสดงว่ายังมี package ไม่ครบให้ทำการลงตัว openssl-devel
#yum install openssl-devel

####ถ้าใน debian , ubuntu
#apt-get install libssl-dev

ถ้าใน ubuntu อาจจะลองเชคว่ามี libssl-dev ยังนะครับถ้ามีแล้วก็ทำ link module ไป
#ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/libssl.so

เพิ่มเสร็จแล้วก็ ./configure อีกรอบนะครับ
[remotehost]# ./configure

[remotehost]# make all
[remotehost]# make install-plugin
[remotehost]# make install-daemon
[remotehost]# make install-daemon-config

ในส่วนนี้ถ้าต้องการให้รัน service ผ่าน xinetd ก็เพิ่มลงไปแต่ถ้าใครจะไปรันเป็น daemon service ก็สุดแค่นี้ครับผม : )

[remotehost]# make install-xinetd
5. Setup NRPE to run as daemon (i.e as part of xinetd):

Modify the /etc/xinetd.d/nrpe to add the ip-address of the Nagios monitoring server to the only_from directive. Note that there is a space after the 127.0.0.1 and the nagios monitoring server ip-address (in this example, nagios monitoring server ip-address is: 192.168.1.2)
       only_from       = 127.0.0.1 192.168.1.2
Modify the /etc/services and add the following at the end of the file.
       nrpe 5666/tcp # NRPE
Start the service
       [remotehost]#service xinetd restart
Verify whether NRPE is listening
       [remotehost]# netstat -at | grep nrpe
       tcp 0      0 *:nrpe *:*                         LISTEN
Verify to make sure the NRPE is functioning properly
[remotehost]# /usr/local/nagios/libexec/check_nrpe -H localhost

NRPE v2.12

6. Modify the /usr/local/nagios/etc/nrpe.cfg

The nrpe.cfg file located on the remote host contains the commands that are needed to check the services on the remote host. By default the nrpe.cfg comes with few standard check commands as samples. check_users and check_load are shown below as an example.

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

In all the check commands, the “-w” stands for “Warning” and “-c” stands for “Critical”. for e.g. in the check_disk command below, if the available disk space gets to 20% of less, nagios will send warning message. If it gets to 10% or less, nagios will send critical message. Change the value of “-c” and “-w” parameter below depending on your environment.

command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1

Note: You can execute any of the commands shown in the nrpe.cfg on the command line on remote host and see the results for yourself. For e.g. When I executed the check_disk command on the command line, it displayed the following:

[remotehost]#/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
DISK CRITICAL - free space: / 6420 MB (10% inode=98%);| /=55032MB;51792;58266;0;64741

In the above example, since the free disk space on /dev/hda1 is only 10% , it is displaying the CRITICAL message, which will be returned to nagios server.

ขั้นตอนที่ ทำการติดตั้ง NRPE ในฝั่ง Server

4 Configuration steps on the Nagios monitoring server to monitor remote host:

1. Download NRPE Add-on

Download nrpe-2.12.tar.gz from Nagios.org and move to /home/downloads:

2. Install check_nrpe on the nagios monitoring server

[nagios-server]# tar xvfz nrpe-2.12.tar.gz
[nagios-server]# cd nrpe-2.1.2
[nagios-server]# ./configure
[nagios-server]# make all
[nagios-server]# make install-plugin

./configure will give a configuration summary as shown below:

*** Configuration summary for nrpe 2.12 05-31-2008 ***:

General Options:
————————-
NRPE port: 5666
NRPE user: nagios
NRPE group: nagios
Nagios user: nagios
Nagios group: nagios
 

Note: I got the “checking for SSL headers… configure: error: Cannot find ssl headers” error message while performing ./configure. Install openssl-devel as shown below and run the ./configure again to fix the problem.

[nagios-server]# rpm -ivh openssl-devel-0.9.7a-43.16.i386.rpm krb5-devel-1.3.4-47.i386.rpm zlib-devel-1.2.1.2-1.2.i386.rpm e2fsprogs-devel-1.35-12.5.
el4.i386.rpm
warning: openssl-devel-0.9.7a-43.16.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
Preparing… ########################################### [100%]
1:e2fsprogs-devel ########################################### [ 25%]
2:krb5-devel ########################################### [ 50%]
3:zlib-devel ########################################### [ 75%]
4:openssl-devel ########################################### [100%]
Verify whether nagios monitoring server can talk to the remotehost.

[nagios-server]#/usr/local/nagios/libexec/check_nrpe -H 192.168.1.3
NRPE v2.12

Note: 192.168.1.3 in the ip-address of the remotehost where the NRPE and nagios plugin was installed as explained in Section II above.

3. Create host and service definition for remotehost

Create a new configuration file /usr/local/nagios/etc/objects/remotehost.cfg to define the host and service definition for this particular remotehost. It is good to take the localhost.cfg and copy it as remotehost.cfg and start modifying it according to your needs.
 

host definition sample:

define host{
use linux-server
host_name remotehost
alias Remote Host
address 192.168.1.3
contact_groups admins
}

Service definition sample:

define service{
use generic-service
service_description Root Partition
contact_groups admins
check_command check_nrpe!check_disk
}
Note: In all the above examples, replace remotehost with the corresponding hostname of your remotehost.

4. Restart the nagios service

Restart the nagios as shown below and login to the nagios web (http://nagios-server/nagios/) to verify the status of the remotehost linux sever that was added to nagios for monitoring.

[nagios-server]# service nagios reload

golfreeze:
ถ้าใครจะใช้ตัว nrpe ผ่าน init-script แทนการใช้งานผ่าน xinetd ก็ได้นะครับผม
ก็ปรับตามนี้ครับ

#cd nrpe
#cp init-script /etc/init.d/nrpe
#chmod 755 /etc/init.d/nrpe

#/etc/init.d/nrpe restart
ก็ใช้งานได้เลยครับผม

ส่วน configure ของ nrpe จะอยู่ที่
$/usr/local/nagios/etc/nrpe.cfg

แล้วทำการตั้งค่าให้ nrpe start เองอัตโนมัติตอน reboot เครื่องครับ

###On CentOS
#chkconfig --level 235 nrpe on


###On debian and ubuntu
#update-rc.d nrpe defaults

golfreeze:
ในส่วนของไฟล์ command.cfg ในเครื่อง monitoring_server ใส่เป็นแบบนี้นะครับ

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

แล้วในส่วนของ hosts.cfg
ใส่เป็น

define service{
        use                             local-service         ; Name of service template to use
        host_name                       kingkong.packetlove.com
        service_description             Current Users
        check_command                   check_nrpe!check_users
        }

golfreeze:
#reference
http://www.thegeekstuff.com/2010/12/enable-nrpe-command-arguments/
https://sourceforge.net/p/nagios/mailman/message/17581009/
http://www.thegeekstuff.com/2008/06/how-to-monitor-remote-linux-host-using-nagios-30/

golfreeze:
[root@dev objects]# /usr/local/nagios/libexec/check_nrpe -H 103.246.22.33 -c check_home
DISK OK - free space: /home 776813 MB (92% inode=99%);| /home=62310MB;707229;795633;0;884037
[root@dev objects]# /usr/local/nagios/libexec/check_nrpe -H 103.246.22.33 -c check_total_procs
PROCS OK: 266 processes | procs=266;320;400;0;
[root@dev objects]# /usr/local/nagios/libexec/check_nrpe -H 103.246.22.33 -c check_load

นำร่อง

[0] ดัชนีข้อความ

[#] หน้าถัดไป

Go to full version