Nagios is the most popular, free, open source, powerful monitoring system. It enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes. Nagios has the capability of monitoring devices, application, services, entire IT infrastructure. It supports both Linux and Windows OS and it has an intuitive web interface. Installed properly, it can warn you if a server or a network system goes down or fails via email alerts.Nagios Core

In order to install and configure Nagios core on CentOS 8/ RHEL 8, please follow the instructions below:

– Install LAMP stack

First requirement is to install LAMP stack or any other web hosting stack. To achieve this, execute the command:

# dnf install httpd mariadb-server php-mysqlnd php-fpm

Ensure that Apache web server is up and running. Start and enable Apache server by running the following commands:

# systemctl start httpd
# systemctl enable httpd

Run this command to ckeck the status of Apache server:

# systemctl status httpd

Next, start and enable MariaDB server:

# systemctl start mariadb
# systemctl enable mariadb

Run this command to ckeck the status run of MariaDB:

# systemctl status mariadb

To secure your server, making it less susceptible to unauthorized access, run the following command:

# mysql_secure_installation

Set a strong password for your MySQL instance. For the subsequent prompts, Type Yes and hit ENTER.

 

– Install required packages

To install and configure Nagios, some additional packages are needed, which can be installed by running the following command:

# dnf install gcc glibc glibc-common wget gd gd-devel perl postfix

 

– Create a Nagios user account

Create a user account for the Nagios user running the command:

# adduser nagios
# passwd nagios

Then, create a group for Nagios and add the Nagios user to this group. Run the following command:

# groupadd nagiosxi

Add the Nagios user to the group:

# usermod -aG nagiosxi nagios

As well as this, add Apache user to the Nagios group:

# usermod -aG nagiosxi apache

 

– Download and install Nagios core

After installing the required dependencies and adding user accounts, let’s start with the Nagios core installation. The latest stable version is Nagios 4.4.5 which was released on August 19, 2019. Download first the Nagios tarball file from its official site.

To download Nagios core, first head to the tmp directory

# cd /tmp

Then, download the tarball file

# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.5.tar.gz

Extract it using the following command:

# tar -xvf nagios-4.4.5.tar.gz

Next, navigate to the uncompressed folder

# cd nagios-4.4.5

Run the following commands below in the given order:

# ./configure --with-command-group=nagcmd
# make all
# make install
# make install-init
# make install-daemoninit
# make install-config
# make install-commandmode
# make install-exfoliation

Run the following command to set up Apache configuration:

# make install-webconf

 

– Configure Apache Web Server authentication

We need to setup apache authentication for user nagiosadmin. Do not change this username. Or, you would required more changes in configuration which may be quite tedious.

Issue the following command to set up authentication:

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

Enter and confirm the password as requested.

Now restart your web server to make the new settings take effect.

 

– Download and install Nagios plugins

Download latest Nagios plugins which will extend the functionality of the Nagios Server, using the following command:

# wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz

These plugins will help you monitor various services, network devices, and applications.

Next, extract the tarball file and navigate to the uncompressed plugin folder:

# tar -xvf nagios-plugins-2.2.1.tar.gz
# cd nagios-plugins-2.2.1

 

– Verify and start Nagios

Verify the Nagios configuration file using the following command:

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

Then, start Nagios and verify its status

# systemctl start nagios
# systemctl status nagios

If Firewall is running on the machine then use the following command to allow “80”:

# firewall-cmd --permanent --add-port=80/tcp
# firewall-cmd --reload

 

– Access Nagios in the web browser

Nagios creates its own apache configuration file. Simply browse your server’s IP address as shown:

http://server-ip/nagios

You will be prompted for the username and the password of the user we created earlier. Enter the credentials and hit Sign In. This ushers you to the Nagios dashboard.

 

That’s it. You have successfully installed and configured Nagios core service on your CentOS 8 / RHEL 8 system.