As your data center is being populated with more and more Linux servers, you need to have the means to monitor those systems. As with anything in the open source world, there are a vast number of tools available for the task. One such tool is Icinga2, a web-based system monitor that keeps a constant check on the availability of network resources, generates real-time reporting on performance and services, and can even notify users of outages. Icinga2 also uses a RESTful API, so you can update configuration files on the fly and notifications can come by way of email, texts, or mobile messaging applications.

I want to walk you through the process of installing Icinga2 on Ubuntu Server 16.04. I will assume you have the operating system installed and a user account with sudo privileges. With that said, let’s install.

SEE: Wireless networking policy (Tech Pro Research)

Installing Apache

The first thing that must be done is the installation of both the web and database server. Before you do that, however, it’s wise to update and upgrade your server. Open a terminal window and issue the commands:

sudo apt-get update
sudo apt-get upgrade

Should your kernel be upgraded in the process, you’ll need to reboot the server. Because of this, it is recommended that you run the update/upgrade at a time when a reboot is feasible.

With the update/upgrade out of the way, it’s time to install Apache (and it’s required PHP modules). Back at the terminal window, issue the command:

sudo apt-get install apache2 libapache2-mod-php

Once that completes, install the PHP modules with the command:

sudo apt-get install php php-{xml,cli,opcache,gd,intl,readline,mysql,curl,mbstring,ldap,json,pgsql}

Now we need to configure your timezone in the php.ini file. Issue the command:

sudo nano /etc/php/7.0/apache2/php.ini

In that file, look for the following line:

date.timezone = Africa/Nairobi

Change it to reflect your timezone (such as America/Kentucky/Louisville). Save and close the file.

Restart Apache with the command:

sudo systemctl restart apache2

Installing MySQL

Next we’ll install MySQL. From the terminal window, issue the following command:

sudo apt-get install mysql-server

During this installation, you will be asked to create/verify a MySQL admin password.

SEE: Web server configuration and management policy (Tech Pro Research)

Creating the database

With the database server installed, it’s time to create the databases for Icinga2. We actually must create two databases, one for Icinga2 and Icinga Web2. Gain access to the MySQL prompt with the command:

mysql -u root -p

You’ll be required to type the MySQL admin password you created during the installation. Once at the prompt, create the first database (and a user) with the commands:

GRANT ALL PRIVILEGES on icinga2_db.* to 'icinga2_user'@'localhost' identified by 'PASSWORD';

where PASSWORD is a unique and strong password.

Next, create the Icinga Web2 database with the following commands:

CREATE DATABASE icingaweb2_db;
GRANT ALL PRIVILEGES on icingaweb2_db.* to 'icingaweb2_user'@'localhost' identified by 'PASSWORD';

where PASSWORD is a unique and strong password.

Install Icinga2 and Icinga Web2

The first thing to do is import the GPG key with the command:

curl -sSL | sudo apt-key add -

Next add the apt repository with the command:

echo "deb icinga-bionic main" | sudo tee /etc/apt/sources.list.d/icinga.list

Notice we are adding the bionic repository (even though we are using Xenial). It still works.

Update apt with the command:

sudo apt-get update

Finally, install Icinga2 and Icinga Web2 with the command:

sudo apt-get install icinga2 icingaweb2 icinga2-ido-mysql

When asked if Icinga2 should use MySQL, answer YES and then answer NO when asked if the dbconfig-common should be used to configure the database.

SEE: IT pro’s guide to working smarter with Linux (Tech Pro Research)

Configure the backend

We now need to enable ido-mysql and the Icinga2 command features with the command:

sudo icinga2 feature enable command ido-mysql

Restart Icinga2 with the command:

sudo systemctl restart icinga2

Next we need to configure MySQL IDO. Issue the command:

sudo nano etc/icinga2/features-enabled/ido-mysql.conf

In that file, make sure the object section looks like this:

object IdoMysqlConnection "ido-mysql" {
user = "icinga2_user",
password = "PASSWORD",
host = "localhost",
database = "icinga2_db"

where PASSWORD is the password you created for the icinga2_user account from the MySQL prompt.

Save and close that file, and then restart Icinga2 with the command:

sudo systemctl restart icinga2

The web installer

Before you point your browser to the Icinga Web2 installation (to finalize the install), you must generate a setup token. To do that, issue the command:

sudo icingacli setup token create

This will create a string of characters that will then be entered in the first page of the web installer. Point your browser to http://SERVER_IP/icingaweb2 (where SERVER_IP is the IP address of your hosting server) and you will then be asked for to enter the token (Figure A).

Figure A

You will also see a few extra steps outlined below the Setup Token text area. These are automatically taken care of during the installation. Should you run into any problems, go back to this page and issue the suggested commands.

The resulting page will check to make sure everything is ready to go. You shouldn’t see any issues at this point, so click Next. In the following setup pages, you will be asked to:

  1. Select the modules you want to include: I suggest selecting all three.
  2. Authentication: Select Database.
  3. Configure Icinga2 database: Make sure to use icingaweb2_db and icinga2web_user/password as the database name and database user here.
  4. Monitoring IDO Resource: Make sure to use the icinga2_db database and icinga2_user user/password here.
  5. Command Transport: Leave the defaults.
  6. Create an admin user.

Once all of that is completed, you’ll be prompted to log into the Icinga2 Web Interface. Congratulations, you’ve successfully installed Icinga2, and it is now monitoring your server. Enjoy this powerful tool that will keep you in the know as to your server’s health. In our next entry, we’ll walk through the process of adding remote hosts to monitor.