Official Power Up Hosting Blog

Everything about Linux, Windows, and hosting ;)

I am an avid book reader, who enjoys technology as well as writing.


Our Newsletter

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.



Official Power Up Hosting Blog

The Universal Guide To Install Nagios (CentOS, Ubuntu, and Windows).

Apurva ChodnekarApurva Chodnekar

Contents Of This Guide:

  1. Introduction:
    i) What is Nagios?
    ii) Nagios core vs xi
    iii) How does Nagios work?
  2. How to install Nagios on Centos 7 (Linux)
  3. How to install Nagios client on Windows.
  4. How to install Nagios on Ubuntu
  5. How to upgrade Nagios ubuntu


This universal guide will help you to install Nagios on Ubuntu and windows.

The newbies can check out the content of this guide and find out more about it.

Rest of you can skip straight to the installation part.

i) What is Nagios?

Nagios Ain't Gonna Insist On Sainthood (Nagios)

An open source application that monitors network, infrastructure and system.

That's the definition that you will find online. Seems simple enough right? But it encompasses quite a lot of things.

So, what exactly is Nagios? And why do you need it?

As the definition says, it is an application that monitors system, infrastructure and network.

It is a very important network administration tool.

But why is there is a need to monitor all these things?
Here are few points that will answer your question.

The first and foremost here is the downtime.
Greater amount of downtime = low productivity and also, it makes you look unprofessional.
And this will make you lose clients.

Which brings us to our next point, server availability.
Your clients should always be able to access the servers. They should never doubt your services and always have a reliable server by their side.

To add more weight to this, let's consider an example.

Suppose a client calls you to rant about their website or services being down. And you have no idea what went wrong then what will you do.

You will call your support team and ask them to fix things.

But when you don't know the exact cause of a problem you have to turn off the whole system and that equals to more downtime and less server availability. Which does not help your cause.

Another thing, Nagios monitoring system covers both the virtual and physical systems.

These are some things that you personally cannot keep tabs on all the time. So, you have reached the right conclusion. And that is why we need Nagios.

It will monitor the system and send alerts to the users, in this case which happens to be you. You can fix it in the nick of time. It also sends out an alert when the issue is resolved.

Nagios core vs xi

Is nagios free?

Nagios core is the free version and Nagios XI is the paid one.

Like all other products and services Nagios also has branched out as a paid and a free version. And similar to them the paid version will give you more features.

You can check out the official Nagios xi vs Nagios Core Features Comparison.

How does Nagios work?

As we have already discussed what nagios does is sends out alerts.

It's a monitoring tool that keeps tab on your services.

Suppose you have set a maximum limit for a particular service, then Nagios will alert you when that limit has been crossed.

Nagios keeps check on your services in periodic intervals.

One of the techniques that we will implement in this guide is NRPE.

Nagios Remote Plugin Executor (NRPE).

Nagios will install this package on all hosts that are to be monitored.

It communicates via the TCP port 5666.

In NRPE there is configuration file. It consist predefined commands.

So, whenever a query is received by NRPE, it searches for the requested command in that configuration file and then executes it as need be.

How To Install Nagios on Centos 7.

In this part of the guide we will learn nagios installation and configuration on centos step by step.

Each detailed step will guide you through the entire process quickly.

Note: During this installation process your internet connection should be on.

Step 1. We are going to start by installing the epel repository with the following command.

yum install epel-release

We will need to install the httpd, php libraries, and other php libraries as well but we will get to that later.

Step 2. Some of you might get an error as follows:

Another app is currently holding the yum lock; waiting for it to exit...

To fix this error. You will have to kill the pid with the kill command.

Suppose the pid=12758 then here's how you can kill that process.

kill 12758
kill 12758

Type "clear" in the terminal and then install the epel repository again.

yum install epel-release

If the "Another app..." error persists you can keep killing the process and then run the command again.

It doesn't happen often but when it does you know what to do now.

Once that is done and you install epel-release it will inform you how much download and install space the repository is going to need.

If you meet the requirements then enter "Y" and then hit enter.

After that you will be again asked to enter Y/N for a question Is this okay [Y/N]:

Next it will ask you whether or not you want to install the key.

Enter "y" and hit enter again.

Now that you have successfully installed the repository. you can finally start with installation of nagios on centos.

