How to Install Nagios Core on CentOS

Nagios is open-source software for system and network monitoring. Nagios can monitor the activity of a host and its services and provide a warning/alert if something bad happens on the server. Nagios can run on Linux operating systems, and we will use the CentOS 8 server.

This tutorial will show you how to install the Nagios Core on a CentOS 8 system. We will install the Nagios Core 4.4.5 from the EPEL repository and then add the CentOS 8 host monitor to the Nagios Server.

Prerequisites

  • 2 CentOS 8 servers
    • Nagios server - hostname: hakase-nagios with an IP: 10.5.5.20
    • CentOS client - hostname: client01 with an IP: 10.5.5.21
  • Root privileges

What we will do:

  • Install EPEL Repository
  • Install Nagios Core 4.4.5
  • Install Nagios Plugin and NRPE Plugin
  • Add Host to Monitor to Nagios Server
  • Add Configuration for Host Monitor
  • Testing

Step 1 - Install the EPEL Repository

First, we will add repository EPEL (Extra Package for Enterprise Linux) to the CentOS 8 system. We will install Nagios packages from the EPEL repository.

Install the EPEL repository using the dnf command below.

sudo dnf install epel-release

Once the installation is complete, check all available repository on the system.

sudo dnf repolist

And you've added the EPEL repository to the CentOS 8 system.

Step 2 - Install and Configure Nagios Core

In this step, we will install and configure the latest stable version of Nagios Server 4.4.5 on the CentOS 8 system. And we will use the nagios package provided by the EPEL repository.

Check all available packages named as 'nagios'.

dnf search nagios

Then check the 'nagios' package details.

dnf info nagios

And you will get details about the nagios package as below.

- Install and Configure Nagios Core 4.4.5

Now install the 'nagios' using the dnf command below.

sudo dnf install nagios

Once the instalaltion is complete, go to the '/etc/nagios' directory and edit the configuration file 'nagios.cfg'.

cd /etc/nagios/
vim nagios.cfg

Uncomment the following line.

cfg_dir=/etc/nagios/servers

Save and close.

Now create a new directory for storing all host monitor configuration.

mkdir -p /etc/nagios/servers

Then edit the contact configuration file 'objects/contacts.cfg'.

vim objects/contacts.cfg

Change the email address with your own.

email       [email protected]

Save and close.

And you've configured the Nagios Server.

- Setup Nagios Authentication

For the authentication, Nagios is using the basic httpd authentication provided by the Apache2 web server.

Now create a new apache basic authentication for user 'nagiosadmin' using the htpasswd command below.

htpasswd  /etc/nagios/passwd nagiosadmin

Type and repeat your strong password, and the basic authentication for Nagios Server has been created.

Next, go to the '/var/www/html' directory and create the index.html file.

cd /var/www/html
echo "This is index.html for Apache" > index.html

Then start the httpd service and add it to the system boot.

systemctl enable --now httpd
systemctl status httpd

And you've created a new user 'nagiosadmin' for Nagios Server.

- Setup Firewall

Add new services http and https to the firewalld services list.

firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanent

Reload the firewalld.

firewall-cmd --reload

Now you've added the http and https services to the firewalld. As a result, the Nagios Server can be accessible from the web browser.

Step 3 - Install NRPE Plugin and Nagios Plugins

The NRPE (Nagios Remote Plugin Executor) is a Nagios agent that allows a remote system to execute 'Nagios Plugins' script on the remote monitoring system.

Install Nagios Plugins and NRPE plugins using the following command.

sudo dnf install nagios-plugins nrpe nagios-plugins-nrpe

Once all installation is complete, we will install some of Nagios plugins for basic server monitoring, including the ssh service, disk space, user login, etc.

To get completed all available Nagios Plugins, run the command below.

dnf search nagios-plugins

Now you can install Nagios Plugins using the bash loop command below.

for i in users uptime ssh ping procs load http swap disk; do dnf install nagios-plugins-$i -y; done

Once all installation is complete, go to the '/etc/nagios' directory and edit the configuration file 'objects/commands.cfg'.

cd /etc/nagios/
vim objects/commands.cfg

Paste the following configuration to the end of the line.

define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

