Install Nagios on centos 7

This document describes how to install Nagios Core 4.1.1 and Nagios Plugins 2.1.1 on Centos 7 minimal. Nagios is a very popular open source monitoring system.  We will be able to monitor host resources via the Nagios  web interface. We will also utilize the Nagios Remote Plugin Executor (NRPE), that will be installed as an agent on remote hosts, to monitor their local resources.

Here we are going to Install the Nagios Core in CentOS Linux release 7.4.1708 (Core)

Disable SELinux

Prior to starting our install, we need to disable SELinux.

setenforce 0

Modify /etc/selinux/config and change enforcing to disabled.

Install Prerequisites

We now need to install the programs that Core will need in order to function / install properly.

yum install httpd php php-cli gcc glibc glibc-common gd gd-devel net-snmp openssl-devel wget unzip -y

Now, let’s create a user and group for Nagios to use.

useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache

Download and Install Nagios

This is where we will download the required .tar.gz files for Nagios and Nagios Plugins.

tar zxf nagios-4.1.1.tar.gz
tar zxf nagios-plugins-2.1.1.tar.gz
cd nagios-4.1.1

Compile and Install Nagios.

./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

Creating a password for nagiosadmin

We now need to create a password for the nagiosadmin user. This will be used to login to your core web GUI.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Install Nagios Plugins

Now that Nagios is installed, we need to install the plugins so that it can utilize them for checks.

cd nagios-plugins-2.1.1
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
make all
make install

Start Nagios

If everything worked correctly prior to this, you will be able to start your Nagios Core service.

service httpd start
service nagios start

Now we should  be able to access  Nagios  machine by navigating to http://SERVERIP/nagios/

Replace SERVERIP with our actual server IP address. A screenshot is attached for reference. Make sure port 80 is open in the server firewall.

NRPE – How To Install NRPE v3 From Source

Download the source.

cd /tmp
wget --no-check-certificate -O nrpe.tar.gz
tar xzf nrpe.tar.gz

Compile and Install

cd /tmp/nrpe-nrpe-3.2.1/
./configure --enable-command-args
make all
make install-groups-users
make install
make install-config

Update Services File

The /etc/services file is used by applications to translate human readable service names into port numbers when connecting to a machine across a network.

echo >> /etc/services
echo '# Nagios services' >> /etc/services
echo 'nrpe    5666/tcp' >> /etc/services
make install-init
systemctl enable nrpe.service

Open Port 5666 in the server firewall.

systemctl start nrpe.service

Open file /usr/local/nagios/etc/nrpe.cfg and make sure parameter “dont_blame_nrpe=1”.

Start the service using below command.

systemctl start nrpe.service


Now check that NRPE is listening and responding to requests.

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

You should see the output similar to the following:

NRPE v3.2.1

If you get the NRPE version number (as shown above), NRPE is installed and configured correctly.

Configure Nagios

Now let’s perform the initial Nagios configuration. You only need to perform this section once, on your Nagios server.

Organize Nagios Configuration

Open the main Nagios configuration file in your favorite text editor. We’ll use vi to edit the file:

vi /usr/local/nagios/etc/nagios.cfg
Now find an uncomment this line by deleting the #:
Save and exit.

Now create the directory that will store the configuration file for each server that you will monitor:

mkdir /usr/local/nagios/etc/servers

Configure check_nrpe Command

Let’s add a new command to our Nagios configuration:

vi /usr/local/nagios/etc/objects/commands.cfg

Add the following to the end of the file:

define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

Save and exit. This allows you to use the check_nrpe command in your Nagios service definitions.

systemctl restart nagios.service

Monitor a Remote CentOS 7 Host with NRPE

In this section, we'll show you how to add a new host to Nagios, so it will be monitored.

On a server that you want to monitor, install the EPEL repository:

yum install epel-release
Now install Nagios Plugins and NRPE:
yum install nrpe nagios-plugins-all

Now, let’s update the NRPE configuration file. Open it in your favorite editor (we’re using vi):

vi /etc/nagios/nrpe.cfg

Find the allowed_hosts directive, and add the public IP address of nagios server to the comma-delimited
list (substitute it in place of the highlighted example):


Save and exit. This configures NRPE to accept requests from your Nagios server, via its private IP address.

Restart NRPE to put the change into effect:

systemctl start nrpe.service
systemctl enable nrpe.service

Make sure port

5666 is open in the server firewall.

Add Host to Nagios Server Configuration

On your Nagios server, create a new configuration file for each of the remote hosts that you want to monitor in /usr/local/nagios/etc/servers/. Replace the highlighted word, “yourhost”, with the name of your host:

vi /usr/local/nagios/etc/servers/yourhost.cfg

Add in the following host definition, replacing the host_name value with your remote hostname
, the alias value with a description of the host, and the address value with the public IP address of the
remote client host.