Step 3. As we are going to use and install it on centos 7, we need to install the httpd and php packages.

yum install -y httpd php

Once we have installed the dependencies we can move on to the libraries.

yum install -y gcc glibc glibc-common make gd gd-devel net-snmp

It might take some time to install, update and clean.

During that time it will update numerous packages.

Step 4. Add nagios user to the system so that you don't have to run it as a root

useradd nagios

Now, add a new nagcmd group. The purpose of this group command is to allow you run external commands using the web interface.

groupadd nagcmd

Then add usermod.

usermod -G nagcmd nagios
usermod -G nagcmd apache

Step 5.

After you have set up the user. We get to the download and installation part.

Before we download the installation package we need to create a new directory to store the packages in.

mkdir ~/nagios
cd ~/nagios

Next, get the latest nagios version using the wget command as follows.


After you have downloaded nagios you can download nagios plugins.


Step 6. Now that you have downloaded the packages you need to extract the content using following commands.

tar zxvf nagios-4.3.4.tar.gz

tar zxvf nagios-plugins-2.2.1.tar.gz

Step 7. Next step involves compiling and installing the files
and for that we will have to set the current directory to nagios 4.3.4.

cd nagios-4.3.4

Now run the ./configure command. This commands usually finds out the whereabout of the compiler.

./configure --with-command-group=nagcmd

To compile and install the nagios files use the following commands. The make command builds up the software in this case it will build nagios.

make all

The make install command will copy the files to correct locations.

make install

Step 8.

In this step first, we are going to install the init script.

make install-init


*** Init script installed ****

Now, install the files that you require to run Nagios from the command line.

make install-commandmode


*** External command directory configured ***

Last we need to install the sample configuration file.

make install-config


*** Config files installed ***

To get access to the web based interface of nagios we need to install the web component of nagios.

make install-webconf


*** Nagios/Apache conf file installed ***

Step 9. Next step involves setting up a password for nagosadmin.

We are going to need the user credentials when we access the web page using it's ip address. The user will be nagiosadmin. We need to set up a password for it.

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


New password:
Re-type new password:

To see all the changes in effect you have to restart apache.

systemctl start httpd.service

Step 10.

That concludes the nagios web component part now it's time to configure the plugins.

Start by setting the plugin as the current directory.

cd ~.nagios/nagios-plugins-2.2.1

Next steps will seem familiar as we already used them once to install nagios. Now we will use them to install nagios plugins.

./configure --with-nagios-user=nagios --with-nagios-group=nagios

This will take just about a minute or two. Once it is done use the following commands.

make install

Step 11.

To ensure that nagios starts at boot time we will execute the following commands.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc.nagios.cfg

Step 12.

If everything goes well then with the following commands you can add the service to run nagios on boot.

chkconfig --add nagios
chkconfig --level 35 nagios on

Now start the service.

systemctl start nagios.service

Step 13.

You will need the ip address of your device in this final step.

Execute the following commands in the terminal.


Open the browser and enter the below link in it. Replace the "enteryouripaddress" part with the ip address and then hit enter.


After you hit enter you will be asked for credentials.

Your username is nagiosadmin and enter the password that set.

It will take you to the Nagios home screen, from where you can monitor centos.

To set up CentOS 7 you can follow CentOS 6&7 - Initial Server Setup and Security Guide (For Beginners)

Want to run windows on the same pc as linux then you can follow our Ultimate Guide To Dual Boot Windows and Ubuntu.

That will help you install the server. The next step is to add a host on windows or linux. You can skip the windows part and start with linux if you want to add a linux host.

How to install Nagios client on Windows.

What exactly is "NSClient++"?

It's a nagios windows agent. It's function is to permit nagios to collect all the performance metrics.

Open the nscplus folder and download the latest version of NSCP file compatible with your windows.

After you download the nagios agent the next obvious step is to install nsclient++ on windows.

How to install nagios client?

The answer to that is follow the steps shown:

Here are the steps that will guide you through the installation of nagios windows client.

Step 1. Get the latest nagios client download.


Step 2. Open and run the setup.


Click on "Next".

Step 3. You will be presented with two Nagios monitoring tools.

Select one.


We are going to select "Generic" for this guide and move forward by clicking on "Next".

