Home / How To / How to install Nagios Monitoring Software on Ubuntu 20.04 LTS

How to install Nagios Monitoring Software on Ubuntu 20.04 LTS



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

In this tutorial we will show you step by step how to install Nagios 4.4.x on Ubuntu 20.04. We will install Nagios Core 4.4.x from the source, install nrpe and nagios plugins and then add host to monitor to Nagios server.

conditions

  • 2 Ubuntu 20.04 servers
    • Nagios Server ̵
      1; Hostname: nagios20 with an IP: 172.16.0.5
    • Ubuntu Client – Hostname: client01 with an IP: 172.16.0.6
  • Red privileges

What we should do:

  • Install package dependency
  • Install Nagios Core 4.4.6
  • Install Nagios Plugin and NRPE Plugin
  • Add Host to Monitor to Nagios Server
  • Testing

Step 1 – Install package dependency

First, we will update the Ubuntu repository and install some package dependencies for the Nagios installation.

Update the Ubuntu repository with the apt command below.

sudo apt update

Then install package dependencies for Nagio installation.

sudo apt install -y autoconf bc gawk dc build-essential gcc libc6 make wget unzip apache2 php libapache2-mod-php libgd-dev libmcrypt-dev make libssl-dev snmp libnet-snmp-perl gettext

And you have installed package dependency for Nagios server.

Step 2 – Install Nagios Core 4.4.6

In this step we will install the latest stable version Nagios Core 4.4.6. And we will install it manually from the source.

– Download Nagios Core 4.4.6

Go to your home directory and download the Nagios Core source code.

cd ~/
wget https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.6.tar.gz

Extract the Nagios package and go to the extracted Nagios directory.

tar -xf nagios-4.4.6.tar.gz
cd nagioscore-*/

– Compile and install Nagios

First compile Nagio’s source code and define the Apache virtual host configuration for Nagios.

sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled
sudo make all

Collect Nagios

Create Nagios users and group and add the Apache user ‘www-data’ to the ‘nagios’ group.

sudo make install-groups-users
sudo usermod -a -G nagios www-data

Nagios Add user and group

Install Nagios binaries, service demo scripts, and command mode.

sudo make install
sudo make install-daemoninit
sudo make install-commandmode

Then install the sample script configuration.

sudo make install-config

Then install the Apache configuration for Nagios and enable the mod_rewrite and mode_cgi modules.

sudo make install-webconf
sudo a2enmod rewrite cgi

Restart the Apache service now.

systemctl restart apache2

And you have installed Nagios Core 4.4.6.

Compile Nagioscore

– Create nagiosadmin users

After installing Nagios Core, we add the basic authentication for accessing the Nagios dashboard. And we’ll use the basic Apache authentication.

Create a new basic verification of apache for the “nagiosadmin” user.

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

Write your strong password.

Create Nagios Admin users

And you have created a new user ‘nagiosadmin’ for verification of Nagios dashboard.

– Install the UFW firewall

For the firewall configuration, you need to add the Apache service and the Nagios server port to the UFW firewall.

Add the SSH and Apache HTTP port with the ufw command below.

for svc in Apache ssh
do
ufw allow $svc
done

Then start the UFW firewall service and add it to the system boot.

ufw enable

Write ‘and‘and the UFW firewall service are activated.

Now check all available rules with the command below.

ufw status numbered

Now you get both SSH and Apache services added to the UFW firewall.

Add port to UFW firewall

And finally, you have completed the Nagios Core installation on the Ubuntu 20.04 server.

Step 3 – Install Nagios Plugins and NRPE Plugin

After installing Nagios Core, we will install Nagios Plugins and NRPE Plugins.

Both Nagios and NRPE plugins are available on Ubuntu repository by default. You can install these packages using the apt command below.

sudo apt install monitoring-plugins nagios-nrpe-plugin

When the installation is complete, go to nagio’s installation directory “/ usr / local / nagios / etc” and create a new directory for storing all server host configurations.

cd /usr/local/nagios/etc
mkdir -p /usr/local/nagios/etc/servers

Then edit the Nagios configuration ‘nagios.cfg’ with the vim editor.

vim nagios.cfg

Deselect the “cfg_dir” option that will be used for sooting all server-threat configurations.

