Install and configure Icinga2 monitoring tool on Ubuntu 20.04

The
You can download this article in PDF format to support us through the following link.

Download the guide in PDF format

turn off
The

The
The

The epitome of infrastructure is when you know what the basic information of a device or any critical service is, when and how it changes in a way that draws attention. Adequate monitoring of the core resources within an organization can alleviate the burden of fear, conjecture, and panic, and replace it with systematic, organized, and well-founded remedial measures when any strange or catastrophic event occurs. Without the tools of managers and infrastructure managers, this is almost impossible to achieve. Icinga is one of the tools that can decorate the daily support and maintenance of the servers and services running in it.

Through its rich web pages, Icinga is a monitoring system that can check the availability of network resources, notify users of interruptions and generate performance data for reporting. Considered scalability and scalability during development. Icinga can monitor large, complex environments across multiple locations through distributed monitoring. To take advantage of this monitoring product, we will set up Icinga 2 and Icinga Web 2 on Ubuntu 20.04 (Focal Fossa).

Icinga 2 is a monitoring server, required Icinga Web 2 The browser allows you to see clearly, conveniently and comfortably what is happening under the hood. You can easily manage the configuration in any of the following ways Director Icinga, Configuration management tools or Icinga DSL. We will start by installing Icinga 2 and start venting.

Phase 1: Install and configure Icinga 2 on Ubuntu 20.04

At this stage Icinga2 will be installed gradually. Empecemos.

Step 1: Update and install the necessary applications

We will start with a clean and up-to-date server with the latest software.

sudo apt update && sudo apt upgrade

Install the basic applications we need throughout the installation process.

sudo apt install -y vim apt-transport-https wget gnupg

Step 2: Add the Icinga package repository

We will need to add the Icinga repository to our server package management configuration as shown below.

wget -O - https://packages.icinga.com/icinga.key | sudo apt-key add -
. /etc/os-release; if [ ! -z ${UBUNTU_CODENAME+x} ]; then DIST="${UBUNTU_CODENAME}"; else DIST="$(lsb_release -c| awk '{print $2}')"; fi;
echo "deb https://packages.icinga.com/ubuntu icinga-${DIST} main" | sudo tee /etc/apt/sources.list.d/${DIST}-icinga.list
echo "deb-src https://packages.icinga.com/ubuntu icinga-${DIST} main" | sudo tee -a /etc/apt/sources.list.d/${DIST}-icinga.list

Then update the server to obtain the software package from the newly added repository.

sudo apt update

Step 3: Install Icinga2 on Ubuntu 20.04

Now that we have the official Icinga repository, we can install Icinga 2 using the apt package manager to obtain the icinga2 package, as shown below.

sudo apt install icinga2 -y

Step 4: Set up check plugins

No plugin Icinga 2 does not know how to check external services. of Monitor plug-in projects An extensive set of plug-ins is provided, which can be used with Icinga 2 to check whether the service is working properly. The recommended way to install these standard plugins is to use Ubuntu’s package manager, as shown below.

sudo apt install monitoring-plugins -y

After completion, start and enable icinga2

sudo systemctl enable --now icinga2

And check its status

$ systemctl status icinga2