Step 4. On the next screen you have to select "Choose Setup Type" and then click on "next."


Step 5.


Don't forget to check the "Install sample configuration" checkbox.

Then you have to configure the NSClient++.

Add the IP address of Nagios Core or Nagios XI whichever you choose to install on the "Allowed Hosts field".

Also set up a password so that you can access it.


Tick the "Enable common check plugins" option and "Enable nsclient server(check_nt)".

After that proceed by clicking on "Next".

Step 6. You will be presented with a "Ready to install NSClient++" screen as shown. Click on "Install".




Click on "finish" to complete the installation.

Step 7. Next step has to carried out on your Nagios server. So log in to it and execute a few commands.

Use the following command to open the commands.cfg file in the vi editor.

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

Change the define command syntax as shown in the following script.

define command{
command_name check_nt
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s PASSWORD -v $ARG1$ $ARG2$

After you have made the respective changes save the file and then close it.

Step 8. The final step is to restart the Nagios service.

service nagios restart

This will let you monitor the performance of the windows machine that you installed the NSClient on.

You can use the same steps to install and configure other windows machines.

How to Install Nagios on Ubuntu.

What follows next is the complete set up on nagios on Ubuntu 16.04.
It will show you how to install, configure and set up a host on Ubuntu 16.04.

The most important prerequisite of this installation guide is that you have two Ubuntu 16.04 servers (64 bit servers).

Run the following line before you begin with the installation. It will prepare your OS for the nagios install and host setup.

sudo apt-get install wget build-essential apache2 php5 php5-gd libgd-dev unzip

And we'll get one more thing out of the way.

Create a user and group.

useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagios,nagcmd www-data

This will create a new user nagios and add it to the usergroup nagcmd.

Installation and Configuration:

Step 1. Installing the Nagios package.

A] Downloading the Nagios package.

cd /tmp 


Extract the content of the zip file using the following command.

tar zxvf nagios-4.3.4.tar.gz 

Set the current directory to nagios 4.3.4.

cd nagios-4.3.4

B] Compiling Nagios.

Fist, configure Nagios using the below line:

./configure --with-nagios-group=nagios --with-command-group=nagcmd

Then execute the following commands.

make all
sudo make install
sudo make install-commandmode
sudo make install-init
sudo make install-config
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf


If you have taken a look at "How to install Nagios on CentOS 7" then you must be familiar with most of these commands.
This one particularly is for installing Nagios on Ubuntu.

C] Copying the event handlers:

cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

Step 2. Install Nagios Plugins.

A] Downloading the plugins zip.


Next we will extract the content of the nagios plugins directory.

tar -xzf nagios-plugins*.tar.gz

Set the current directory as nagios-plugin-2.2.1.

cd nagios-plugin-2.2.1

B] Use the below command once again to configure Nagios before installing nagios plugin.

/configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl

make install

Step 3. We will now configure Nagios.

Edit the nagios cfg with vim editor using the below command.

vim /usr/local/nagios/etc/nagios.cfg

Here's what you have to do once you open the file in the editor.

Find the following line.


Remove the "#" in front of it to uncomment it. Then save the file and exit it.

Create a new directory named servers.

Use the mkdir command for it as shown below.

mkdir -p /usr/local/nagios/etc/servers

Adding an Ubuntu Host for Nagios to monitor.

As we have seen already this guide doesn't just help you to install and configure nagios but to also add a host to it.

So, this is the part of the nagios install tutorial that will help you with that endeavour.

Nagios Server IP :
Ubuntu Host IP :

This is where we are going to need the Nagios server Ip and Ubuntu Host IP.

We will perform a few steps to prep for the final adding of an host.

Step 1. The steps are simple enough. First connect to the host.

ssh root@

Step 2. Next we are going to use the apt get nagios install command to install the NRPE service.

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

Step 3. Edit the NRPE configuration file.

vim /etc/nagios/nrpe.cfg

Add the below line to it. Or set server_address to Nagios Server IP as shown below.


Step 4. Now restart the NRPE server.

service nagios-nrpe-server restart

Adding the host:

Connect to the server.

ssh root@

Create a new /usr/local/nagios/etc/servers/ubuntu_host file.

Then open it with the editor.

vim /usr/local/nagios/etc/servers/ubuntu_host.cfg