Save and close.

Now start the Nagios service and add it to the system boot.

systemctl enable --now nagios

After that, check the status of Nagios service.

systemctl status nagios

You will get the Nagios service is up and running.

Now open your web browser and type the Nagios Server URL as below.

http://10.5.5.20/nagios/

Log in with the user 'nagiosadmin' and your password.

Once you've logged in, you will get the Nagios dashboard as below.

As a result, you've installed the Nagios Server 4.4.5 on CentOS 8 system.

Step 4 - Add Host to Monitor to Nagios Server

In this step, we will add the CentOS 8 system to the Nagios Server. We will add the CentOS 8 server 'client01' with IP address '10.5.5.21' to the Nagios Server.

To add the host to the Nagios Server, you will need to install the NRPE and Nagios Plugins to the server.

On the 'client01' system, install the NRPE server using the following command.

sudo dnf install nrpe

After that, install some of Nagios Plugins using the bash loop command below.

for i in users uptime ssh ping procs load http swap disk; do dnf install nagios-plugins-$i -y; done

Once all installation is complete, go to the '/etc/nagios' directory and edit the nrpe configuration file 'nrpe.conf'.

cd /etc/nagios/
vim nrpe.conf

Uncomment the 'server_address' line and change the value with the 'client01' IP address '10.5.5.21'.

server_address = 10.5.5.71

On the 'allowed_hosts' line, add the Nagios Server IP address '10.5.5.20'.

allowed_hosts=127.0.0.1,::1,10.5.5.70

Define some Nagios command for basic monitoring as below.

command[check_root]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /
command[check_ping]=/usr/lib64/nagios/plugins/check_ping -H 10.5.5.71 -w 100.0,20% -c 500.0,60% -p 5
command[check_ssh]=/usr/lib64/nagios/plugins/check_ssh -4 10.5.5.71
command[check_http]=/usr/lib64/nagios/plugins/check_http -I 10.5.5.71

Save and close.

Now start the NRPE service and ad it to the system boot.

systemctl enable --now nrpe

Check the status of the NRPE service.

systemctl status nrpe

And you will get the NRPE service is up and running.

Next, add the nrpe port to the firewalld and reload the firewalld configuration.

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

And you've completed the NRPE configuration on the host monitor 'client01'.

Now back to the Nagios Server terminal and check the 'client01' host using the nagios nrpe command below.

/usr/lib64/nagios/plugins/check_nrpe -H 10.5.5.21
/usr/lib64/nagios/plugins/check_nrpe -H 10.5.5.21 -c check_ping

As a result, you get the NRPE version on the 'client01' host and the ping command to the 'client01' has been successful.

Step 5 - Add Configuration for Host Monitor

Back to the Nagios Server, go to the '/etc/nagios/server' directory and create a new configuration 'client01.cfg'.

cd /etc/nagios/servers/
vim client01.cfg

Paste the following configuration into it.

define host {
        use                          linux-server
        host_name                    client01
        alias                        CentOS Host
        address                      10.5.5.12
        register                     1
}

define service {
      host_name                       client01
      service_description             PING
      check_command                   check_nrpe!check_ping
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

define service {
      host_name                       client01
      service_description             Check Users
      check_command                   check_nrpe!check_users
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

define service {
      host_name                       client01
      service_description             Check SSH
      check_command                   check_nrpe!check_ssh
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

define service {
      host_name                       client01
      service_description             Check Root / Disk
      check_command                   check_nrpe!check_root
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

define service {
      host_name                       client01
      service_description             Check HTTP
      check_command                   check_nrpe!check_http
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

Save and close.

Now restart the Nagios service.

sudo systemctl restart nagios

And you've added the configuration for 'client01' host to the Nagios Server.

Step 6 - Testing

Open your web browser and log in to the Nagios Dashboard.

http://10.5.5.20/nagios/

Click the 'Hosts' menu and you get the 'client01' on the host list.

Now click on the name of the host 'client01' and you will get details about services monitoring for the 'client01' server.

As a result, you've installed the Nagios 4.4.5 on the CentOS 8 system, and you've added the host to monitor 'client01' to the Nagios Server.

Reference

Share this page:

0 Comment(s)