How to Install Icinga2 on Ubuntu 20.04

Icinga2 is a free, open-source, and cross-platform monitoring tool written in PHP and C++. It can monitor network resources, notifies outages, large complex environments, generate performance data for reporting. Icinga is scalable and extensible.

Icinga capabilities include monitoring SMTP, POP3, HTTP, NNTP, ping, CPU load, disk usage, switches, routers, and more.

The Icinga stack consists of Icinga2 - which monitoring server and Icinga Web 2 - is the web interface to keep monitoring.

In this tutorial learn how to install Icinga2 on Ubuntu 20.04 LTS. We also configure the Icinga Web 2 interface.

Step 1: Install LAMP Stack

Icinga runs on a web server and is accessed from a browser. So the first step is to install the LAMP stack. LAMP is the acronym for Linux Apache MariaDB/MySQL and PHP. Apache is the webserver, MariaDB is the database server and PHP is the popular server-side scripting language.

Let's begin. First update the package lists:

$ sudo apt update

To install Apache web server, run the command:

$ sudo apt install apache2 

Once Apache is installed, enable it to automatically start on boot time.

$ sudo systemctl enable apache2 

Then Start Apache daemon.

$ sudo systemctl start apache2

To confirm that the web server is running, execute:

$ sudo systemctl status apache2
Check Apache2 status
Check Apache2 status

Moving on, we will install the MariaDB database server and client.

$ sudo apt install mariadb-server mariadb

Once the installation is complete, enable MariaDB to start on boot.

$ sudo systemctl enable mariadb

Then start the MariaDB daemon.

$ sudo systemctl start mariadb

Once again, verify the status of MariaDB

$ sudo systemctl status mariadb
Enable start and confirm the status of MariaDB
Enable start and confirm the status of MariaDB

To harden the database server run the script

$ sudo mysql_secure_installation

Be sure to secure the database server with a root password.

Harden MariaDB database server
Harden MariaDB database server

And answer 'Yes' for the remaining prompts to secure the database server.

Harden MariaDB database server
Secure MariaDB database server

Moving on, we will install PHP which is the remaining component of the LAMP stack. But first, install the dependencies shown.

$ sudo  apt install software-properties-common

Then add the OndeJ repository which provides the latest version of PHP, which currently is PHP 8.0. Icinga requires PHP 7.3 and later versions so we are well within the required version range.

$ sudo add-apt-repository ppa:ondrej/php

Once the repository is added, install PHP and the required dependencies for installation of Icinga

$ sudo apt install php php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip php-cli php-mysql php8.0-common php8.0-opcache php-gmp php-imagick

Then verify the version of PHP installed.

$ php -v
Check PHP version
Check PHP version

A few modifications are required. Edit the php.ini file.

$ sudo vim /etc/php/8.0/apache2/php.ini

Be sure to set the date.timezone parameter and set the cgi.fix_pathinfo parameter to 0.

date.timezone = Africa/Kolkata
cgi.fix_pathinfo=0

Save the changes and exit.

Step 2: Add the Icinga2 repository

The next step is to install Icinga2 on Ubuntu. However, since Icinga's repository is not hosted on the Ubuntu repository, we need to manually add the repository locally.

First, add Icinga's GPG key

$ curl https://packages.icinga.com/icinga.key | apt-key add -

Next, create a repository file for Icinga in the /etc/apt/sources.list.d directory.

$ sudo vim /etc/apt/sources.list.d/icinga-focal.list

Then add the following lines to define where Ubuntu will download Icinga from.

deb http://packages.icinga.com/ubuntu icinga-focal main
deb-src http://packages.icinga.com/ubuntu icinga-focal main

Save and exit the configuration file.

Step 3: Install Icinga2

First, update the package lists and repositories first.

$ sudo apt update

Then install Icinga2 and monitoring plugins.

$ sudo apt install icinga2 monitoring-plugins

Once installed, enable the Icinga monitoring tool.

$ sudo systemctl enable icinga2

Then start the service.

$ sudo systemctl start icinga2

Then check the running status of Icinga.

$ sudo systemctl status icinga2
Check Icinga status
Check Icinga status

Icinga is running as expected and that's a good sign that we are headed in the right direction.

Step 4: Install the Icinga2 IDO MySQL module

The Icinga Data Output (IDO) feature exports all the configuration and status information into a database. The IDO database is used as a data backend by Icinga Web 2.

To install the Icinga IDO database module, run the command:

$ sudo apt install icinga2-ido-mysql

The installation will get underway and along the way, you get this pop-up prompting you to enable Icinga 2's ido-mysql feature. Select 'Yes' option and press ENTER.

Select whether to enable Icinga 2 ido-mysql feature
Select whether to enable Icinga 2 ido-mysql feature

The icinga2-ido-mysql module must have a database installed and configured so that it can be used. We are going to configure the database manually in the MariaDB database server, so when prompted whether to create it automatically, select 'No' and press ENTER.

Select No to cancel icinga-ido-mysql database creation
Select No to cancel icinga-ido-mysql database creation

The next step is to manually create the database for the icinga2-ido-mysql module.

Login to MariaDB shell.

$ sudo mysql -u root -p

Run the commands provided to create the database, database user and grant all privileges to the user.

>  CREATE DATABASE icinga2db;

>  GRANT ALL ON icinga2db.* TO 'icinga2user'@'localhost' IDENTIFIED BY 'P@ssword';

>   FLUSH PRIVILEGES;

>   EXIT;

