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:
Download & Installing NRPE along with XinetD:
# 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 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:
SET / Modify:::
only_from 127.0.0.1 192.168.1.4 // There should be space but not any comma between IPs
Modify Services for NRPE to listen on port 5666:
ADD
nrpe 5666/tcp #NPRE
Start Services:
# systemctl enable xinetd //CentOS 7
# service xinetd start
# systemctl start xinetd //CentOS 7
CHECK if xinetd has made NRPE listen…
Confirm that Plugin of NRPE is working fine…
{{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
}
– Add following command’s definition lines in “commands.cfg” file
command_name check_nrpe_Pub
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -c $ARG1$
}
– Add Host to Nagios Config file: /etc/nagios/nagios.cfg
– Restart Nagios Process.
Configuring Client Host to be Monitored:
– Add following lines to: /usr/local/nagios/etc/nrpe.cfg
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_mysql]=/usr/local/nagios/libexec/check_ps.sh -p mysqld -w 10 -c 20 -t cpu
– Restart XinetD Process.