cfg_dir=/usr/local/nagios/etc/servers

Save and close.

Next, edit the configuration file “resource.cfg” and define the binary files path for Nagios Monitoring Plugins.

vim resource.cfg

Define the Nagios Monitoring Plugins path by changing the default configuration as below.

$USER1$=/usr/lib/nagios/plugins

Save and close.

Then add nagio’s admin email contacts by editing the “objects / contacts.cfg” configuration file.

vim objects/contacts.cfg

Change the email address with your own.

define contact{
        ......
        email [email protected]
}

Save and close.

Now define the nrpe control command by editing the configuration object “objects / commands.cfg”.

vim objects/commands.cfg

Add the following configuration at the end of the line.

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

Save and close, and the Nagioscore configuration is complete.

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

systemctl start nagios
systemctl enable nagios

Set up Nagio's NRPE plugins

The Nagios service is running, check with the following command.

systemctl status nagios

Below is the result.

Check Nagios Service

As a result, the Nagios service is up and running. Now we need to restart the Apache service to apply a new Nagios configuration.

systemctl restart apache2

And the Nagios configuration is complete.

Open your browser and type the server’s IP address according to the “nagios” URL path.Advertisement

http://172.16.0.5/nagios/

Log in with the user “nagiosadmin” and enter your password.

Log in to Nagios Server

And you get Nagios Dashboard as below.

Nagio's dashboard

As a result, you have installed Nagios on the Ubuntu 20.04 server. And you can add hosts to the Nagios server.

Step 5 – Add Linux Host to Monitor

In this step, we will add the Ubuntu server with the hostname “client01” and the IP address “172.16.0.6” to the Nagios server.

– Install NRPE Server on Client01 Server

Log in to the “client01” server with your ssh.

ssh [email protected]

After logging in, update the Ubuntu layer and install Nagios Plugins and NRPE Server.

sudo apt update
sudo apt install nagios-nrpe-server monitoring-plugins

Then go to the NRPE installation directory “/ etc / nagios” and edit the “nrpe.cfg” configuration file.

cd /etc/nagios/
vim nrpe.cfg

Deselect the “server_address” line and change the value with the “client01” IP address.

server_address=172.16.0.6

Add Nagios Server IP address “172.16.0.5” to the line “allow_hosts”.

allowed_hosts=127.0.0.1,::1,172.16.0.5

Save and close.

Then edit the configuration “nrpe_local.cfg”.

vim nrpe_local.cfg

Change the IP address with the IP address “client01” and paste the configuration into it.

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

Save and close.

Now restart the NRPE service and add it to the system boot.

systemctl restart nagios-nrpe-server
systemctl enable nagios-nrpe-server

And Nagio’s NRPE server is up and running.

Add host to Nagios

Check the NRPE service with the following command.

systemctl status nagios-nrpe-server

The NRPE service is up and running.

Check Nagio's NRPE service

Go back to the Nagios server and check the NRPE server “client01”.

/usr/lib/nagios/plugins/check_nrpe -H 172.16.0.6
/usr/lib/nagios/plugins/check_nrpe -H 172.16.0.6 -c check_ping

And you will get the result as below.

Check NRPE status

And you have installed the Nagios NRPE server and Nagios Plugins on the “client01” host.

– Add host configuration to Nagios server

Back to the Nagios server terminal, go to the directory “/ usr / local / nagios / etc” and create a new configuration “server / client01.cfg”.

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

Change the IP address and host name with your own and paste the configuration into it.

# Ubuntu Host configuration file1

define host {
        use                          linux-server
        host_name                    client01
        alias                        Ubuntu Host
        address                      172.16.0.6
        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 APT Update
      check_command                   check_nrpe!check_apt
      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.

Restart Nagios Server.

systemctl restart nagios

Add host to Nagios Server

Step 5 – Test

Return to your browser and wait a few minutes.

Click “hosts“menu and you get” client01 “has been added.

Add host to Nagios

Below is detailed monitoring of the “client01” server.

Nagio's Services Monitoring

You have now added Host to monitor Nagios Server.

And the installation of Nagios 4.4.6 on Ubuntu 20.04 Server has been successfully completed.

Reference


Source link