Nagios is configured using text files and provides an intuitive web interface for administration and monitoring. In case of an issue, service degradation or outage, Nagios will send alerts via Email, SMS or even a phone call if configured to do so.
Follow steps below to install and configure Nagios 4 monitoring server on RHEL / CentOS 8.
Setup Pre-requsites
Set SELinux in permissive mode:
sudo sed -i 's/SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config
sudo setenforce 0
Step 1: Install dependencies
It is recommended to work on an update system.
sudo dnf update
Install required dependencies for building and running Nagios Server on RHEL / CentOS 8.
sudo dnf install @php
sudo dnf install @perl @httpd wget unzip glibc automake glibc-common gettext autoconf php php-cli gcc gd gd-devel net-snmp openssl-devel unzip net-snmp postfix net-snmp-utils
You can also check How to Install Development Tools on RHEL / CentOS 8.
sudo dnf groupinstall "Development Tools"
After the installation, start and enable httpd and php-fpm services.
sudo systemctl enable --now httpd php-fpm
Confirm services status.
$ systemctl status httpd php-fpm ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Drop-In: /usr/lib/systemd/system/httpd.service.d └─php-fpm.conf Active: active (running) since Mon 2020-09-21 21:07:31 UTC; 17min ago Docs: man:httpd.service(8) Main PID: 794 (httpd) Status: "Running, listening on: port 443, port 80" Tasks: 213 (limit: 11510) Memory: 38.0M CGroup: /system.slice/httpd.service ├─794 /usr/sbin/httpd -DFOREGROUND ├─810 /usr/sbin/httpd -DFOREGROUND ├─811 /usr/sbin/httpd -DFOREGROUND ├─812 /usr/sbin/httpd -DFOREGROUND └─813 /usr/sbin/httpd -DFOREGROUND Mar 18 21:07:30 rhel8.local systemd[1]: Starting The Apache HTTP Server… Mar 18 21:07:31 rhel8.local httpd[794]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using rhel8.local. Set > Mar 18 21:07:31 rhel8.local httpd[794]: Server configured, listening on: port 443, port 80 Mar 18 21:07:31 rhel8.local systemd[1]: Started The Apache HTTP Server. ● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled) Active: active (running) since Mon on 2020-09-21 21:07:31 UTC; 17min ago Main PID: 795 (php-fpm) Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec" Tasks: 6 (limit: 11510) Memory: 43.2M CGroup: /system.slice/php-fpm.service ├─ 795 php-fpm: master process (/etc/php-fpm.conf) ├─1023 php-fpm: pool www ├─1030 php-fpm: pool www ├─1033 php-fpm: pool www ├─1043 php-fpm: pool www └─1087 php-fpm: pool www Mar 18 21:07:30 rhel8.local systemd[1]: Starting The PHP FastCGI Process Manager… Mar 18 21:07:31 rhel8.local systemd[1]: Started The PHP FastCGI Process Manager.
You can see detailed guides on installation of PHP and Apache httpd server.
Step 2: Download Nagios Core
Check the releases page for latest Nagios available. Then download and extract Nagios tarball.
cd ~
export VER="4.4.6"
curl -SL https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-$VER/nagios-$VER.tar.gz | tar -xzf -
Change to created Nagios folder.
cd nagios-$VER
Step 3: Compiling Nagios Core on RHEL 8 / CentOS 8
1.
After extracting the archive, run the configure script:
./configure
Sample output.
2
. Run the make command with all
option to compile the main program and CGIs.
make all
3.
Create User And Group
This creates the nagios user and group. The apache user is also added to the nagios group.
sudo make install-groups-users
sudo usermod -a -G nagios apache
4
. Install Nagios on RHEL / CentOS 8
Install Nagios base.
sudo make install
4.
Install the init script in /lib/systemd/system
.
$ sudo make install-daemoninit /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 /etc/systemd/system/multi-user.target.wants/nagios.service → /usr/lib/systemd/system/nagios.service. *** Init script installed ***
5.
Install and configures permissions on the directory for holding the external command file.
$ sudo make install-commandmode /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 ***
6.
Install sample config files in /usr/local/nagios/etc
.
$ sudo make install-config /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg /usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg /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.
7.
Install the Apache config file for the Nagios web interface.
$ sudo make install-webconf /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 ***
8.
Installs the Exfoliation theme for the Nagios web interface.
$ sudo make install-exfoliation *** Exfoliation theme installed *** NOTE: Use 'make install-classicui' to revert to classic Nagios theme
9.
Install the classic theme for the Nagios web interface.
$ sudo make install-classicui *** Classic theme installed *** NOTE: Use 'make install-exfoliation' to use new Nagios theme
Step 4: Create Nagios Web user
You need to add a user account for accessing the Nagios web interface. For this, we’ll use the htpasswd
to write to /usr/local/nagios/etc/htpasswd.users
file.
$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin New password: Re-type new password: Adding password for user nagiosadmin
Enter and confirm password for the user. You also need to restart the Apache service for changes to take effect:
sudo systemctl restart httpd
Step 5: Install Nagios Plugins
Nagios plugins are used to extend Nagios monitoring features.
cd ~
Download Nagios plugins from Github releases page.
VER="2.3.3"
curl -SL https://github.com/nagios-plugins/nagios-plugins/releases/download/release-$VER/nagios-plugins-$VER.tar.gz | tar -xzf -
Change to the plugins source directory:
cd nagios-plugins-$VER
Compile and install Nagios plugins by running commands below.
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
sudo make install
You should see below output on successful compilation.
..... configure: creating ./config.status config.status: creating gl/Makefile config.status: creating nagios-plugins.spec config.status: creating tools/build_perl_modules config.status: creating Makefile config.status: creating tap/Makefile config.status: creating lib/Makefile config.status: creating plugins/Makefile config.status: creating lib/tests/Makefile config.status: creating plugins-root/Makefile config.status: creating plugins-scripts/Makefile config.status: creating plugins-scripts/utils.pm config.status: creating plugins-scripts/utils.sh config.status: creating perlmods/Makefile config.status: creating test.pl config.status: creating pkg/solaris/pkginfo config.status: creating po/Makefile.in config.status: creating config.h config.status: config.h is unchanged config.status: executing depfiles commands config.status: executing libtool commands config.status: executing po-directories commands config.status: creating po/POTFILES config.status: creating po/Makefile ....... make[1]: Leaving directory '/usr/src/nagios-plugins-2.2.1/po' make[1]: Entering directory '/usr/src/nagios-plugins-2.2.1' make[2]: Entering directory '/usr/src/nagios-plugins-2.2.1' make[2]: Nothing to be done for 'install-exec-am'. make[2]: Nothing to be done for 'install-data-am'. make[2]: Leaving directory '/usr/src/nagios-plugins-2.2.1' make[1]: Leaving directory '/usr/src/nagios-plugins-2.2.1'
Step 6: Verify installation and Start Nagios service
Confirm that your Nagios installation was successful and working.
$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg Nagios Core 4.4.5 Copyright (c) 2009-present Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 2019-08-20 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
Start and enable nagios service to start at boot.
$ sudo systemctl enable --now nagios Created symlink /etc/systemd/system/multi-user.target.wants/nagios.service → /usr/lib/systemd/system/nagios.service.
Service status should indicate running.
$ systemctl status nagios ● nagios.service - Nagios Core 4.4.3 Loaded: loaded (/usr/lib/systemd/system/nagios.service; enabled; vendor preset: disabled) Active: active (running) since Mon on 2020-09-21 22:55:35 UTC; 18s ago Docs: https://www.nagios.org/documentation Process: 29161 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS) Process: 29159 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS) Main PID: 29162 (nagios) Tasks: 6 (limit: 11510) Memory: 2.9M CGroup: /system.slice/nagios.service ├─29162 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg ├─29163 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh ├─29164 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh ├─29165 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh ├─29166 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh └─29167 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg Mar 18 22:55:35 rhel8.local nagios[29162]: qh: Socket '/usr/local/nagios/var/rw/nagios.qh' successfully initialized Mar 18 22:55:35 rhel8.local nagios[29162]: qh: core query handler registered Mar 18 22:55:35 rhel8.local nagios[29162]: qh: echo service query handler registered Mar 18 22:55:35 rhel8.local nagios[29162]: qh: help for the query handler registered Mar 18 22:55:35 rhel8.local nagios[29162]: wproc: Successfully registered manager as @wproc with query handler Mar 18 22:55:35 rhel8.local nagios[29162]: wproc: Registry request: name=Core Worker 29165;pid=29165 Mar 18 22:55:35 rhel8.local nagios[29162]: wproc: Registry request: name=Core Worker 29163;pid=29163 Mar 18 22:55:35 rhel8.local nagios[29162]: wproc: Registry request: name=Core Worker 29164;pid=29164 Mar 18 22:55:35 rhel8.local nagios[29162]: wproc: Registry request: name=Core Worker 29166;pid=29166 Mar 18 22:55:36 rhel8.local nagios[29162]: Successfully launched command file worker with pid 29167
Step 7: Access Nagios Web Dashboard
Allow http and https protocols on the firewall.
sudo firewall-cmd --permanent --add-service={http,https} sudo firewall-cmd --reload
During installation, an Apache configuration file for Nagios was added. You can access the dashboard on http:[IP/hostname]/nagios/
Authenticate with username and password added earlier.
Username: nagiosadmin
You should see Nagios Dashboard where you can add devices to be monitored.
There you have it. The latest version of Nagios is now installed on RHEL 8 / CentOS 8.