Install And Configure Nagios 4 On CentOS 7

Install And Configure Nagios 4 On CentOS 7


Nagios is an open source software that can be used for network and infrastructure monitoring. Nagios will monitor servers, switches, applications and services. It alerts the System Administrator when something went wrong and also alerts back when the issues has been rectified.


  • Monitor your entire IT infrastructure;
  • Identify problems before they occur;
  • Know immediately when problems arise;
  • Share availability data with stakeholders.hypothetical question;
  • Detect security breaches;
  • Plan and budget for IT upgrades;
  • Reduce downtime and business losses.


In this tutorial i am going to use two systems as mentioned below.

Nagios server:

Operating system : CentOS 7 minimal server
IP Address       :

Nagios client:

Operating System : CentOS 7 minimal server
IP Address       :


Before installing Nagios, make sure that you’ve a properly installed and configured LAMP stack in your server. To install and configure LAMP server, refer the following link.

Also install the following prerequisites too. All commands should be run as root user.

yum install gd gd-devel gcc glibc glibc-common wget

Create Nagios User And Group

Create a new nagios user account and give it a password:

useradd -m nagios
passwd nagios

Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.

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

Download Nagios And Plugins

Go to the nagios download page, and get the latest version. As of writing this, the latest version was 4.0.8.


And, download nagios plugins too.


Install Nagios And Plugins

Install nagios:

I tested this how-to on CentOS 7 minimal server, although it should work on all RHEL 7 and its clones like Scientific Linux 7 too.

Go to the folder where you’ve downloaded nagios, and extract it using command:

tar xzf nagios-4.0.8.tar.gz

Change to the nagios directory, and run the following commands one by one from the Terminal to compile and install nagios.

cd nagios-4.0.8
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
Install Nagios Web interface:

Enter the following commands to compile and install nagios web interface.

make install-webconf

Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account. You’ll need it while logging in to nagios web interface..

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

Restart Apache to make the new settings take effect.

systemctl restart httpd
Install Nagios plugins:

Go to the directory where you downloaded the nagios plugins, and extract it.

tar xzf nagios-plugins-2.0.3.tar.gz

Change to the nagios plugins directory:

cd nagios-plugins-2.0.3

Run the following commands one by one to compile and install it.

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

We aren’t finished yet.

Configure Nagios

Nagios sample configuration files have now been installed in the /usr/local/nagios/etc directory. These sample files should work fine for getting started with Nagios. However, you’ll need to put your actual email ID to receive alerts.

To do that, Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you’d like to use for receiving alerts.

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

Find the following line and enter the email id:

define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user
        email                   ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

Save and close the file.

Then, Edit file /etc/httpd/conf.d/nagios.conf,

vi /etc/httpd/conf.d/nagios.conf

And edit the following lines if you want to access nagios administrative console from a particular IP series. Here, I want to allow nagios administrative access from series only.

## Comment the following lines ##
#   Order allow,deny
#   Allow from all
## Uncomment and Change lines as shown below ##
Order deny,allow
Deny from all
Allow from

Restart httpd service:

systemctl restart httpd

Now, check for any configuration errors using command:

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

If there are no errors, start nagios service and make it to start automatically on every boot.

systemctl start nagios
chkconfig --add nagios
chkconfig nagios on

Adjust SELinux Settings

By default, SELinux will be in enforcing mode, and it throws “Internal Server Error” messages when you attempt to access the Nagios CGIs.

To rectify this error, edit file /etc/selinux/config:

vi /etc/selinux/config

And, set SELinux to permissive mode.


Reboot your server to take effects the changes.

Access Nagios Web Interface

Open nagios administrator console with URL http://nagios-server-ip/nagios and enter the username as nagiosadmin and its password which we created in the earlier steps.

Mozilla Firefox_001

This is how Nagios administrative console looks:

Nagios Core - Mozilla Firefox_002

Click on the “Hosts” section in the left pane of the console. You will see there the no of hosts to be monitored by Nagios server. We haven’t added any hosts yet. So it simply monitors the localhost itself only.

Nagios Core - Mozilla Firefox_003

Click on the particular host to display more details:

Nagios Core - Mozilla Firefox_005

