Install Nagios Server on CentOS 8

0
397

In this guide, you will learn how to install Nagios Server on CentOS 8. Nagios provides enterprise-class Open Source IT monitoring, network monitoring, server and applications monitoring.

Install Nagios Server on CentOS 8

To install Nagios Server on CentOS 8, follow through the steps below;

Run System Update

Resynchronize your system packages to their latest versions.

dnf update

Install Required Build Tools

In this guide, we are going to build Nagios Core from the source code. As such there are packages and build tools that you need to install. Run the command below to install them.

dnf install gcc glibc glibc-common perl httpd php php-cli wget net-snmp gd gd-devel

Download Nagios Core Source Code

Navigate to the Nagios Core downloads page and grab the latest Nagios core source code. You can simplify this step by just using wget.

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

Extract the Nagios Source Code

Once the Nagios source is downloaded, extract it by running the command;

tar xzf nagios-4.4.5.tar.gz

Installing Nagios Core

Next, navigate to the Nagios source code directory.

cd nagios-4.4.5/

Configure Nagios Core on CentOS 8

Run the configuration script to adapt Nagios to your system and check if all required dependencies and build tools are in place.

./configure

If the configuration is successful, you will be provided with the summary;

...
*** Configuration summary for nagios 4.4.5 2019-08-20 ***:

 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:  /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):  


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

Compile Nagios Core

Next, proceed to compile Nagios Main program and CGIs.

make all

If the main program and CGIs compiled without any errors, proceed to install Nagios and its configurations.

Create Nagios User and Group

Nagios runs as non-privileged nagios user. As such, you need to create a Nagios system user and group.

make install-groups-users

Add Apache user to the Nagios group.

usermod -aG nagios apache

Install Nagios Core on CentOS 8

Install Nagios main program, CGIs, and HTML files.

make install

Install Nagios Service

Install Nagios Systemd initialization scripts.

make install-daemoninit

Install Nagios Commands

Install and configure the external command file as well as the permissions on the directory holding the external commands file.

make install-commandmode

Install Nagios Configuration Files

Install Nagios Sample configuration file.

make install-config

This command installs Nagios sample configuration files in /usr/local/nagios/etc.

Install Nagios Apache Configuration files

Next, install the Apache HTTP server configuration files for Nagios.

make install-webconf

Setup Nagios Apache Authentication

To setup Nagios Web authentication, you need to create an Apache user for authentication. This can be done using the htpasswd command.

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

The user, nagiosadmin, is used by default.

If you need to use a different user, you need to replace all the occurences of nagiosadmin on the /usr/local/nagios/etc/cgi.cfg file with the user you created.

For example, if you use a user like monadmin, replace nagiosadmin as shown below.

sed -i 's/nagiosadmin/monadmin/g' /usr/local/nagios/etc/cgi.cfg

If you also want to use a different authentication user file instead of, /usr/local/nagios/etc/htpasswd.users, ensure you edit the Nagios Apache configuration file, /etc/httpd/conf.d/nagios.conf and change the value of AuthUserFile.

Set the ownership of the Nagios Apache authentication configuration file to web-server user, apache.

chown apache:apache /usr/local/nagios/etc/htpasswd.users

Adjust the file permissions appropriately such that the owner (apache) have read write access, the group has read access.

chmod 640 /usr/local/nagios/etc/htpasswd.users

Start Apache Web server

Once you are done with configuration, start and enable Apache to run on system boot.

systemctl enable httpd --now

If firewallD is running on your system, be sure to enable external access to Apache.

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

Start Nagios Core service

Start and enable Nagios service to run on system boot.

systemctl enable nagios --now

To check the status

systemctl status nagios
● nagios.service - Nagios Core 4.4.5
   Loaded: loaded (/usr/lib/systemd/system/nagios.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-10-19 01:58:43 EDT; 27s ago
     Docs: https://www.nagios.org/documentation
  Process: 31542 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
  Process: 31540 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
 Main PID: 31543 (nagios)
    Tasks: 6 (limit: 24012)
   Memory: 2.7M
   CGroup: /system.slice/nagios.service
           ├─31543 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
           ├─31544 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─31545 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─31546 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           ├─31547 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
           └─31548 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

You can check Nagios logs at /usr/local/nagios/var/nagios.log.

Accessing Nagios on CentOS 8

You can now access your Nagios server from the browser using the address http://<server-IP or HOSTNAME>/nagios.

You will be prompted to enter username and password created above to login.

Enter the authentication credentials and proceed to Nagios web interface.

Install Nagios Server on CentOS 8

Huraay!! Nagios is installed on CentOS 8. So what is next?

The next step would now be to start monitoring your end points with nagios. This involves installing Nagios plugins and the NRPE plugins.

If you can check, even the status of the localhost and services are down since no Nagios plugins are installed by default.

Nagios Server CentOS 8 host state
Nagios Server CentOS 8 services state

Next, install Nagios plugins so as to monitor state of the host and services.

Install Nagios Plugins on CentOS 8

That marks the end of our tutorial on how to install Nagios Server on CentOS 8.

You can also check other Nagios Tutorials by following the links below;

Install Nagios Core on Debian 10 Buster

Monitor Linux Hosts using Nagios check_by_ssh Plugin

How to Install and Configure Nagios Core From repo Ubuntu 18.04

How to Install and Configure Nagios Core From the Source Ubuntu 18.04

LEAVE A REPLY

Please enter your comment!
Please enter your name here