In this guide we shall discuss on how to setup Nagios on Rocky Linux 8. Nagios is an open source host, process, service and network monitoring tool for various operating systems such as Windows, Linux, BSD e.t.c.

Nagios provides a web interface for administration and monitoring. This application can send email, SMS and Phone call alerts in case of an outage on the devices you are monitoring.

The steps below will guide us on how to setup Nagios on Rocky Linux 8 system. But before you begin installation of packages, set SELinux to permissive mode:

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

Step 1 – Update system

Update your system packages:

sudo dnf update

Step 2 – Install Dependencies for Nagios on Rocky Linux 8

Install package dependencies required for installation of Nagios

sudo dnf install -y php 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

Install Development tools:

sudo dnf -y groupinstall "Development Tools"

After installation, start and enable httpd and php-fpm services:

sudo systemctl enable --now httpd php-fpm

You can check the status of the service as shown below:

$ 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 Sat 2021-07-10 17:57:29 EAT; 13s ago
     Docs: man:httpd.service(8)
 Main PID: 20826 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 11259)
   Memory: 16.3M
   CGroup: /system.slice/httpd.service
           ├─20826 /usr/sbin/httpd -DFOREGROUND
           ├─20827 /usr/sbin/httpd -DFOREGROUND
           ├─20828 /usr/sbin/httpd -DFOREGROUND
           ├─20829 /usr/sbin/httpd -DFOREGROUND
           └─20830 /usr/sbin/httpd -DFOREGROUND

Jul 10 17:57:29 rocky8 systemd[1]: Starting The Apache HTTP Server...
Jul 10 17:57:29 rocky8 httpd[20826]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::9a7a:c5e0:70de:4954. Set the 'Server>
Jul 10 17:57:29 rocky8 systemd[1]: Started The Apache HTTP Server.
Jul 10 17:57:29 rocky8 httpd[20826]: Server configured, listening on: port 80

● 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 Sat 2021-07-10 16:36:29 EAT; 1h 21min ago
 Main PID: 1071 (php-fpm)
   Status: "Processes active: 0, idle: 10, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 11 (limit: 11259)
   Memory: 42.9M
   CGroup: /system.slice/php-fpm.service
           ├─1071 php-fpm: master process (/etc/php-fpm.conf)
           ├─1181 php-fpm: pool librenms
           ├─1182 php-fpm: pool librenms
           ├─1183 php-fpm: pool librenms
           ├─1184 php-fpm: pool librenms
           ├─1185 php-fpm: pool librenms
           ├─1186 php-fpm: pool www
           ├─1187 php-fpm: pool www
           ├─1188 php-fpm: pool www
           ├─1189 php-fpm: pool www
           └─1190 php-fpm: pool www

Jul 10 16:36:28 rocky8 systemd[1]: Starting The PHP FastCGI Process Manager..

Step 3 – Download and Configure Nagios on Rocky Linux 8

Download the latest version of Nagios Core and extract Nagios tarball.

cd ~
rm -rf nagios*
curl -s  https://api.github.com/repos/NagiosEnterprises/nagioscore/releases/latest |grep browser_download_url  |  cut -d '"' -f 4  | wget -i -
tar -xvf nagios-*.tar.gz

After a successful download, navigate to the extracted folder to proceed with the installation:

cd nagios-*/

Run the configure script:

./configure

Sample output:

Run the make command to compile the main program:

sudo make all

Create a nagios user and add apache user to the nagios group

sudo make install-groups-users
sudo usermod -a -G nagios apache

Install Nagios on Rocky Linux 8.

sudo make install

Install the init script in /lib/systemd/system.

sudo make install-daemoninit

Sample output:

[[email protected]rocky8 nagios-4.4.6]# 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 ***

Install and configure permissions on the directory for holding the external command line

sudo make install-commandmode

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.

Install Apache config file for 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 ***

Install the classic theme for Nagios web interface

sudo make install-classicui

Install the exfoliation heme for Nagios web interface:

sudo make install-exfoliation

Step 4 – Create Nagios Web user

We need to create a user account for accessing Nagios Web interface. Create user using htpasswd command:

$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password: 
Re-type new password: 
Adding password for user nagiosadmin

In the above command, we created a user called nagiosadmin and assigned a password to the user.

After the above exercise, restart apache service for the changes to take effect.

sudo systemctl restart httpd

Step 5 – Install Nagios Plugins on Rocky Linux 8

Download and install Nagios plugins form Github releases page. Then extract the downloaded file.

cd ~
rm -rf nagios-plugins-*
curl -s  https://api.github.com/repos/nagios-plugins/nagios-plugins/releases/latest |grep browser_download_url  |  cut -d '"' -f 4 | wget -i -
tar -xvf nagios-plugins-*.tar.gz

Navigate to the plugins directory extracted and install the downloaded plugins as shown below:

cd nagios-plugins-*/
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
sudo make install

Step 6 – Verify installation and start Nagios service

Verify thet the Nagios installation has been successful.

$ sudo /usr/local/nagios/bin/nagios --verify-config /usr/local/nagios/etc/nagios.cfg

Nagios Core 4.4.6
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2020-04-28
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.

sudo systemctl restart nagios
sudo systemctl  enable --now nagios

For a service that is up and running:

$ systemctl status nagios
● nagios.service - Nagios Core 4.4.6
   Loaded: loaded (/usr/lib/systemd/system/nagios.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-07-10 18:40:08 EAT; 3min 46s ago
     Docs: https://www.nagios.org/documentation
  Process: 44343 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
  Process: 44341 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
 Main PID: 44344 (nagios)
    Tasks: 6 (limit: 11259)
   Memory: 2.4M
   CGroup: /system.slice/nagios.service
           ├─44344 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
           ├─44345 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─44346 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─44347 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─44348 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           └─44351 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

Jul 10 18:40:08 rocky8 nagios[44344]: qh: echo service query handler registered
Jul 10 18:40:08 rocky8 nagios[44344]: qh: help for the query handler registered
Jul 10 18:40:08 rocky8 nagios[44344]: wproc: Successfully registered manager as @wproc with query handler
Jul 10 18:40:08 rocky8 nagios[44344]: wproc: Registry request: name=Core Worker 44348;pid=44348
Jul 10 18:40:08 rocky8 nagios[44344]: wproc: Registry request: name=Core Worker 44347;pid=44347
Jul 10 18:40:08 rocky8 nagios[44344]: wproc: Registry request: name=Core Worker 44346;pid=44346
Jul 10 18:40:08 rocky8 nagios[44344]: wproc: Registry request: name=Core Worker 44345;pid=44345
Jul 10 18:40:09 rocky8 nagios[44344]: Successfully launched command file worker with pid 44351

Step 7 – Access Nagios Web Interface

Before we can access this web interface, we need to allow http service through the firewall as shown below:

sudo firewall-cmd --permanent  --add-service={http,https}
sudo firewall-cmd --reload

Then access the Nagios dashboard via http://[IP/hostname]/nagios/ of your rocky Linux 8 host.

You will get to the login interface where you can login with the credentials we set at step 4 for nagiosadmin user.

Viola! We now have our Nagios server installed on Rocky Linux 8:

You can now add your hosts for monitoring as discussed in the Nagios Documentation discussed in another article.

Check these other articles on our website:

Add Remote Hosts to Nagios Server for Monitoring

installing Nagios Server on Oracle Linux 8.

LEAVE A REPLY

Please enter your comment!
Please enter your name here