Add Monitoring targets to Nagios server

Now, let us add some clients to monitor by Nagios server. To do that we have to install nrpe and nagios-plugins in our monitoring targets.

On CentOS/RHEL/Scientifc Linux clients:

Add EPEL repository in your CentOS/RHEL/Scientific Linux 6.x or 7 clients to install nrpe package.

To install EPEL on CentOS 7, run the following command:

yum install epel-release

On CentOS 6.x systems, refer the following link.

Install “nrpe” and “nagios-plugins” packages in client systems:

yum install nrpe nagios-plugins-all openssl
On Debian/Ubuntu clients:
sudo apt-get install nagios-nrpe-server nagios-plugins

Configure Monitoring targets

Edit /etc/nagios/nrpe.cfg file,

sudo vi /etc/nagios/nrpe.cfg

Add your Nagios server ip address:

## Find the following line and add the Nagios server IP ##

Start nrpe service on CentOS clients:

CentOS 7:

systemctl start nrpe
chkconfig nrpe on

CentOS 6.x:

service nrpe start
chkconfig nrpe on

For Debian/Ubuntu Clients, start nrpe service as shown below:

sudo /etc/init.d/nagios-nrpe-server restart

Now, go back to your Nagios server, and add the clients in the configuration file.

To do that, Edit “/usr/local/nagios/etc/nagios.cfg” file,

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

and uncomment the following lines.

## Find and uncomment the following line ##

Create a directory called “servers” under “/usr/local/nagios/etc/”.

mkdir /usr/local/nagios/etc/servers

Create config file to the client to be monitored:

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

Add the following lines:

define host{
use                             linux-server
host_name                       client
alias                           client
max_check_attempts              5
check_period                    24x7
notification_interval           30
notification_period             24x7

Here, is my nagios client IP address. Finally restart nagios service.

systemctl restart nagios

Wait for few seconds, and refresh nagios admin console in the browser and navigate to “Hosts” section in the left pane. You will see the newly added client will be visible there. Click on the host to see if there is anything wrong or any alerts it has.

Nagios Core - Mozilla Firefox_006

Click on the monitoring target (client) to view the detailed output:

Nagios Core - Mozilla Firefox_007

Similarly, you can define more clients by creating a separate config files “/usr/local/nagios/etc/servers” directory for each client.

Define services

We have just defined the monitoring host. Now, let us add some services of the monitoring host. For example, to monitor the ssh service, add the following lines shown in bold in the “/usr/local/nagios/etc/servers/clients.cfg” file.

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

Add the following lines shown in bold:

define host{
use                             linux-server
host_name                       client
alias                           client
max_check_attempts              5
check_period                    24x7
notification_interval           30
notification_period             24x7
define service {
        use                             generic-service
        host_name                       client
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0

Save and close the file. Restart Nagios.

systemctl restart nagios

Wait for few seconds, and check for the added services (i.e ssh) in the nagios web interface. Navigate to Services section on the left side bar, you’ll see the ssh service there.

Nagios Core - Mozilla Firefox_008

To know more about object definitions such as Host definitions, service definitions, contact definitions, please do visit here. This page will explain you the description and format of all object definitions.

Thats it. Cheers!


  • raj


    Notifications are not working can you please guide

  • Jiraiya

    Wow, this was very comprehensive. Thanks for helping a newbie!

  • SK

    You’re very welcome. Stay tuned with us.

  • mbondr

    There seems to be confusion between the /usr/local/nagios/etc directory you install in and the normal /etc/nagios directory. The website scripts are completely misaligned.

  • mbondr

    Really. Everything is set up to point to the normal directories. Can I copy the directories you create to their normal locations so Nagios can find them?

  • mbondr

    [root@localhost nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

    Nagios Core 4.0.8
    Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
    Copyright (c) 1999-2009 Ethan Galstad
    Last Modified: 08-12-2014
    License: GPL

    Reading configuration data…
    Error: Cannot open resource file ‘/etc/nagios/resource.cfg’ for reading!
    Warning: external_command_buffer_slots is deprecated and will be removed. All commands are always processed upon arrival
    Warning: command_check_interval is deprecated and will be removed. Commands are always handled on arrival
    Error in configuration file ‘/usr/local/nagios/etc/nagios.cfg’ – Line 560 (Check result path ‘/var/log/nagios/spool/checkresults’ is not a valid directory)
    Error processing main config file!

    [root@localhost nagios]#

  • mbondr

    From the website:


    Error: Could not open main config file ‘/etc/nagios/nagios.cfg’ for reading!

    Here are some things you should check in order to resolve this error:

    Make sure you’ve installed a main config file in its proper
    location. See the error message about for details on where the CGI is
    expecting to find the configuration file. A sample main configuration
    file (named nagios.cfg) can be found in the sample-config/ subdirectory of the Nagios source code distribution.

    Make sure the user your web server is running as has permission to read the main config file.

    Make sure you read the documentation on installing and configuring
    Nagios thoroughly before continuing. If all else fails, try sending a
    message to one of the mailing lists. More information can be found at

  • Tony Montana

    “Create Nagios User And Group
    Create a new nagios user account and give it a password:”

    I don’t understand why we have to create a new user and group ? Could you explain me please ?

  • Igor Koenig




    Page Nagios Core: Unable to get process status

  • Niclas Horn

    The “home” page works, all other links on the Nagios page results in error msg

    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

    More information about this error may be available in the server error log.


    and i have followd nagios install documentation and so on but iam stuck now :S

    i have installed on CentOS 7, some things have been different from CentOS 6.x

  • Santosh Yadav

    Very very useful stuffs…Thanks SK and keep posting…..

  • Santosh Yadav

    Just I want to understand that how can I monitor complete LAN , I mean how can I add multiple clients/servers for monitoring along with printers and hard disks etc ?

  • Lexter Garcia

    Hi SK, thank you for the wonderful tutorials that you’ve made. However, When I try to follow all the steps, it gives me the below error when I try to run the “systemctl restart nagios” at the near end of the tutorials, and I can’t view the hosts tab on may nagios server. What will I do to make it right? thanks

    ***If you have errors in your nagios.cfg you will get this error when you restart the nagios service
    Job for nagios.service failed. See ‘systemctl status nagios.service’ and ‘journalctl -xn’ for details

  • Swapnil Rathi

    when I uncomment these line then after my nagios service will not start.. when I do comment then service start 7 restart I can’t monitor other system.. please provide me solution

  • Hatem Sabrey

    thanks for the great article, it is really supportive.
    i’ve installed the nagios on centos6.6, when comes to the verification stage, it shows an issue of [the libltdl.so3 is required] while is available in /usr/lib64/

    so can you help me to solve this issue

    i’ve checked google about it but no any steps regarding solving it mean time i’m new to linux and nagios.

  • Francesco

    Hi, I get :

    [root@localhost system]# systemctl start nagios
    Failed to start nagios.service: Unit nagios.service failed to load: No such file or directory.

    The previous steps went smoothly with no errors :

    [root@localhost system]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

    Nagios Core 4.0.8
    Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
    Copyright (c) 1999-2009 Ethan Galstad
    Last Modified: 08-12-2014
    License: GPL

    Reading configuration data…
    Read main config file okay…
    Read object config files okay…
    Running pre-flight check on configuration data…

    Checking objects…
    Checked 8 services.
    Checked 1 hosts.
    Checked 1 host groups.
    Checked 0 service groups.
    Checked 1 contacts.
    Checked 1 contact groups.
    Checked 24 commands.
    Checked 5 time periods.
    Checked 0 host escalations.
    Checked 0 service escalations.
    Checking for circular paths…
    Checked 1 hosts
    Checked 0 service dependencies
    Checked 0 host dependencies
    Checked 5 timeperiods
    Checking global event handlers…
    Checking obsessive compulsive processor commands…
    Checking misc settings…

    Total Warnings: 0
    Total Errors: 0

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

    Can you please help ?

    Thank you

  • Pingback: Install Nagios Centos 7()

  • http://pinofiliax.pico/ pinofiliax

    Muchas gracias!!

  • Pingback: Nagios 4 + Redhat 6 | daerohin()

  • Dominic Bundy

    yum -y install perl perl-devel is missing from the above