Kiến Thức Linux Monitoring

How to Install Nagios Monitoring Software on Ubuntu 18.04 LTS

Nagios is open-source software for system and network monitoring. Nagios can monitor the activity of a host and its services and provides a warning/alert if something bad happens on the server. Nagios can run on Linux operating systems, and we will be using the Ubuntu 18.04 server.In this tutorial, we will show you step by step installing the Nagios 4.4.x on Ubuntu 18.04. We will install the Nagios Core 4.4.x from source, install the nrpe and nagios plugins, and then add host to monitor to the Nagios server.Prerequisites

  • 2 Ubuntu 18.04 servers
    • Nagios server – hostname: hakase-nagios with an IP: 10.5.5.11
    • Ubuntu client – hostname: client01 with an IP: 10.5.5.12
  • Root privileges

What we will do:

  • Install Packages Dependencies
  • Install Nagios Core 4.4.5
  • Install Nagios Plugin and NRPE Plugin
  • Add Host to Monitor to Nagios Server
  • Testing

Step 1 – Install Packages Dependencies

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

Update the Ubuntu repository using the apt command below.

sudo apt update

After that, install packages dependencies for Nagios installation.

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

And you’ve installed packages dependencies for Nagios server.

Step 2 – Install Nagios Core 4.4.5

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

Download Nagios Core 4.4.5

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

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

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

tar xzf nagios-4.4.5.tar.gz
cd nagioscore-nagios-4.4.5/

Compile and Install Nagios

First, compile Nagios source code and define the Apache virtual host configuration for Nagios.

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

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

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

Install Nagios binaries, service daemon script, and the command mode.

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

After that, install the sample script configuration.

sudo make install-config

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

sudo make install-webconf
sudo a2enmod rewrite cgi

Now restart the Apache service.

systemctl restart apache2

And you’ve installed the Nagios Core 4.4.5.

Create nagiosadmin user

After installing the Nagios Core, we will add the basic authentication for accessing the Nagios dashboard. And we will be using the basic Apache authentication.

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

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

Type your strong password.

And you’ve created a new user ‘nagiosadmin’ for the Nagios dashboard authentication.

Setup UFW Firewall

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

Add the Apache HTTP port and the Nagios port ” using the ufw command below.

sudo ufw allow Apache

Now reload the UFW firewall.

sudo ufw reload

And you’ve completed the Nagios Core installation on the Ubuntu 18.04 server.

Step 3 – Install Nagios Plugins and NRPE Plugin

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

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

sudo apt install nagios-plugins nagios-nrpe-plugin

Once the installation is complete, go to the nagios installation directory “/usr/local/nagios” and edit the configuration file “nagios.cfg”.

cd /usr/local/nagios/
vim nagios.cfg

Uncomment the additional config directory for servers.

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

Save and close.

Now create a new directory “/usr/local/nagios/etc/servers” that will be used for storing the configuration of host monitor.

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

After that, go to the “/usr/local/nagios/etc/” directory and edit the configuration file “resurces.cfg”.

cd /usr/local/nagios/etc/
vim resources.cfg

Change the default directory for Nagios plugins as below.

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

Save and close.

Next, add the nagios admin contacts by editing the configuration file “objects/contacts.cfg”.

vim objects/contacts.cfg

Change the email address with your own.

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

Save and close.

Next, define the nrpe check command by editing the configuration file “objects/commands.cfg”.

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 start nagios
systemctl enable nagios

The Nagios service is up and running, check using the following command.

systemctl status nagios

Below is the result.

Next, we need to restart the Apache service to apply a new Nagios configuration.

systemctl restart apache2

After that, open your web browser and type the server IP address following the “nagios” URL path.

http://10.5.5.11/nagios/

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

And you will get the Nagios Dashboard as below.

As a result, you’ve installed Nagios on the Ubuntu 18.04 server. And you’re able to add hosts to the Nagios server.

Step 5 – Add Linux Host to Monitor

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

Install NRPE Server on the Client01 Server

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

ssh [email protected]

Once you’ve logged in, update the Ubuntu repository and install Nagios Plugins and NRPE Server.

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

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

cd /etc/nagios/
vim nrpe.cfg

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

server_address=10.5.5.12

One the “allowed_hosts” line, add the Nagios Server IP address “10.5.5.11”.

allowed_hosts=127.0.0.1,::1,10.5.5.11

Save and close.

Next, edit the “nrpe_local.cfg” configuration.

vim nrpe_local.cfg

Change the IP address with the “client01” IP address, 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 10.5.5.12 -w /
100.0,20% -c 500.0,60% -p 5
command[check_ssh]=/usr/lib/nagios/plugins/check_ssh -4 10.5.5.12
command[check_http]=/usr/lib/nagios/plugins/check_http -I 10.5.5.12
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 the Nagios NRPE server is up and running.

Check the NRPE service using the following command.

systemctl status nagios-nrpe-server

The NRPE service is up and running.

Next, back to the Nagios Server and check the “client01” NRPE server.

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

And you will get the result as below.

And you’ve installed the Nagios NRPE Server and Nagios Plugins on the “client01” host.

Add Hosts Configuration to the Nagios Server

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

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

Change the IP address and the hostname 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                      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 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.

Now restart the Nagios Server.

systemctl restart nagios

Step 5 – Testing

Back to your browser and wait for some minutes.

Click on the “Hosts” menu and you will get the “client01” has been added.

Below are details monitoring about the “client01” server.

Now you’ve added Host to monitor to the Nagios Server.

And the installation of Nagios 4.4.5 on Ubuntu 18.04 Server has been completed successfully.

Reference

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Tags

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !