1. Overview
Nagios performance monitoring application can be used as an network monitoring tools or server monitoring tools to monitor various network device types such as switches, routers, firewalls as well as application performance monitoring on Linux and Windows servers for host up/down status, CPU usage, memory usage, disk usage, switch or router interface up/down status , and more. It will send an alert when things go bad and when they get better.
In this instruction will show you how to monitor a remote CentOS Linux server with Nagios performance monitoring application using some Nagios plugins called NRPE.
2. Prerequisites
In this tutorial monitoring CentOS/RHEL 7 Linux Server With Nagios performance monitoring application, it is supposed that:
a. You have already done the initial server setup. Please refer to this link Minimal RHEL/CentOS 7 Initial Server Setup.
b. You have already installed Nagios performance monitoring application server. Please refer to this link. Installing Nagios Core For IT Infrastructure Monitoring on RHEL/CentOS 7
3. Configure Remote CentOS Linux Host
3.1 Install Nagios Plugin
To compile Nagios performance monitoring application plugin from source code, we have to install some prerequisite packets as the following.
# yum install -y gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel
We need to create a user for assigning privilege on Nagios performance monitoring application plugin software.
# useradd nagios
Go to /tmp directory and download the tar file of Nagios performance monitoring application plugin by using command wget as the following.
# cd /tmp # wget http://www.nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
Then, we need to extract the tar packet and then go into the extracted directory of Nagios performance monitoring application plugin.
# tar zxf nagios-plugins-2.2.1.tar.gz # cd /tmp/nagios-plugins-2.2.1
To compile Nagios performance monitoring application plugin from the source code, execute the command as shown below.
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl # make all # make install
3.2 Install NRPE Plugin
After successfully compile Nagios performance monitoring application plugin, now we need to install NRPE plugin, but first let navigate to /tmp directory and download NRPE plugin. After the download is finished, extract the NRPE plugin and go in the extracted directory.
# cd /tmp # wget https://sourceforge.net/projects/nagios/files/nrpe-3.x/nrpe-3.2.0.tar.gz # tar xvf nrpe-3.2.0.tar.gz # cd /tmp/nrpe-3.2.0
To compile NRPE plugin from the source code, we need to execute the following commands.
# ./configure --enable-command-args # make all # make install # make install-plugin # make install-daemon # make install-config # make install-inetd # make install-groups-users # make install-init
If you want to know the available option of make command, you can just type make and you will see all the available options as shown below.
# make Please enter make [option] where [option] is one of: all builds nrpe and check_nrpe nrpe builds nrpe only check_nrpe builds check_nrpe only install-groups-users add the users and groups if they do not exist install install nrpe and check_nrpe install-plugin install the check_nrpe plugin install-daemon install the nrpe daemon install-config install the nrpe configuration file install-inetd install the startup files for inetd, launchd, etc. install-init install the startup files for init, systemd, etc.
Then, let edit file “/etc/services” as the following.
# vim /etc/services nrpe 5666/tcp #NRP
Then, we need to start NRPE service and enable it to start at the boot time.
# systemctl enable nrpe # systemctl start nrpe
To check if NRPE is up and running, we use the following command.
# nmap localhost Starting Nmap 6.40 ( http://nmap.org ) at 2017-08-13 14:48 +07 Nmap scan report for localhost (127.0.0.1) Host is up (0.0000050s latency). Not shown: 994 closed ports PORT STATE SERVICE 22/tcp open ssh 25/tcp open smtp 80/tcp open http 443/tcp open https 3306/tcp open mysql 5666/tcp open nrpe Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds
To see if verify the NRPE plugin is functioning as expected, we execute the check_nrpe command as the following.
# cd /usr/local/nagios/libexec # ./check_nrpe -H localhost NRPE v3.2.0
Now we need to open NRPE port 5666 on firewall to be accessible from Nagios performance monitoring application server.
# vim /etc/sysconfig/iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 5666 -j ACCEPT # systemctl restart iptables # iptables -L -v -n Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 15 2040 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:5666 6 982 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
3.3 Configure NRPE Commands
Normally, after successfully install NRPE plugin there should be some in place commands the following.
# vim /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 -r -w .15,.10,.05 -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
Since the in place command commands name “check_hda1” is not applicable on my server, will create another command to monitor /var directory on my server. First we need to check the directory path of /var partition using the following command.
# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg--systems-lv--root 4.0G 65M 4.0G 2% / devtmpfs 478M 0 478M 0% /dev tmpfs 489M 0 489M 0% /dev/shm tmpfs 489M 6.6M 482M 2% /run tmpfs 489M 0 489M 0% /sys/fs/cgroup /dev/mapper/vg--systems-lv--usr 4.0G 2.2G 1.9G 53% /usr /dev/sda1 509M 262M 247M 52% /boot /dev/mapper/vg--systems-lv--home 3.0G 33M 3.0G 2% /home /dev/mapper/vg--systems-lv--var 4.0G 574M 3.5G 15% /var /dev/mapper/vg--systems-lv--tmp 2.0G 73M 2.0G 4% /tmp tmpfs 98M 0 98M 0% /run/user/0
Then, we need to edit file “/usr/local/nagios/etc/nrpe.cfg” have and define the command to check /var directory, let name the command as “check_disk_var”. Also, we can define the command to check SSH services and allow Nagios performance monitoring application server with IP address 10.0.0.23 to access it via NRPE.
# vim /usr/local/nagios/etc/nrpe.cfg allowed_hosts=127.0.0.1, 10.0.0.23 command[check_disk_var]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/mapper/vg--systems-lv--var command[check_ssh]=/usr/local/nagios/libexec/check_ssh -p 22 localhost
Then, we need to restart NRPE service.
# systemctl restart nrpe
Let check if the in place and the new defined commands are working fine in localhost by executing “check_nrpe” plugin as the following.
# cd /usr/local/nagios/libexec # ./check_nrpe -H localhost -c check_users USERS OK - 1 users currently logged in |users=1;5;10;0 # ./check_nrpe -H localhost -c check_load OK - load average: 0.00, 0.02, 0.05|load1=0.000;0.150;0.300;0; load5=0.020;0.100;0.250;0; load15=0.050;0.050;0.200;0; # ./check_nrpe -H localhost -c check_zombie_procs PROCS OK: 0 processes with STATE = Z | procs=0;5;10;0; # ./check_nrpe -H localhost -c check_total_procs PROCS OK: 144 processes | procs=144;150;200;0; # ./check_nrpe -H localhost -c check_disk_var DISK OK - free space: /var/tmp 3512 MB (85.97% inode=100%);| /var/tmp=573MB;3268;3677;0;4086 # ./check_nrpe -H localhost -c check_ssh SSH OK - OpenSSH_6.6.1 (protocol 2.0) | time=0.009659s;;;0.000000;10.000000
4. Configure Nagios Core Host
On Nagios performance monitoring application host, go directory /tmp and download NRPE plugin, extract it, and go into the extracted directory as the following.
# cd /tmp # wget https://sourceforge.net/projects/nagios/files/nrpe-3.x/nrpe-3.2.0.tar.gz # tar xvf nrpe-3.2.0.tar.gz # cd /tmp/nrpe-3.2.0
Then, execute the following commands to install NRPE plugin on Nagios performance monitoring application server.
# ./configure # make all # make install-plugin
Now we can go and check and should be able to see a file name “check_nrpe” there. To check if the Nagios performance monitoring application can connected to the remote CentOS7 Linux host with IP address of 10.0.0.10, execute NRPE plugin file as the following.
# /usr/local/nagios/libexec # ./check_nrpe -H 192.168.171.12 NRPE v3.2.0
Let check if the in place and the new defined commands are working fine in localhost by executing “check_nrpe” plugin as the following.
# cd /usr/local/nagios/libexec # ./check_nrpe -H 10.0.0.10 -c check_users USERS OK - 1 users currently logged in |users=1;5;10;0 # ./check_nrpe -H 10.0.0.10 -c check_load OK - load average: 0.00, 0.02, 0.05|load1=0.000;0.150;0.300;0; load5=0.020;0.100;0.250;0; load15=0.050;0.050;0.200;0; # ./check_nrpe -H 10.0.0.10 -c check_zombie_procs PROCS OK: 0 processes with STATE = Z | procs=0;5;10;0; # ./check_nrpe -H 10.0.0.10 -c check_total_procs PROCS OK: 144 processes | procs=144;150;200;0; # ./check_nrpe -H 10.0.0.10 -c check_disk_var DISK OK - free space: /var/tmp 3512 MB (85.97% inode=100%);| /var/tmp=573MB;3268;3677;0;4086 # ./check_nrpe -H 10.0.0.10 -c check_ssh SSH OK - OpenSSH_6.6.1 (protocol 2.0) | time=0.009659s;;;0.000000;10.00000
Now let define a command to call NRPE plugin, so we can using in the configuration file.
# cd /usr/local/nagios/techspacekh/commands # vim check_nrpe.cfg define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }
If we want to verify if the change on Nagios configuration is working fine, we can use the following command.
# ./usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg Total Warnings: 0 Total Errors: 0
Then, we need to restart service of Nagios performance monitoring application.
# systemctl restart nagios
Right now let create a configuration to monitor a CentOS7 Linux server with 10.0.0.10 as the following.
# cd /usr/local/nagios/techspacekh/remotehosts # vim centos7-linux.cfg define host{ use linux-server host_name CentOS7-Linux alias CentOS7-Linux notes Production Server address 10.0.0.10 hostgroups linux-servers } define service{ use generic-service host_name CentOS7-Linux service_description PING check_command check_ping!200.0,20%!600.0,60% check_interval 5 retry_interval 1 } define service{ use generic-service host_name CentOS7-Linux service_description CPU Load check_command check_nrpe!check_load } define service{ use generic-service host_name CentOS7-Linux service_description Total Processes check_command check_nrpe!check_total_procs } define service{ use generic-service host_name CentOS7-Linux service_description Zombie Processes check_command check_nrpe!check_zombie_procs } define service{ use generic-service host_name CentOS7-Linux service_description Current Users check_command check_nrpe!check_users } define service{ use generic-service host_name CentOS7-Linux service_description SSH Monitoring check_command check_nrpe!check_ssh }define service{ use generic-service host_name CentOS7-Linux service_description Disk Space /var check_command check_nrpe!check_disk_var }
Then, we need to restart Nagios service.
# systemctl restart nagios
Go to the web interface of Nagios performance monitoring application and we should see one host name “CentOS7-Linux” and some services defined as the following.
6. Conclusion
That’s all about how to add or check or monitor a CentOS/RHEL7 Linux server with Nagios performance monitoring application from Tech Space KH. Nagios performance monitoring application is one of the best network monitoring tools and server monitoring tools. Hopefully, you can find this guide informative. If you have any questions or suggestions you can always leave your comments below. I will try all of my best to review and reply them.