How to install Nagios on CentOS 7

Share on Social Media

Want full control over your server monitoring? Learn how to install Nagios on CentOS 7 and start tracking system health like a pro—before performance issues catch you off guard. Don’t miss out on building a rock-solid monitoring setup trusted by IT experts worldwide! #centlinux #linux #nagios

What is Nagios?

Nagios Core is a free and open source software application that provides monitoring and alerting services for servers, switches, applications and services. It monitors targets (i.e. hosts and services) and alerts users when something go wrong and alerts them a second time when the problem has been resolved. Nagios Core is primary application and monitoring and alerting engine, around that hundred of Nagios Projects are built.

How to install Nagios on CentOS 7
How to install Nagios on CentOS 7

In this article, we will install Nagios on CentOS 7. But before moving forward, it is required to have basic concepts of Nagios Core 4. Therefore, it is highly recommended that you should attend:

Recommended Training: Nagios | Ultimate IT monitoring guide with EyesOfNetwork from Tech Academy

4667764 b00b 3

System Specification

We have configured a CentOS 7 virtual machine with following specifications:

  • Operating System – CentOS 7.6
  • Nagios Core – 4.4.2
  • Hostname – nagios-01.example.com
  • IP Address: – 192.168.116.130/24

Install Nagios on CentOS 7

Connect to nagios-01.example.com using ssh.

Install prerequisite packages using yum command.

yum install -y gcc glibc glibc-common wget unzip httpd php gd gd-devel perl postfix

Currently, Nagios Core does not compliance with SELinux, therefore we have to disable SELinux.

sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
setenforce 0

Create a directory for downloading Nagios Core source.

mkdir setup

Download Nagios Core from https://www.nagios.org/downloads/nagios-core/.

cd ~/setup
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.2.tar.gz

Extract downloaded source of Nagios Core.

tar xf nagios-4.4.2.tar.gz

Compile and install Nagios Core from extracted source.

cd ~/setup/nagios-4.4.2
./configure

Output:

config.status: creating t/Makefile
config.status: creating t-tap/Makefile
config.status: creating include/config.h
config.status: creating lib/snprintf.h
config.status: creating lib/iobroker.h

Creating sample config files in sample-config/ ...


*** Configuration summary for nagios 4.4.2 2018-08-16 ***:

General Options:
-------------------------
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagios
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Install ${includedir}: /usr/local/nagios/include/nagios
Lock file: /run/nagios.lock
Check result directory: /usr/local/nagios/var/spool/checkresults
Init directory: /lib/systemd/system
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /usr/sbin/sendmail
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):


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

Execute following command to compile Nagios Source.

make all

Output:

...
make[1]: Entering directory `/root/setup/nagios-4.4.2/worker'
cd ./ping && make all
make[2]: Entering directory `/root/setup/nagios-4.4.2/worker/ping'
gcc -I.. -I ../../include -I ../.. -g -O2 -DHAVE_CONFIG_H -o worker-ping worker-ping.c -L ../../lib -l nagios
make[2]: Leaving directory `/root/setup/nagios-4.4.2/worker/ping'
make[1]: Leaving directory `/root/setup/nagios-4.4.2/worker'

*** Compile finished ***

If the main program and CGIs compiled without any errors, you
can continue with testing or installing Nagios as follows (type
'make' without any arguments for a list of all possible options):

make test
- This runs the test suite

make install
- This installs the main program, CGIs, and HTML files

make install-init
- This installs the init script in /lib/systemd/system

make install-daemoninit
- This will initialize the init script
in /lib/systemd/system

make install-groups-users
- This adds the users and groups if they do not exist

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
You'll have to modify these sample files before you can
use Nagios. Read the HTML documentation for more info
on doing this. Pay particular attention to the docs on
object configuration files, as they determine what/how
things get monitored!

make install-webconf
- This installs the Apache config file for the Nagios
web interface

make install-exfoliation
- This installs the Exfoliation theme for the Nagios
web interface

make install-classicui
- This installs the classic theme for the Nagios
web interface


