Thursday , October 18 2018
Home / General / How to monitor Linux host by Nagios Core

How to monitor Linux host by Nagios Core

In this tutorial, I will demonstrate how to monitor Linux host by Nagios Core NMS. I’ll be adding CentOS client host.

Installing NRPE (on  Client Host):

Now, we’ll install NRPE on client host to let its services be checked and monitored by NMS Server.

Installing Required Deps:

# yum install openssl-devel  xinetd -y

Download & Installing NRPE along with XinetD:

# cd /usr/local/src
# wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
# tar xzvf nrpe-2.15.tar.gz
# cd nrpe-2.15
# chown nagios:nagios /usr/local/nagios  -R
# ./configure –enable-openssl
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
# make install-xinetd
# vim /etc/xinetd.d/nrpe

Add Nagios User & Group:

# groupadd -g 9000 nagios
# groupadd -g 9001 nagcmd
# useradd -u 9000 -g nagios -G nagcmd -d /usr/local/nagios -c “Nagios Admin” nagios
# grep “^User” /etc/httpd/conf/httpd.conf
RESULT should be: CentOS>>          User Apache
# usermod -G nagcmd apache

Configure XinetD to Allow Access only from NMS Server:

# vim /etc/xinetd.d/nrpe

SET / Modify:::
only_from    127.0.0.1  192.168.1.4        // There should be space but not any comma between IPs

4- NRPE Config

Modify Services for NRPE to listen on port 5666:

 # vim /etc/services

ADD
nrpe       5666/tcp            #NPRE

5- NRPE Service

Start Services:

 # chkconfig xinetd on
# systemctl enable xinetd            //CentOS 7
# service xinetd start
# systemctl start xinetd            //CentOS 7

CHECK if xinetd has made NRPE listen…

    # netstat -at | grep nrpe

Confirm that Plugin of NRPE is working fine…

  # /usr/local/nagios/libexec/check_nrpe  -H 192.168.1.27

3- Test NRPE Plugin

{{It must tell current version of nrpe installed on the target host like:   NRPE v2.15}}

Configuring NMS Server to Monitor Client Host:

– Create Client’s configuration file on NMS Server at:   /etc/nagios/objects/linuxhost.cfg                //using linuxhost just for example.

– Add following lines into it:

##############################################################################
#
# HOST DEFINITIONS
#
###############################################################################
###############################################################################

define host{
use                     linux-server
host_name               LinuxServer_1
alias                    Linux Server
address                 192.168.1.9
statusmap_image         linux40.gd2
icon_image              linux40.png
}

###############################################################################
#
# SERVICE DEFINITIONS
#
###############################################################################

define service{
use                             local-service
host_name                       LinuxServer_1
service_description             PING
check_command                   check_ping!100.0,20%!500.0,60%
}

define service{
use                             local-service
host_name                       LinuxServer_1
service_description             Directory: /
check_command                   check_nrpe_Pub!check_Root
}

define service{
use                             local-service
host_name                      LinuxServer_1
service_description             Current Users
check_command                   check_nrpe_Pub!check_users
}

1- linuxhost1

– Add following command’s definition lines in “commands.cfg” file

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

2- linuxhost2

– Add Host to Nagios Config file:     /etc/nagios/nagios.cfg

cfg_file=/etc/nagios/objects/LinuxServer_1.cfg

– Restart Nagios Process.

Configuring Client Host to be Monitored:

– Add following lines to:     /usr/local/nagios/etc/nrpe.cfg

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_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_Root]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
command[check_Var]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /var

 

Adding more lines depend how many and which services are required to be monitored. Like I have added custom script to monitor Java and MySQL services. their lines are:

command[check_Java]=/usr/local/nagios/libexec/check_ps.sh -p java -w 10 -c 20 -t cpu
command[check_mysql]=/usr/local/nagios/libexec/check_ps.sh -p mysqld -w 10 -c 20 -t cpu

– Restart XinetD Process.

About Muhammad Attique

Leave a Reply

Your email address will not be published. Required fields are marked *