Nagios is an open source monitoring system, and for a long stretch it was the default answer for keeping an eye on Linux infrastructure. It runs scheduled checks against hosts, services and network devices, so servers, switches and the applications sitting on top of them all fall within its reach. The alerting is what earns its place day to day: it tells you when a check starts failing, then tells you again once that check recovers, which means you always know whether an incident is still open. This tutorial walks through installing Nagios Core on a CentOS 7 server.
Nagios Official Website
Official Website: https://www.nagios.org/
How to Install Nagios Core on Centos 7
Worth knowing what you are getting into first. Nagios Core isn’t a yum install. You compile it from source, which means dependencies, a build, a web server, and a handful of steps that have to happen in the right order. Budget half an hour rather than five minutes.
The sequence below is the one that works. Skip ahead and something later will fail in a way that doesn’t obviously point back at what you missed.
Installing Dependencies
# yum install -y httpd php Installed: 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 Complete!
Adding Libraries
# yum install -y gcc glibc glibc-common make gd gd-devel net-snmp
Adding Nagios User/Group
Nagios gets its own account. Running a monitoring daemon as root means anything that can make it execute something can do so with full privileges, and a monitoring system by design talks to a lot of machines.
# useradd nagios # id nagios uid=1001(nagios) gid=1001(nagios) groups=1001(nagios)
The nagcmd group is what lets the web interface hand commands back to Nagios. Without it you get a read-only dashboard: you can see a failing service but you can’t acknowledge it or schedule downtime from the browser.
# groupadd nagcmd # usermod -G nagcmd nagios # usermod -G nagcmd apache
Download Nagios Core
Now the source itself, from the official site linked above. Put it somewhere deliberate rather than wherever you happen to be standing, because you’ll be extracting and building in here:
# mkdir ~/nagios # cd ~/nagios
Then pull the tarball down:
# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.4.tar.gz 2017-09-23 05:07:55-- https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.4.tar.gz Resolving assets.nagios.com (assets.nagios.com)... 72.14.181.71, 2600:3c00::f03c:91ff:fedf:b821 Connecting to assets.nagios.com (assets.nagios.com)|72.14.181.71|: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 https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz 2017-09-23 05:12:20-- https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz Resolving nagios-plugins.org (nagios-plugins.org)... 72.14.186.43 Connecting to nagios-plugins.org (nagios-plugins.org)|72.14.186.43|: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
Into the Nagios directory and run configure. This is the step that checks your system has everything the build needs, so read what it prints rather than scrolling past it. A missing dependency shows up here as a clear error, and it’s far easier to fix now than halfway through a compile.
The last few lines of a successful run look like this:
# cd nagios-4.3.4/
# ./configure --with-command-group=nagcmd
Output:
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.
That summary is worth a look. It confirms the user and group it will run as, and the web interface path, which is the address you’ll be opening at the end.
Now the actual build:
# make
Please supply a command line argument (i.e. 'make all'). Other targets are:
nagios cgis contrib modules workers
clean
install install-base install-cgis install-html install-exfoliation install-config install-init install-commandmode fullinstall
# make all
# make install
Output:
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'
Three more make targets after that: the init script so the service can start, the command mode so the web interface can act, and the sample configuration. That last one matters more than it sounds. It gives you a working localhost check to prove the install before you write any config of your own.
# make install-init Output: /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 Output: /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.
Nagios is installed at this point but you can’t see anything yet. The web interface is a separate install step:
# make install-webconf
Output:
/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 ***
Setup Web User Password
The web interface has its own login, separate from any system account. nagiosadmin is the default user and it has no password until you set one:
# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin New password: Re-type new password: Adding password for user nagiosadmin
Apache needs restarting before it picks up the new configuration:
# /bin/systemctl restart httpd.service
And Apache should come back on its own after a reboot, otherwise the dashboard disappears the first time the server restarts:
# /bin/systemctl enable httpd.service Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service 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
Nagios on its own checks nothing. It’s a scheduler and an alerting engine, and the plugins are what actually test whether a disk is full or a port is answering. Without them you have a working interface with nothing to display.
# 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 anything, get Nagios to check its own configuration. It parses every file and reports what it finds, so a typo shows up here rather than as a service that refuses to start for no visible reason.
You want zero errors. Warnings are usually fine to proceed with, but read them.
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Output:
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
Website: https://www.nagios.org
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
Same treatment for Nagios itself. A monitoring system that doesn’t survive a reboot is the definition of a false sense of security:
# /sbin/chkconfig --add nagios # /sbin/chkconfig --level 35 nagios on
Then start it:
# /bin/systemctl start nagios.service
Verify Nagios Server
That’s the install done. Open the interface in a browser and log in as nagiosadmin with the password you set earlier.
Open Web Browser: http://Ip-Adddress/nagios
Nothing loading? On CentOS 7 the firewall is nearly always the reason. Apache is running and listening, the packets are being dropped before they reach it.
Username: nagiosadmin password: As Set above

Nagios Home Page

Nagios Services Page
What you get out of the box is the localhost check from that sample configuration. Useful for proving the install works, and not much else. The real work starts when you begin adding the hosts and services you actually care about, which is a job for its own guide.
The Ubuntu equivalent is covered in installing Nagios Core on Ubuntu.


