Install Icinga2 on Ubuntu 16.04: Difference between revisions

From ICO wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 113: Line 113:
===Create IDO database===
===Create IDO database===
Create the main database for Icinga.
Create the main database for Icinga.
make sure you are in the /tmp directory (default unix socket location for PostgreSQL).
Make sure you are in the /tmp directory (default unix socket location for PostgreSQL).


<code>$ cd /tmp</code>
<code>$ cd /tmp</code>
Line 134: Line 134:
   password = "icingaidopass",
   password = "icingaidopass",
   host = "localhost",
   host = "localhost",
   database = "icinga"
   database = "icingaidodb"
}
}
</pre>
</pre>


===Create IDO database===
===Configuration databases authentication===
PostgreSQL handles authentication to databases from a file which states which users can connect to which database using certain methods.
Previously we have created a roles and databases. We must tell PostgreSQL how these databases can be accessed and by whom.
 
Edit the pg_hba.conf in ''/etc/postgresql/*/main/pg_hba.conf'' and add the roles and databases we defined earlier user with md5 authentication method.
'md5' means that the user needs to authenticate with a password to access the database.
 
<pre>
# TYPE  DATABASE        USER          ADDRESS              METHOD
#icinga
local  icingaidodb      icingaido                            md5
host    icingaidodb      icingaido      127.0.0.1/32          md5
host    icingaidodb      icingaido      ::1/128              md5
 
local  icingawebdb      icingaweb                            md5
host    icingawebdb      icingaweb      127.0.0.1/32          md5
host    icingawebdb      icingaweb      ::1/128              md5
</pre>

Revision as of 12:16, 12 November 2016

Author: Etienne Barrier

Last modified: 11.11.2016

Background

This tutorial shows how to install Icinga 2 on Ubuntu 16.04 LTS, using PostgreSQL (as for database) and Apache 2 (as for webserver).

This tutorial does NOT show: - how to install Icinga version 1 - how to install/configure databses other than PostgreSQP (for example MySQL, MariaDB, etc.) - how to install/configure webservers other than Apache2 (for example Nginx) - how to use Icinga2

It is assumed that you are already familiar with the basics of Linux command line terminal commands. But this tutorial is made so that you can copy paste the commands to your terminal.

Versions used in this tutorial: - Icinga 2 (version: r2.5.4-1) - Ubuntu 16.04.1 LTS (Xenial) - PostgreSQL (version: 9.5.2) - Apache 2 (version: 2.4.18) - Php (version 7.0)

Depending on the versions you use, the commands and/or the path shown in this tutorial might be different.

The version of Icinga used (version 2) is referred sometimes as “Icinga” or “Icinga 2” accross the tutorial.

This tutorial is based on the following tutorials: Official Icinga documentation [1] [2]

For any comments, please write to etienne(dot}barrier{at]itcollege[dot)ee.


What is Icinga?


Icinga is made of two parts - Icinga 2 and Icinga Web 2. The first one is the core of the software and the second is a web interface.

Install Icinga 2 core

Add Icinga's repository to the package management configuration.

$ add-apt-repository ppa:formorer/icinga $ apt update

Install Icinga 2 package.

$ apt install icinga2

Once done, check that Icinga is up and running

$ service icinga2 status

If it is not running, start it.

$ service icinga2 start

Make sure Icinga will start automatically on startup.

$ systemctl enable icinga2.service

Install plugins

Nagios plugins

To be able to check external services, Icinga needs monitoring plugins to know about them and to make sure they work properly. Available monitoring plugins are available on the Monitoring Plugins Project website. We install the main set of plugins that come from Nagios monitoring solution. Note that Icinga service runs as user and group called "Nagios" (for historical reasons).

$ apt install nagios-plugins

Vim and Nano configuration syntax highlighting

Icinga provides packages to highlight its configuration files using Nano and Vim utilities. The package for Nano is included by default when installinIcinga2. For Vim, do:

$ apt install vim-icinga2 vim-addon-manager $ vim-addon-manager -w install icinga2

Install and configure PostgreSQL databases

Icinga needs two databases to work: one main to store monitoring information (DB IDO: Database Icinga Data Output) and one to store Icinga users and groups information for its web interface. We will install both of them manually.

Install PostgreSQL

Install PostgreSQL database system.

$ apt install postgresql

Install IDO module for PostgreSQL

Install Icinga IDO module for PostgreSQL. It installs files and directories to enable the export and storage of monitoring information into a database. We will install the database manually in our tutorial.

$ apt install icinga2-ido-pgsql

A wizard will start. Say "No" to enable the IDO module for PostgreSQL, we do it manually later. The wizard proposes us to create and configure the database for us. Choose “No” because we will do it manually (see below).

Create Icinga users database

Create the users database for Icinga. First go to the /tmp directory because that is the default unix socket location for PostgreSQL.

$ cd /tmp

Create a role (similar to a user) for the database. The database will require to login and we choose a password. You can choose a different role name ("icingaweb") and a different password ("icingawebpass") than what is given as an example below. Remember them for later! $ sudo -u postgres psql -c "CREATE ROLE icingaweb WITH LOGIN PASSWORD 'icingawebpass'"

Create the database (“icingawebdb”) and we assign its owner as being “icingaweb” (created earlier) with UTF8 encoding. $ sudo -u postgres createdb -O icingaweb -E UTF8 icingawebdb

Import the web database schema to the newly created database. This will populate the web database with tables and indexes,...

$ psql -U icingaweb -d icingawebdb < /usr/share/icingaweb2/etc/schema/pgsql.schema.sql You should see a list of statements such as “CREATE TABLE”, “CREATE INDEX” ...

Create IDO database

Create the main database for Icinga. Make sure you are in the /tmp directory (default unix socket location for PostgreSQL).

$ cd /tmp

Create a role (similar to a user) for the database. The database will require to login and we choose a password. You can choose a different role name ("icingaido") and a different password ("icingaidopass") than what is given as an example below. Remember them for later! $ sudo -u postgres psql -c "CREATE ROLE icingaido WITH LOGIN PASSWORD 'icingaidopass'"

Create the database (“icingaidodb”) and we assign its owner as being “icingaido” (created earlier) with UTF8 encoding. $ sudo -u postgres createdb -O icingaido -E UTF8 icingaidodb

Import the IDO database schema to the newly created IDO database. This will populate the IDO database with tables, indexes,...

$ psql -U icingaido -d icingaidodb < /usr/share/icinga2-ido-pgsql/schema/pgsql.sql You should see a long list of statements such as “CREATE FUNCTION”, “CREATE TABLE”, “CREATE INDEX” ...

Edit the file /etc/icinga2/features-enabled/ido-mysql.conf and insert the values you have chosen for the IDO database.

object IdoMysqlConnection "ido-mysql" {
  user = "icingaido",
  password = "icingaidopass",
  host = "localhost",
  database = "icingaidodb"
}

Configuration databases authentication

PostgreSQL handles authentication to databases from a file which states which users can connect to which database using certain methods. Previously we have created a roles and databases. We must tell PostgreSQL how these databases can be accessed and by whom.

Edit the pg_hba.conf in /etc/postgresql/*/main/pg_hba.conf and add the roles and databases we defined earlier user with md5 authentication method. 'md5' means that the user needs to authenticate with a password to access the database.

# TYPE  DATABASE         USER           ADDRESS               METHOD
#icinga
local   icingaidodb      icingaido                            md5
host    icingaidodb      icingaido      127.0.0.1/32          md5
host    icingaidodb      icingaido      ::1/128               md5

local   icingawebdb      icingaweb                            md5
host    icingawebdb      icingaweb      127.0.0.1/32          md5
host    icingawebdb      icingaweb      ::1/128               md5