● icinga2.service - Icinga host/service/network monitoring system
     Loaded: loaded (/lib/systemd/system/icinga2.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/icinga2.service.d
             └─limits.conf
     Active: active (running) since Wed 2020-07-15 12:33:17 EAT; 3min 53s ago
   Main PID: 42856 (icinga2)
      Tasks: 8
     Memory: 13.3M
     CGroup: /system.slice/icinga2.service

Step 5: Install MySQL | MariaDB and configure DB IDO MySQL

Icinga 2’s database Icinga data output (DB IDO) function is responsible for exporting all configuration and status information to the database. Let’s install MariaDB and database Icinga data output.

Fortunately, we already have a detailed guide to install MariaDB 10.5. See how to install MariaDB on Ubuntu 20.04 (Focal Fossa)

After that, install DB IDO as shown below.

sudo apt install icinga2-ido-mysql -y

During the installation process, you will see a prompt, please select “First of all.

In the second prompt, select ““, because we have installed and configured the database.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

Next, create a database and user for Icinga2. You are free to use different names to name the database and user, and make sure to use a secure password.

$ mysql -u root -p

MariaDB [(none)]> CREATE DATABASE icinga;
MariaDB [(none)]> GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON icinga.* TO 'icinga'@'localhost' IDENTIFIED BY 'icinga';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> quit

After creating the database, you can use the following command to import the Icinga 2 IDO mode. When asked, enter the root password at the prompt and take a moment to complete.

$ mysql -u root -p icinga < /usr/share/icinga2-ido-mysql/schema/mysql.sql
Enter password: 

Step 6: Enable IDO MySQL module

The package provides a new configuration file, which is installed in /etc/icinga2/features-available/ido-mysql.conf. Update the database credentials in this file.

$ sudo vim /etc/icinga2/features-available/ido-mysql.conf

/**
 * The db_ido_mysql library implements IDO functionality
 * for MySQL.
 */

library "db_ido_mysql"

object IdoMysqlConnection "ido-mysql" {
  user = "icinga",
  password = "icinga",
  host = "localhost",
  database = "icinga"
}

Next, use icinga2 feature enable to enable the ido-mysql function configuration file as follows:

$ sudo icinga2 feature enable ido-mysql
Enabling feature ido-mysql. Make sure to restart Icinga 2 for these changes to take effect

Restart Icinga 2 as recommended.

sudo systemctl restart icinga2

Step 7: Set up Icinga 2 REST API

Icinga Web 2 and other web interfaces require REST APIs to send actions (rearrange inspections, etc.) and query object details. The important thing is that we need to activate the api.

Use the icinga2 cli command to enable the api function as follows:

sudo icinga2 api setup

The sample output when running the above command is shown below

information/cli: Generating new CA.
information/base: Writing private key to '/var/lib/icinga2/ca//ca.key'.
information/base: Writing X509 certificate to '/var/lib/icinga2/ca//ca.crt'.
information/cli: Generating new CSR in '/var/lib/icinga2/certs//ubuntu-20.04-amd64.csr'.
information/base: Writing private key to '/var/lib/icinga2/certs//ubuntu-20.04-amd64.key'.
information/base: Writing certificate signing request to '/var/lib/icinga2/certs//ubuntu-20.04-amd64.csr'.       
information/cli: Signing CSR with CA and writing certificate to '/var/lib/icinga2/certs//ubuntu-20.04-amd64.crt'.
information/pki: Writing certificate to file '/var/lib/icinga2/certs//ubuntu-20.04-amd64.crt'.
information/cli: Copying CA certificate to '/var/lib/icinga2/certs//ca.crt'.
information/cli: Adding new ApiUser 'root' in '/etc/icinga2/conf.d/api-users.conf'.
information/cli: Reading '/etc/icinga2/icinga2.conf'.
information/cli: Enabling the 'api' feature.
Enabling feature api. Make sure to restart Icinga 2 for these changes to take effect.
information/cli: Updating 'NodeName' constant in '/etc/icinga2/constants.conf'.
information/cli: Created backup file '/etc/icinga2/constants.conf.orig'.
information/cli: Updating 'ZoneName' constant in '/etc/icinga2/constants.conf'.
information/cli: Backup file '/etc/icinga2/constants.conf.orig' already exists. Skipping backup.

The above command will not only enable the api function, but also use the automatically generated password to set the certificate and the new API user root in the /etc/icinga2/conf.d/api-users.conf configuration file.

Edit the /etc/icinga2/conf.d/api-users.conf file and add a new ApiUser object below the automatically generated ApiUser object, and specify the permission attribute using the minimum permissions required by Icinga Web 2.

$ sudo vim /etc/icinga2/conf.d/api-users.conf

object ApiUser "icingaweb2" {
  password = "Wijsn8Z9eRs5E25d"
  permissions = [ "status/query", "actions/*", "objects/modify/*", "objects/query/*" ]
}

Please note that by default, this API will listen on port 5665.

For clarity, the screenshot of the entire configuration file is shared below

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

Restart Icinga 2 to activate the new configuration.

sudo systemctl restart icinga2

Phase 2: Set up Icinga Web 2

Icinga 2 can be used with Icinga Web 2 and various modules to improve the monitoring experience. This section explains how to set up Icinga Web 2.

Step 1: Add the package repository

The preferred method of installing Icinga Web 2 is to use the official package repository. Please note that if Icinga Web 2 and Icinga 2 are installed on the same server, there is no need to add the repository again. On the other hand, if you plan to install Icinga Web 2 on a separate Ubuntu 20.04 server, you must perform Step 1 and Step 2 in Phase 1 of Setting Up Icinga 2 above.

Step 2: Install Icinga Web 2

We will use the apt package manager to retrieve and install the icingaweb2 package. Below are the commands we will execute. You will notice other packages icingacli and libapache2-mod-php. libapache2-mod-php is cool for Ubuntu because it makes Icinga Web 2 directly usable without touching PHP FPM. In addition, after installing Icinga Web 2, your web server should be up and running. This is only in the Ubuntu | Debian installation.

sudo apt install icingaweb2 libapache2-mod-php icingacli -y

Step 3: Prepare Web settings

In order to prepare for the web setup, we will have to manually create the database and database user. If you are on a separate server, you must install MariaDB | MySQL for this part. Please use how to install MariaDB on Ubuntu 20.04 (Focal Fossa) for quick setup. If you are on the same server, skip the link and continue to add database users.

$ mysql -u root -p

MariaDB [mysql]> CREATE DATABASE icingaweb2;
MariaDB [mysql]> GRANT ALL ON icingaweb2.* TO [email protected] IDENTIFIED BY 'StrongPassword';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> quit

Once completed, we will continue to use the Icinga Web 2 Setup Wizard to set up Icinga Web 2 quickly and easily, which is available the first time you access Icinga Web 2 in your browser. When using network settings, you need to use a token for authentication. In order to generate tokens, we will use the icingacli tool available to us as shown below.

sudo icingacli setup token create
The newly generated setup token is: 47cd8e45837e8db0

You can use icingacli to display the token later:

sudo icingacli setup token show

If you have a firewall, please allow port 80 or 443 (if you are using https)

sudo ufw allow http

Step 4: Start the web installer

Finally, visit Icinga Web 2 in the browser to access the installation wizard and complete the installation: http: //[domain-name-or-ip-address]/icingaweb2/setup.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

This will launch the web interface, where we will complete the setup of Icinga Web 2. On the first page shown below, you will be asked to enter the token we created before this step. Copy and paste the token into it and click “next”

Module

The second page prompts you to activate other modules put together by the Icinga team. If you think they are helpful, just activate them and click “nextNext step.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

PHP module

The following page shows the available PHP modules and the missing PHP modules. Click “next”.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

Configure authentication type

The next step is to choose the type of authentication you will use. If you have an LDAP implementation or want to use a database, please select the one that suits your needs from the drop-down list. hit”nextOnce completed.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

Configuration Database | LDAP

Based on what you selected in the previous step, a form will be displayed to fill in the details required by Icinga Web 2 to authenticate the user. This guide will use the database. Enter the database details that we typed in step 3, step 2. When you are finished, you can click “Verify Configuration” to cross-check that the details you entered are correct. Click “nextafter finishing.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

The message displayed after verification is as follows

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

Certified backend

The next page will ask you to name the backend.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

Add administrative user

Next, we will add an administrative user, which will be used to log in to Icinga web2 after setup. Through this account, we can also create other users.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

Application configuration

Here, adjust all configuration options related to the application and logging to suit your needs, then click “next

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

Review the completed configuration

At this stage, we have successfully configured Icinga Web 2. We just need to confirm our settings before setting. If everything is fine, please click “next“.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

Configure monitoring module

The monitoring module provides various status and report views through powerful filter functions, enabling you to track the most important events in the monitoring environment. Click “next“Start configuring the monitoring module.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04Configure monitoring backend

This will guide Icinga 2 how to obtain monitoring information.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

Monitor IDO resources

Fill in the connection details below to access the IDO database we configured in step 5, stage 1. Verify the settings and click “next“.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

After proper verification, you should see a success message similar to this. Click “next” go ahead.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

Direct transportation

This is a good place for the API we set up in stage 1, step 7. Enter the details you set in the environment in the form. As a reminder, the configuration of this guide is as follows:

object ApiUser "icingaweb2" {
  password = "Wijsn8Z9eRs5E25d"
  permissions = [ "status/query", "actions/*", "objects/modify/*", "objects/query/*" ]
}

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

After typing the credentials, click “verification“To check that all settings are correct.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

Monitor security

To protect your surveillance environment from prying eyes, please fill in the following settings.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

Final monitoring module review

You can review the changes you should make before completing this step. It is recommended that you return at any time to make any corrections. Otherwise, if everything looks beautiful, click “Finish“, you will receive the message “Icinga Web 2 has been successfully set up.”

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

Click “Log in to Icinga Web 2“To start monitoring with Icinga. The next screenshot shows the rest of the road.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

This will make you fall into the arms of the “login page”. Enter the administrative user we created earlier, and then you should enter through the gate.

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

Install and configure Icinga2 monitoring tool on Ubuntu 20.04

ul off

We finally ended the Icinga monitoring guide. It has been a long time, but we have finally arrived. We thank you for your presence, support and everything you have provided.

Must read:

Install Sensu Monitoring Tool on Ubuntu

10 best open source Linux monitoring tools

How to install Ajenti control panel on Ubuntu

The
You can download this article in PDF format to support us through the following link.

Download the guide in PDF format

turn off
The

The
The

Sidebar