define host {
        use                             linux-server
        host_name                       yourhost
        alias                           My first Apache server
        max_check_attempts              5
        check_period                    24x7
        notification_interval           30
        notification_period             24x7

With the configuration file above, Nagios will only monitor if the host is up or down. If this is sufficient
for you, save and exit then restart Nagios. Make sure the client server IP will accept ICMP ping requests
other wise the host will show as down.

If you want to monitor particular services, Add any of these service blocks for services you want to monitor. Note that the value of check_command determines what will be monitored, including status threshold values. Here are some examples that you can add to your host’s configuration file:


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

SSH (notifications_enabled set to 0 disables notifications for a service):

define service {
        use                             generic-service
        host_name                       yourhost
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0

use generic-service means, it is simply inheriting the values of a service template called “generic-service”
that is defined by default.

Now save and quit. Reload your Nagios configuration to put any changes into effect:

systemctl reload nagios.service

Now lets  configure the NRPE to monitor resource usage like disk usage of Nagios Client.

Open  file /etc/nagios/nrpe.cfg in Nagios client using vi editer.  By default you will see command arguments like below are allowed in the Nagios Client server.

command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib64/nagios/plugins/check_load -r -w .15,.10,.05 -c .30,.25,.20
command[check_hda1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/xvda1
command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200

Due to this the Nagios server is allowed to verify  above commands  remotely using NRPE service.

We can test this by logging in to the Nagios server and issue command like below, we will get the Nagios Client Server Status.

[[email protected]]# /usr/local/nagios/libexec/check_nrpe -H IPADDRESS -c check_total_procs
PROCS OK: 86 processes | procs=86;150;200;0;
[[email protected] ~]#
[[email protected] ~]# /usr/local/nagios/libexec/check_nrpe -H IPADDRESS -c check_hda1
DISK OK - free space: / 29685 MB (96.66% inode=100%);| /=1023MB;24566;27637;0;30708

Now in order to allow above Nagios service check, add below entries in the Nagios Server Configuration file  /usr/local/nagios/etc/servers/yourhost.cfg

define service{
 use generic-service
 host_name yourhost
 service_description CPU Load
 check_command check_nrpe!check_total_procs
define service{
 use generic-service
 host_name yourhost
 service_description Free Disk Space
 check_command check_nrpe!check_hda1

Now let’s say we need to add more resource usage check of Nagios Client in which the the corresponding commands are not defined by default on file /etc/nagios/nrpe.cfg

Add entries like below, which will add command line to monitor mailq and MySQL status in the Nagios Client.

command[check_mysql]=/usr/lib64/nagios/plugins/check_mysql -u root -p password
 command[check_mailq]=/usr/lib64/nagios/plugins/check_mailq -w 5 -c 10

Restart NRPE service using below command

systemctl restart nrpe.service

Add below entries in the Nagios Server configuration file /usr/local/nagios/etc/servers/yourhost.cfg

define service{
 use generic-service
 host_name yourhost
 service_description MySQL Status
 check_command check_nrpe!check_mysql
define service{
 use generic-service
 host_name yourhost
 service_description Mail Queue
 check_command check_nrpe!check_mailq

Restart nagios service using below command

service nagios restart

This concluded the Nagios Core install and monitor a Nagios client using NRPE service.

How to Install NRPE on Ubuntu 16.04

NRPE is available under default apt repositories of Ubuntu systems. Execute the following command to install it

sudo apt-get update
sudo apt-get install nagios-nrpe-server nagios-plugins

The rest of steps for configuring NRPC in Nagios Client is same as that we done it on Centos 7 based Nagios

Monitoring Windows host with Nagios

We will explain how to monitor remote windows machine and the various service running on the windows server using nagios monitoring server. Which means monitor Windows machines “private” services such as CPU loadDisk usageMemory usage,  etc. For this, we required to install an NSClient++ addon on the Windows machine. The addon acts a proxy between the Windows machine and Nagios and monitors actual services by communicating with the check_nt plugin. NSClient++ will also support check_nrpe plugin.

Download the latest version of NSClient++ from

Run the NSClient++ installer package to start the installation. The welcome screen will appear. Click Next to continue to the next step.

Select Generic and click Next to continue.

Click the Typical button.

Enter the IP address(s) of the Nagios Core Server in the Allowed hosts box, separated by a comma

Enter a password in the Password box that is required for communication between the Nagios server and the Windows machine (used by check_nt plugin).
Enable common check plugins = Checked
Enable nsclient server (check_nt) = Checked

Enable NRPE Server ( check_nrpe) = Checked

Click Install button and we will see the installation completes automatically.

The NSClient++ agent will now be running as a service.  Make sure port  12489 and 5666 are opened in the server firewall

Additionally open nslicent.ini file located in C:\Program Files\NSClient++\ and make sure below parameters are enabled.


Now go the Nagios server and Open file  /usr/local/nagios/etc/objects/commands.cfg and make sure below entries are there

# 'check_nt' command definition
 define command{
 command_name check_nt
 command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s password -v $ARG1$ $ARG2$

Replace -s password argument with your own check_nt password set during NsClient++ install step.

Open file /usr/local/nagios/etc/objects/templates.cfg  and make sure below entries are there

# Windows host definition template – This is NOT a real host, just a template!

define host{
       name windows-server ; The name of this host template
       use generic-host ; Inherit default values from the generic-host template
       check_period 24x7 ; By default, Windows servers are monitored round the clock
       check_interval 5 ; Actively check the server every 5 minutes
       retry_interval 1 ; Schedule host check retries at 1 minute intervals
       max_check_attempts 10 ; Check each server 10 times (max)
       check_command check-host-alive ; Default command to check if servers are "alive"
       notification_period 24x7 ; Send notification out at any time - day or night
       notification_interval 30 ; Resend notifications every 30 minutes
       notification_options d,r ; Only send notifications for specific host states
       contact_groups admins ; Notifications get sent to the admins by default
       hostgroups windows-servers ; Host groups that Windows servers should be a member of
Open File /usr/local/nagios/etc/objects/hostgroups.cfg and make sure below entries are there.
define hostgroup{
 hostgroup_name windows-servers
 alias windows-servers
 members *

Suppose if the file is not present. Create a new one and add below entry in the file /usr/local/nagios/etc/nagios.cfg

# chown nagios.nagios /usr/local/nagios/etc/objects/hostgroups.cfg
# chmod 664 /usr/local/nagios/etc/objects/hostgroups.cfg

Verify the Nagios Configuration and restart the service

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
#  service nagios restart

Now lets create windows host cfg file under the folder /usr/local/nagios/etc/servers

vi /usr/local/nagios/etc/servers/winhost.cfg

Add below entries.

define host{
use windows-server ; Inherit default values from a template
host_name winserver ; The name we're giving to this host
alias My Windows Server ; A longer name associated with the host
address ; IP address of the host
define service{
 use generic-service
 host_name winserver
 service_description NSClient++ Version
 check_command check_nt!CLIENTVERSION
 define service{
 use generic-service
 host_name winserver
 service_description Uptime
 check_command check_nt!UPTIME
 define service{
 use generic-service
 host_name winserver
 service_description CPU Load
 check_command check_nt!CPULOAD!-l 5,80,90
 define service{
 use generic-service
 host_name winserver
 service_description Memory Usage
 check_command check_nt!MEMUSE!-w 80 -c 90
 define service{
 use generic-service
 host_name winserver
 service_description C:\ Drive Space
 check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90
define service{
 use generic-service
 host_name winserver
 service_description W3SVC
 check_command check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
 define service{
 use generic-service
 host_name winserver
 service_description Explorer
 check_command check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe

Restart the Nagios service

service nagios restart

Now we will see screenshot like below in the nagios web interface.

Now let’s Enable Custom Scripts in with NSClient++ and use check_nrpe for nagios monitoring.

Ensure the “NRPE settings” are configured in the “nsclient.ini” file in the client machines

verify mode = none
insecure = true
extended response = 0
allow arguments = true
allow nasty characters = true

Ensure that arguments are allowed in “[/settings/external scripts]” in the “nsclient.ini” file in the client machines

[/settings/external scripts]
 allow arguments = true

Ensure the file “nsclient.ini” in the client machine contains the option “CheckExternalScripts=enabled” in the [/modules] section

 CheckExternalScripts = enabled
We can also achieve this by running below commands
cd "\Program Files\NSClient++\" 
nscp settings --activate-module CheckExternalScripts --add-defaults
nscp settings --path "/settings/external scripts" --key "allow arguments" --set true

Now go the folderC:\Program Files\NSClient++\scripts folder and create a file named check_dummy.bat

Add below entries and save file.

 @echo off 
if [%1] == [] echo No exit code was supplied, aborting! & exit /B 3 
if [%2] == [] echo No dummy message was supplied, aborting! & exit /B 3 
echo %~2 
exit /B %1%

Update nsclient.ini Configuration File

Open the file C:\Program Files\NSClient++\nsclient.ini in Notepad.

 Find this section in the file:
[/settings/external scripts/scripts]

If it doesn’t exist then add it to the end of the file.

Under this section add the following line:

check_dummy_bat = scripts\\check_dummy.bat $ARG1$ "$ARG2$"
Save the file and then use services.msc to restart the NSClient++ service.

Now lets Test Script From Nagios Server. SSH in to the Nagios server and issue command like below.

 # /usr/local/nagios/libexec/check_nrpe -H your_windows_server_ip_address -c check_dummy_bat -a 2 
"Something is CRITICAL"
# echo $?

The output should look like this:

/usr/local/nagios/libexec/check_nrpe -H your_windows_server_ip_address -c check_dummy_bat -a 2 
"Something is CRITICAL"
Something is CRITICAL|

echo $?

Now lets add this script in the Nagios server configuration file for monitoring.
Open file /usr/local/nagios/etc/servers/winhost.cfg and below entry.
define service{
 use generic-service
 host_name winserver
 service_description check_dummy
 check_command check_nrpe!check_dummy_bat

Reload the nagios service. The new service check will show in the nagios panel.

By | 2018-02-18T07:05:15+00:00 February 18th, 2018|Linux, Windows|