*** Support Notes *******************************************

If you have questions about configuring or running Nagios,
please make sure that you:

- Look at the sample config files
- Read the documentation on the Nagios Library at:
https://library.nagios.com

before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you. This might include:

- What version of Nagios you are using
- What version of the plugins you are using
- Relevant snippets from your config files
- Relevant error messages from the Nagios log file

For more information on obtaining support for Nagios, visit:

https://support.nagios.com

*************************************************************

Enjoy.

Create OS user and groups for Nagios Core.

make install-groups-users

Output:

groupadd -r nagios
useradd -g nagios nagios

Add nagios user to apache group.

usermod -a -G nagios apache

Install Nagios on CentOS 7 now.

make install

Output:

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/archives
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/spool/checkresults
chmod g+s /usr/local/nagios/var/spool/checkresults

*** Main program, CGIs and HTML files installed ***

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 /lib/systemd/system

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/setup/nagios-4.4.2'

Install Nagios Core service.

make install-daemoninit

Output:

/usr/bin/install -c -m 755 -d -o root -g root /lib/systemd/system
/usr/bin/install -c -m 755 -o root -g root startup/default-service /lib/systemd/system/nagios.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nagios.service to /usr/lib/systemd/system/nagios.service.

*** Init script installed ***

Enable httpd service.

systemctl enable httpd.service

Install and configure external command file.

make install-commandmode

Output:

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

*** External command directory configured ***

Install Sample configuration files for Nagios Core.

# make install-config
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/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.

Add Nagios Core configurations to Apache Web Server.

make install-webconf

Output:

/usr/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;
fi

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

Configure Linux Firewall

Configure Linux Firewall to allow http service.

firewall-cmd --permanent --add-service=http
firewall-cmd --reload

Setup Basic HTTP Authentication

Nagios does not have integrated user authentication, therefore, we have to use Basic HTTP authentication for this purpose.

Create an admin user for Nagios Core Web UI.

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

Start httpd & nagios services.

systemctl daemon-reload
systemctl start httpd.service
systemctl start nagios.service

Access Nagios Web Interface

Browse URL http://192.168.116.130/nagios to connect with Nagios Core Web UI.

Nagios Core Login
Nagios Core Login

Login using nagiosadmin user.

Nagios Core Dashboard
Nagios Core Dashboard

Go to services page.

Nagios Core Services Page 1
Nagios Core Services Page 1

You can see that all the services are unavailable. It is because we don’t have installed Nagios Plugins on our CentOS 7 server.

Install Nagios Plugins on CentOS 7

Install prerequisite packages for Nagios Plugins using yum command.

yum install -y perl-Net-SNMP gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils epel-release

Download Nagios Plugins from https://www.nagios.org/downloads/nagios-plugins/.

cd ~/setup
wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz

Extract downloaded source of Nagios Plugins.

cd ~/setup
tar xf nagios-plugins-2.2.1.tar.gz

Compile Nagios Plugins source.

cd ~/setup/nagios-plugins-2.2.1
./configure

Output:

...
config.status: executing libtool commands
config.status: executing po-directories commands
config.status: creating po/POTFILES
config.status: creating po/Makefile

Install Nagios Plugins by executing following command.

make
make install

Go to Nagios Web UI and open services page.

Nagios Core Services Page 2
Nagios Core Services Page 2

You can see that, now all the services are in OK state now. (Note: Keep patience, Nagios Core takes a while to collect data for each service)

Final Thoughts

By installing Nagios on CentOS 7, you’ve taken the first crucial step toward proactive server monitoring and issue detection. With its powerful alerting and visualization capabilities, Nagios helps you stay in control of your infrastructure—before problems impact your users.

Don’t fall behind relying on guesswork or outdated tools; now’s the time to automate your monitoring and gain real-time visibility. Thousands of sysadmins trust Nagios—make sure you’re not the one left troubleshooting in the dark.

Need a dependable Linux system administrator? I specialize in managing, optimizing, and securing Linux servers to keep your operations running flawlessly. Check out my services on Fiverr!

