Linux Pathfinder: Linux Howtos and Tutorials

How to Install Nagios Core on Centos 7

How to Install Nagios Core on Centos 7
How to Install Nagios Core on Centos 7

Nagios is a free and open-source computer software application that monitors systems networks and infrastructure. Nagios offers monitoring and alerting services for servers switches applications and services. It alerts users when things go wrong and alerts them a second time when the problem has been resolved. In this tutorial, I am going to demonstrate about How to Install Nagios Core on Centos 7 server.

Nagios Official Website

Official Website:

How to Install Nagios Core on Centos 7

Installing and Configuring Nagios on Centos 7 steps are as follows:

Installing Dependencies

# yum install -y httpd php

  httpd.x86_64 0:2.4.6-67.el7.centos.2   php.x86_64 0:5.4.16-42.el7

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7              apr-util.x86_64 0:1.5.2-6.el7          httpd-tools.x86_64 0:2.4.6-67.el7.centos.2         libzip.x86_64 0:0.10.1-8.el7
  mailcap.noarch 0:2.1.41-2.el7         php-cli.x86_64 0:5.4.16-42.el7         php-common.x86_64 0:5.4.16-42.el7


Adding Libraries

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

Adding Nagios User/Group

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

# useradd nagios
# id nagios
uid=1001(nagios) gid=1001(nagios) groups=1001(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

Download Nagios Core

Next step is to download the latest installation packages from above mentioned Nagios official site. Create a new directory to store the downloaded content:

# mkdir ~/nagios
# cd ~/nagios

You can use wget to download the files:

# wget

2017-09-23 05:07:55--
Resolving (, 2600:3c00::f03c:91ff:fedf:b821
Connecting to (||:443... connect ed.
HTTP request sent, awaiting response... 200 OK
Length: 11101966 (11M) [application/x-gzip]
Saving to: ‘nagios-4.3.4.tar.gz’

100%[======================================>] 11,101,966   166KB/s   in 63s

2017-09-23 05:09:00 (173 KB/s) - ‘nagios-4.3.4.tar.gz’ saved [11101966/11101966]

Download Nagios Plugins

# wget

2017-09-23 05:12:20--
Resolving (
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2728818 (2.6M) [application/x-gzip]
Saving to: ‘nagios-plugins-2.2.1.tar.gz’

100%[======================================>] 2,728,818   81.8KB/s   in 25s    =

2017-09-23 05:12:47 (106 KB/s) - ‘nagios-plugins-2.2.1.tar.gz’ saved [2728818/2728818]

Extract the Downloaded Files

# tar zxvf nagios-4.3.4.tar.gz
# tar zxvf nagios-plugins-2.2.1.tar.gz

Install Nagios Core

Now we need to compile and install the files so we go to the Nagios directory and run the configuration script. After running configure script, output in the last lines would be look like as shown below.

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

Creating sample config files in sample-config/ ...
*** Configuration summary for nagios 4.3.4 2017-08-24 ***:
 General Options:
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagcmd
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
    Install ${includedir}:  /usr/local/nagios/include/nagios
                Lock file:  /run/nagios.lock
   Check result directory:  ${prefix}/var/spool/checkresults
           Init directory:  /etc/rc.d/init.d
  Apache conf.d directory:  /etc/httpd/conf.d
             Mail program:  /bin/mail
                  Host OS:  linux-gnu
          IOBroker Method:  epoll

 Web Interface Options:
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  /bin/traceroute

Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

Next we need to compile and install the Nagios files:

# make
Please supply a command line argument (i.e. 'make all').  Other targets are:
   nagios cgis contrib modules workers
   install install-base install-cgis install-html install-exfoliation install-config install-init install-commandmode fullinstall

# make all
# make install
You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

  make install-init
     - This installs the init script in /etc/rc.d/init.d

  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file

  make install-config
     - This installs sample config files in /usr/local/nagios/etc

make[1]: Leaving directory `/root/nagios/nagios-4.3.4'

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
/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios

*** Init script installed ***

# make install-commandmode

/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw

*** External command directory configured ***

# make install-config
/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg

*** Config files installed ***

Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.

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
/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
if [ 0 -eq 1 ]; then \
        ln -s /etc/httpd/conf.d/nagios.conf /etc/apache2/sites-enabled/nagios.conf; \

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

Setup Web User Password

Now we need to setup the password for the user nagiosadmin with below command.

# 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:

# /bin/systemctl restart httpd.service

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

# /bin/systemctl enable httpd.service 
Created symlink from /etc/systemd/system/ to /usr/lib/systemd/system/httpd.service. 

# /bin/systemctl status httpd.service
 ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: active (running) since Sat 2017-09-23 05:30:36 EDT; 5s ago 

Install Nagios Plugins

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

Nagios Pre-flight Check

Before starting and using the Nagios service, we will have to make sure all steps of installation and configuration. If everything is safe to go then we will go ahead with next step.

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


Nagios Core 4.3.4
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2017-08-24
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

Adding Nagios at Startup

Next we have to make Nagios start at boot time, if everything is fine add the service to run on boot with this commands:

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

And start the service with the following command:

# /bin/systemctl start nagios.service

Verify Nagios Server

Open Web Browser: http://Ip-Adddress/nagios

Username: nagiosadmin
password: As Set above

Nagios Home Page

Nagios Services Page

Share this article:

Asif Khan's picture
I am an experienced Linux System and Network Administrator with having more than 10 years of experience. My primary responsibilities are to keep up and running Linux system environment, backups important data with scripting and configuration management on AWS Linux server environments. My aim is to help people, in finding their path towards a solution to their problems. Well, I believe helping others can good for both parties, to them and to you as well. That day and today is the day that thousands of people seek help from my website to help people find answers to their questions. I am sure that everyone will get all the answers to their questions related to software and operating system, and this website will help you keep your system updated.

Add new comment


Enter the characters shown in the image.