How to Install and Configure Nagios 4.0.7 on CentOS 7

Nagios is a system and network monitoring application that offers monitoring and alerting services for servers, switches, applications, and services. It alerts the users when things go wrong and alerts them a second time when the problem has been resolved.

Nagios runs periodic checks on user-specified resources and services, it can be used to monitor both the local system and remote hosts. Resources that can be monitored include CPU, memory and disk space loads, log files, temperature or hardware errors. It can monitor various parameters and problems for services like HTTP, SMTP, DNS, and with the help of plugins it can be highly extended. Nagios provides all the information v ia mail alerts and in a user-friendly interface.

This guide will help you install the latest Nagios 4.0.x from the source files on CentOS 7, although the same procedure can be used on any system based on Red Hat.

Installing Nagios

Before installing Nagios you should have a working Apache/PHP installation on your system, in case you haven’t you can use the following command to install the required packages:

# yum install -y httpd php

You will also need the following libraries to compile and run Nagios 4.0 from source:

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

Next you will have to add the nagios user to the system so you avoid running it as root:

# useradd nagios

And a new nagcmd group that will allow external commands to be run via the web interface:

# groupadd nagcmd
# usermod -G nagcmd nagios
# usermod -G nagcmd apache

Next step is to download the installation packages. Create a new directory to store the downloaded content:

# mkdir ~/nagios
# cd ~/nagios

The latest versions of the Nagios Core and Nagios Plugins packages can be found on the following websites:

You can use wget to download the files:

# wget
# wget

And then extract the files with tar:

# tar zxvf nagios-4.0.7.tar.gz
# tar zxvf nagios-plugins-2.0.3.tar.gz

Now we need to compile and install the files so we go to the Nagios directory and run the configuration script

# cd nagios-4.0.7
# ./configure --with-command-group=nagcmd

You should get the following output:

nagios configure

Next we need to compile and install the Nagios files:

# make all
# make install

And we should get this output:

nagios make install

Finally we need to install the init scripts, the required files to run Nagios from the command line and the sample configuration files with the following commands:

# make install-init
# make install-commandmode
# make install-config

With your favorite text editor you need to open /usr/local/nagios/etc/objects/contacts.cfg and modify the email field from nagios@localhost to the email address where you wish to receive notifications.

# vim /usr/local/nagios/etc/objects/contacts.cfg

And the configure file should look like this:

nagios contacts cfg

Now that we have Nagios installed and ready to run we need to install the web component by running the following command:

# make install-webconf

And we need to setup the password for the user nagiosadmin. This username will be used to access the web interface so it is important to remember the password that you will input here. Set the password running the following command and enter the password twice:

# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

Restart apache for the settings to take effect:

# systemctl start httpd.service

It’s time to install the Nagios Plugins by running the following commands:

# cd ~/nagios/nagios-plugins-2.0.3
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make install

Next we have to make Nagios start at boot time, so first verify that the configuration file has no errors running the following command:

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

And you should get the output:

nagios verify

If everything is fine add the service to run on boot with this commands:

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

And start the service with the following command:

# systemctl start nagios.service

The web interface

Now that everything is installed and running you can access the web interface with a browser either by using the address http://localhost/nagios if you are doing so from the local computer or by using the address http://SERVER-IP/nagios if you are accessing it from a remote computer.

When prompted for username and password you will introduce the username “nagiosadmin” and the password that you entered in step 6. In case you forget this password you can modify it by rerunning the htpasswd command in step 6.

The web interface when you log-in for the first time will look like this:
Nagios on CentOS 7

You can now use the left-hand side menu to access the various areas of Nagios and perform different tasks.

(Optional) Install NRPE on remote hosts

If you need to monitor remote hosts, you will also need to install NRPE on this hosts so you can run the Nagios plugins remotely on this hosts and gather information. Take note that this is necessary only for more complex functions of Nagios like resource monitoring or anything that needs a plugin to be executed on the remote host. It is not needed to check services that are already visible to server or information that can be gathered via SNMP.

First you need to go to to download the latest version of NRPE,, you can do this with wget and then extract it's content:

# wget
# tar zxvf nrpe-2.15.tar.gz
# cd nrpe-2.15

Next compile nrpe

#./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local
#make all
#sudo make install

As our user DJ Vladinator pointed out if you get an error regarding openssl you can install it using the following command:

# sudo yum install openssl-devel

This covers everything about installing Nagios / Nagios Plugins / NRPE, you can find more information about further configuration in our next article.

8 Comments... add one

  1. I followed this how-to but it seems to be missing one crucial step and that is the fact that CentOS 7 by default (fresh minimal install) blocks http traffic.
    Since CentOS 7 also moved away from iptables in favour of firewalld i used the following commands to allow access:

    firewall-cmd --zone=public --add-port=http/tcp
    firewall-cmd --zone=public --add-port=http/tcp --permanent

    Credits go to Box293 on the Nagios support forum for the above commands

  2. The last part, installing NRPE.
    Something is missing...

    Inside the sample-config folder, there is only not nrpe.cfg

    And when I try the last step, I get this:
    -bash: /usr/share/nrpe/nrpe: No such file or directory

    and inside the src directory is source files, "nrpe.c"

    Anyway, the first part got nagios up and running quickly, thank you.

    • I have the same issue. I ran the configure script in the nrpe source directory like so:
      # ./configure --with-nagios-user=nagios --with-nagios-group=nagios

      And got:
      checking for SSL headers... configure: error: Cannot find ssl headers

      • Also, I was able to get past this. I simply installed the headers it wanted via yum like so:

        sudo yum install openssl-devel

        and then reran config, make, make install like so:

        ./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local
        make all
        sudo make install

        This installs nrpe into /usr/local/bin/nrpe. So, to test, I ran:

        sudo /usr/local/bin/nrpe -c /etc/nrpe.cfg -d

        Which ran without error. If you want nrpe to land somewhere other than /usr/local/. change the prefix.

  3. I followed your instructions, I got here : /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg , I tried to run this command but I found out that under the /nagios directory the /bin does not exist! I checked everywhere and can't figure out what i did wrong, could you help please?

    • It looks like the files didn't got compiled or copied to the location.

      First, what location did you get for Index ($prefix) when you executed the ./configure --with-command-group=nagcmd command ? (the output should look like in the first screenshot)

  4. Great article! One thing to add, you will likely need to change selinux to permissive to enable Nagios commands to work from the web interface.


Leave a Comment