Looking for something?

28 responses to “How to install Nagios on CentOS 7”

  1. Unknown Avatar

    I Like your work highly appreciate
    Thanks

  2. Prasad Avatar

    Hi Ahmer,

    Thank you for the configuration. I wanted to monitor backup job status from veritas backup exec but I am getting unknown error which is "unknown command check_backupexec".

    Details of Nagios: Nagios 4.4.2 in CentOS 7. Veritas backup verion 20, 2018.

  3. Ahmer M Avatar

    Hi,
    Thanks for liking this article.

    Make sure you have defined the command check_backupexec in command.cfg file.
    It looks like you are using BackupExec plugin. Please refer to BackupExec – Nagios Exchange for complete configuration.

  4. Amir Avatar
    Amir

    Hi Ahmer,
    I am faceing the following issue while following your blog:
    systemctl start nagios.service
    Failed to start nagios.service: Unit not found.

    Can you please guide. How to start nagios service.

  5. Ahmer M Avatar

    It looks like nagios service is not correctly installed.
    Please ensure that you have installed nagios daemon using (as mentioned in above article).
    # make install-daemoninit

  6. Unknown Avatar

    how to configure snmp for nagios to monitor hard disk, cpu and etc.

  7. Ahmer M Avatar

    There are some templates available in Nagios default configurations for capturing SNMP traps from network devices. Just configure SNMP traps on that device and configure a service on you Nagios Core server to capture that SNMP trap.

  8. Anonymous Avatar
    Anonymous

    Hi Ahmer,

    Brilliant peace thank you for that!

    Somehow follwing your instructions i must have missed a step, because i am able to start en reload the nagios service and i am also able te see the test appache webpage, but
    When i put in the ipaddress/nagios into the url of my webbrowser it can't find anything 🙁
    The webpage cannot be found

    Could you please guide my into the right direction of the step i might have missed?

    thanks you!

  9. Ahmer M Avatar

    Hi, Thanks for appreciating my work.

    – For Nagios Service, use following command to verify and troubleshoot errors in Nagios configurations.

    – For Apache Service, refer to /var/log/messages for any possible errors.

  10. Unknown Avatar

    how to install ndoutil on nagios ?

  11. Ahmer M Avatar

    Hi, I will add an article on this topic very soon.

  12. Unknown Avatar

    Can I add China skyline gateway for monitoring in nagios ???
    If yes how can I add ?

  13. Ahmer M Avatar

    Yes, you can.
    You have to enable SNMP Traps, and allow Nagios Server to access the router SNMP traps.

  14. Unknown Avatar

    Thanks or the reply.
    Can you guide me through ???

  15. abdeladim Avatar

    thanks you ,
    i have a question please , i wan't to add supervisor can you show me what i should i do ?

  16. Ahmer M Avatar

    Nagios Core uses HTTP basic authentication and Nagios Core's default password file is /usr/local/nagios/etc/htpasswd.users.

    You can use htpasswd command to add a supervisor user therein.

  17. abdeladim Avatar

    Thanks you MR Ahmed,
    What about NRPE,apache, postgress ?
    I want to connect Nagios with server in my vmwork .

  18. Ahmer M Avatar

    Hi, NRPE installation is already mentioned here.

    You need to create services in Nagios to monitor services like Apache, Postgres, etc.

    If you are working on a DIY strategy than, I suggest you to please read Learning Nagios – Third Edition.

  19. Unknown Avatar

    pls provide the proper steps to install NSclient in windows

  20. Unknown Avatar

    Hi Ahmer,

    can u help me to configure the SMTP for email notifications

  21. Ahmer M Avatar

    Sure. Please discuss it on our Facebook Page.

  22. Ahmer M Avatar

    You can find the required information here.

  23. Unknown Avatar

    Hi Ahmer,
    Can you share the post for Naemon thruk installation and configurationd

  24. Ahmer M Avatar

    Hi, I didn't work on it. But consider your request and will write on it soon.

Leave a Reply