Once the database is in place, import the Icinga2 IDO schema using the command shown. When prompted, type the root password and hit ENTER.

Import IDO-mysql-schema
Import IDO-mysql-schema

Step 5: Enable the IDO MySQL module

The IDO package comes with its configuration file called ido-mysql.conf. We need to access this file and modify the database connection details.

So, access the configuration file.

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

Edit the database details for the user, password, host, and database with what you specified in the previous step and save the changes

database details for ido_mysql
database details for ido_mysql

Thereafter, enable the ido-mysql module.

$ sudo icinga2 feature enable ido-mysql
Enable ido-mysql module
Enable ido-mysql module

To effect all the changes we have made, restart the Icinga2 service.

$ sudo systemctl restart icinga2

Step 6: Install and setup Icinga Web 2

The next step is to install Icinga Web 2 package. This is a powerful and extensible PHP framework for applications that provides a neat and intuitive IU for Icinga.

To install Icinga Web 2 alongside with Icinga2 client and PHP module run the command:

$ sudo apt install icingaweb2 icingacli libapache2-mod-php

Once installed, create a database for Icinga Web 2 as follows.

$ sudo mysql -u root -p

Define the database and database user and assign privileges and save the changes.

>  CREATE DATABASE icingaweb2;

>  GRANT ALL ON icingaweb2.* TO 'icingaweb2user'@'localhost' IDENTIFIED BY 'P@ssword';

>   FLUSH PRIVILEGES;

>   EXIT;

The next step involves setting up Icinga2 using the Icinga2 Web wizard installer. This requires a token, and therefore generates the token using the Icinga client.

$ sudo icingacli setup token create

Copy and paste this token somewhere.

Generate token using Icinga CLI
Generate token using Icinga CLI

If you clear the screen or forget the token, don't worry. You can display it at some other point in time, by running:

$ sudo icingacli setup token show

Step 7: Set up Icinga Web 2 on the browser

To access the Icinga2 Web installer browse the following address:

http://server-ip/icingaweb2/setup

You will get the welcome page shown. Paste the token you created and press 'Next'.

Welcome to Icinga Web 2 wizard
Welcome to Icinga Web 2 Wizard

The next page presents all the modules that can be activated. By default 'Monitoring' is selected which will be enough for now. Feel free to activate others.

Select Icinga2 modules
Select Icinga2 modules

Once done, click on the 'Next' button.

Select the preferred module and click Next
Select the preferred module and click Next

The next page shows all the PHP modules that have been enabled. As we installed the required modules, you shouldn't get an error or warning.

Icinga enabled PHP modules
Icinga enabled PHP modules

Simply scroll down and click the Next button.

Click Next PHP modules satisfied Icinga Web 2
Click Next PHP modules satisfied Icinga Web 2

For authentication type, choose 'Database' and click 'Next'.

Select Authentication Type Icinga Web 2
Select Authentication Type Icinga Web 2

Next, enter the database details that you created for Icinga in Step 4.

Enter database details for Icinga
Enter database details for Icinga

At the bottom click on 'Validate configuration' to check if the database details provided are correct.

Vaidate database configuration
Vaidate database configuration

if everything went according to plan, you will get a notification that the configuration has been successfully validated.

Icinga  configuration has been successfully validated
Icinga configuration has been successfully validated

In the next step, just click next to accept the default selection of Icingaweb2 as the authentication backend type.

Icinga Authentication Backend
Icinga Authentication Backend

Next, create the Admin user that you will use to login to Icinga web GUI.

Create Admin user for Icinga
Create Admin user for Icinga

In the next step, just hit ENTER to accept the default Application configuration details.

Accept the default Application configuration details.
Accept the default Application configuration details.

At this point, Icinga2 has been successfully configured. Review all the settings made. If all looks good, scroll down and hit the Next button.

Review Icinga2 web settings
Review Icinga2 web settings

The next step requires you to configure the monitoring module. This is the core module that provides you with powerful filtering capabilities and helps you to keep track of events. So, click the Next button.

Configuration of monitoring module for Icinga2
Configuration of monitoring module for Icinga2

In the 'Monitoring IDO Resource' step, fill out the database details for Icinga2 Web created in Step 6.

Monitoring IDO resource fill out the database details for Icinga2
Monitoring IDO resource fill out the database details for Icinga2

Scroll all the way down and click 'Validate configuration' to confirm if the settings are Ok.

Validate module configuration
Validate module configuration

If all the settings are okay, you should get confirmation that the configuration was validated successfully.

Module configuration validated successfully.
Module configuration validated successfully

For Command Transport select Local Command File and click Next.

Icinga Command Transport

For Monitoring Security simply press Next to accept the defaults.

Icinga monitoring Security

Finally review all the module configuration settings.

Review all module configuration settings
Review all module configuration settings

If all looks good. Click on the Finish button, else head back and edit some of the settings.

Click on Finish to finalize Icinga installation
Click on Finish to finalize Icinga installation

You will get a confirmation that Icinga Web 2 has successfully been set up. To log in click on the link Login to Icinga Web 2 button.

Icinga Web 2 successfully created
Icinga Web 2 successfully created

This brings you to the login screen. Type the Icinga login credentials and press the Login button.

Icinga login screen

Once logged in, you will get the dashboard provided.

Conclusion

In this tutorial, we learned how to install Icinga2 and Icinga Web 2 on Ubuntu 20.04. Thanks for reading, please lets us know your suggestions in the below comment section.

Leave a Comment