Once you open the file, add the following lines to it.

# Configuration file.

define host {
    use                          linux-server
    host_name                    ubuntu_host
    alias                        Ubuntu Host
    register                     1

define service {
  host_name                       ubuntu_host
  service_description             PING
  check_command                   check_ping!100.0,20%!500.0,60%
  max_check_attempts              2
  check_interval                  2
  retry_interval                  2
  check_period                    24x7
  check_freshness                 1
  contact_groups                  admins
  notification_interval           2
  notification_period             24x7
  notifications_enabled           1
  register                        1

define service {
  host_name                       ubuntu_host
  service_description             Check Users
  check_command           check_local_users!20!50
  max_check_attempts              2
  check_interval                  2
  retry_interval                  2
  check_period                    24x7
  check_freshness                 1
  contact_groups                  admins
  notification_interval           2
  notification_period             24x7
  notifications_enabled           1
  register                        1

   define service {
  host_name                       ubuntu_host
  service_description             Local Disk
  check_command                   check_local_disk!20%!10%!/
  max_check_attempts              2
  check_interval                  2
  retry_interval                  2
  check_period                    24x7
  check_freshness                 1
  contact_groups                  admins
  notification_interval           2
  notification_period             24x7
  notifications_enabled           1
  register                        1

define service {
  host_name                       ubuntu_host
  service_description             Check SSH
  check_command                   check_ssh
  max_check_attempts              2
  check_interval                  2
  retry_interval                  2
  check_period                    24x7
  check_freshness                 1
  contact_groups                  admins
  notification_interval           2
  notification_period             24x7
  notifications_enabled           1
  register                        1

define service {
  host_name                       ubuntu_host
  service_description             Total Process
  check_command                   check_local_procs!250!400!RSZDT
  max_check_attempts              2
  check_interval                  2
  retry_interval                  2
  check_period                    24x7
  check_freshness                 1
  contact_groups                  admins
  notification_interval           2
  notification_period             24x7
  notifications_enabled           1
  register                        1

To check the configuration execute the following command.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg


Things Look okay - No serious problems were detected during the pre-flight check

In the next step you have to restart all the services.

service nagios-nrpe-server restart
service apache2 restart
service nagios restart

Last step is to check the nagios server web interface to see if the Ubuntu host has been added.

To do that open your browser and go to
You can replace with your Nagios Server IP.

Once you are at the website you will be asked for credentials.


Add your nagios server username and password to get access.

Then you can check whether your Ubuntu host has been added.

How to upgrade nagios

If you are using an older version of nagios you can learn how to update nagios core, just follow the below steps.

Step 1. You need to be nagios user to upgrade to the newer version.

sudo -s nagios

Step 2. Remove the old depreciated Html files as they have already been replaced by their newer PHP counterparts.

rm /usr/local/nagios/share/{main,side,index}.html

Step 3. Download the latest version of Nagios Core from the official website or you could use the below code.


Now extract the tar file.

tar xzf nagios-4.3.4.tar.gz

Set the current directory to nagios-4.3.4.

cd nagios-4.3.4

Step 4. Install and configure with the following commands.

./configure --with--command-group=nagcmd

make all

make install

Step 5. Checking the configuration files.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Step 6. To restart nagios core use the following command.

/etc/init.d/nagios restart


Update from version 4.2.4 or before:

If you are updating to the version 4.3.0 or any version higher than that, you have to

make following modifications to the nagios configuration file (nagios.cfg).
Run the following commands to make those changes.

cd /etc/httpd/conf.d

cp nagios.conf nagios.conf.bak

cd [the name of nagios build directory]

make install-webconf

service httpd restart

Update from version 4.3.3 or before:

Not only do you have to run the above commands to modify the configuration file but

also run the following command to update the changes made to the init script.

make install-init


You can do so much more with Nagios. After you have installed it take a thorough look at all it has to offer.

Now you don't have to be caught unawares with any issue, you will get an alert and you can fix things before they get out of hand.

Nagios core offers you comprehensive monitoring, visibility, Awareness, Problem Remediation, Proactive planning, Reporting, Multi Tenant Capabilities, and Extendable Architecture.

You can read more about the product at their official website.

I am an avid book reader, who enjoys technology as well as writing.