Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Icinga: How to Install Icinga 2 on Ubuntu

Prerequisites

  • A server with Ubuntu 22.04 as OS
  • User privileges: root or non-root user with sudo privileges

Step 1. Update the System

Before we start to install the software, we need to update the system packages to the latest versions available.

$ sudo apt-get update -y && sudo apt-get upgrade -y

Step 2. Install LAMP stack

First of the LAMP stack is the Apache Web server. To install it execute the following command:

$ sudo apt install apache2 -y

Once installed, start and enable the service.

$ sudo systemctl enable apache2 && sudo systemctl start apache2

Check if the service is up and running:

$ sudo systemctl status apache2

You should receive the following output:

root@host:~# sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2023-04-22 18:00:43 CDT; 17min ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 792 (apache2)
      Tasks: 7 (limit: 4571)
     Memory: 22.5M
        CPU: 246ms
     CGroup: /system.slice/apache2.service

Next is PHP, along with its extensions. To install the PHP8.1 along with extensions, execute the following command:

$ sudo apt-get install php8.1 php8.1-cli php8.1-common php8.1-imap php8.1-redis php8.1-snmp php8.1-xml php8.1-zip php8.1-mbstring php8.1-curl libapache2-mod-php

$ sudo apt install imagemagick

The last of the LAMP stack is the MariaDB database server. To install it execute the command below.

$ sudo apt install mariadb-server -y

Start and enable the mariadb.service with the following commands:

$ sudo systemctl start mariadb && sudo systemctl enable mariadb

Check the status of the mariadb.service

$ sudo systemctl status mariadb

You should receive the following output:

root@host:~# sudo systemctl status mariadb
● mariadb.service - MariaDB 10.6.12 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2023-04-22 18:19:53 CDT; 9s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 5829 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 16 (limit: 4571)
     Memory: 61.4M
        CPU: 514ms
     CGroup: /system.slice/mariadb.service
             └─5829 /usr/sbin/mariadbd

Change the mariadb password

For securing the database, you should use sudo again.

$ sudo mysql_secure_installation


Step 3. Install Icinga 2

First, we will add the GPG key, and will create a repository:

REFERENCE – https://icinga.com/docs/icinga-2/latest/doc/02-installation/02-Ubuntu/

wget -O - https://packages.icinga.com/icinga.key | gpg --dearmor -o /usr/share/keyrings/icinga-archive-keyring.gpg

. /etc/os-release; if [ ! -z ${UBUNTU_CODENAME+x} ]; then DIST="${UBUNTU_CODENAME}"; else DIST="$(lsb_release -c| awk '{print $2}')"; fi; \
 echo "deb [signed-by=/usr/share/keyrings/icinga-archive-keyring.gpg] https://packages.icinga.com/ubuntu icinga-${DIST} main" > \
 /etc/apt/sources.list.d/${DIST}-icinga.list
 echo "deb-src [signed-by=/usr/share/keyrings/icinga-archive-keyring.gpg] https://packages.icinga.com/ubuntu icinga-${DIST} main" >> \
 /etc/apt/sources.list.d/${DIST}-icinga.list

Update the system and install Icinga2

$ sudo apt update -y

$ sudo apt install icinga2 -y

After installation, start and enable the icinga2 service.

$ sudo systemctl start icinga2 && sudo systemctl enable icinga2

Check the status of Icinga 2:

$ sudo systemctl status icinga2

You should get the following output:

root@host:~# sudo 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 Sat 2023-04-22 19:06:11 CDT; 4min 35s ago
   Main PID: 11632 (icinga2)
     Status: "Startup finished."
      Tasks: 16
     Memory: 14.3M
        CPU: 435ms
     CGroup: /system.slice/icinga2.service

Step 4. Install the Icinga2 IDO Module

To install the Icinga2 IDO module, execute the following command:

$ sudo apt install icinga2-ido-mysql -y

While installing, choose Yes on both windows. It is about Icinga2 using MySQL.

After this, we need to create an icinga2-ido-mysql database with the following commands:

$ mysql -u root -p

CREATE DATABASE icinga_ido_db;
GRANT ALL ON icinga_ido_db.* TO 'icinga_ido_db'@'localhost' IDENTIFIED BY 'YourStrongPasswordHere';
FLUSH PRIVILEGES;
EXIT;

Once the database is created, import the Icinga2 IDO schema with the following command:

$ sudo mysql -u root -p icinga_ido_db < /usr/share/icinga2-ido-mysql/schema/mysql.sql

Once the schema is imported, the next is to enable the Icinga2 IDO module:

$ vi  /etc/icinga2/features-available/ido-mysql.conf

Paste the following lines of code:


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

library "db_ido_mysql"

object IdoMysqlConnection "ido-mysql" {
user = "icinga_ido_db",
password = "rajesh123",
host = "127.0.0.1",
database = "icinga_ido_db"
}

Save the file, close it and enable the Icinga2-ido-mysql with the following command:

$ sudo icinga2 feature enable ido-mysql

After this restart the Icinga2 service:

$ systemctl restart icinga2

Step 5. Install and Setup IcingaWeb2

To install Icinga Web execute the following commands:

sudo apt install icingaweb2 icingacli -y

Next is to create a second database for the Icinga web:

$ mysql -u root -p

CREATE DATABASE icingaweb2;
GRANT ALL ON icingaweb2.* TO 'icingaweb2'@'localhost' IDENTIFIED BY 'rajesh123';
FLUSH PRIVILEGES;
EXIT;

Next, we need to create an Icinga token:

root@host:~# sudo icingacli setup token create
The newly generated setup token is: dd3a1a8b218be0db

That was all with installing Icinga via the command line. The last step is about finishing the Icinga installation.

Step 6. Finish Icinga Installation

To finish the Icinga installation, you need to access it at http://YourServerIPaddress/icingaweb2/setup.

Rajesh Kumar
Follow me
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x