Nagios has, for a long time, been the defacto standard tool for server monitoring. These day that’s surprising, as Nagios’ visible development has been quite slow over the past years and new solutions have popped up meanwhile. Not just self-hosted solutions, but cloud-based solutions with fancy metrics voodoo as well.

Still, though, switching monitoring solutions can be a pain and cloud-based solutions arguably cost more than a self-hosted solution. So, say you want to switch from Nagios or you want to start with server monitoring, there is a solution. Icinga2!

Icinga started as a Nagios fork and did quite well, mostly considering Icinga Web which was better than Nagios’ web interface. Icinga 2 is a complete rewrite and even adds a fancy new (optional) web interface which is responsive and customizable. On top of that, the communication between the monitoring server and the nodes it monitors has become more secure as NRPE has been ditched (it’s still available, just not prefered).

I’m going to show you how to set up an Icinga 2 server with Icinga Web 2. In two weeks, I’ll let you know how to add nodes to it as well. Let’s get to business!

As usual, I’m assuming an Ubuntu (or other Debian-based) host that’s up-to-date. These instructions work for Ubuntu versions 14.04 and up. You don’t need a lot of resources for this, though depending on how many nodes you’re going to monitor. A server with 256MB RAM should be sufficient for up to 100 nodes considering you’ll also install Icinga Web 2 on it.

Icinga 2

Anyway, let’s get started. To install Icinga 2, you first need to add the repository. On Ubuntu, this is done like this:

add-apt-repository ppa:formorer/icinga

Press ENTER when it asks you to.

Note: If this command gives you an error, run ‘sudo apt-get install software-properties-common’ to get the ‘add-apt-repository’ command!

Once the repository has been added, update apt:

sudo apt-get update

And install Icinga 2:

sudo apt-get install icinga2

That’s it! Make sure Icinga 2 is running:

sudo service icinga2 status

And start it if it isn’t running:

sudo service icinga2 start

With that settled, let’s go to the installation of Icinga Web 2.

Icinga Web 2

I’m going to use PostgreSQL with Icinga Web 2 as it seems to be easier on resources than recent versions of MySQL. The database is used for the web interface, among other things, so it’s going to be a key part of the system.

Install PostgreSQL by running the following command:

sudo apt-get install postgresql

Next, install the package Icinga 2 requires to work with PostgreSQL:

sudo apt-get install icinga2-ido-pgsql

You should be asked a question now: whether you’d like to enable PostgreSQL for Icinga 2. Select ‘Yes’ here and hit ENTER.

Next you’ll be asked if you want the installer to configure the database for you. Again, select ‘Yes’ and hit ENTER.

Finally, you’ll be asked for a database password. Leave this empty and hit ENTER; a password will be generated for you.

With the database being set up, you can enable it for Icinga 2:

sudo icinga2 feature enable ido-pgsql

You’ll also want to enable the external command module, since you’ll need it later on:

sudo icinga2 feature enable command

In order to activate these changes, you need to restart Icinga 2:

sudo service icinga2 restart

You should get no errors for the restart. Icinga 2 is now taking to PostgreSQL and we can continue with our installation of Icinga Web 2.

It’s possible to manually install Icinga Web 2 or do it automatically. I’m taking the easy route and will should you how to install the package and go on from there. With this automatic installation comes Apache 2 as a web server. If you don’t like that, please see here on how to set up Icinga Web 2 manually: https://github.com/Icinga/icingaweb2/blob/master/doc/installation.md

First, add the repository key for the repository that contains Icinga Web 2 (it’s not in the PPA mentioned before):

sudo wget -O – http://packages.icinga.org/icinga.key | apt-key add –

This will ensure packages’ signature are considered valid. Next, add the repository:

sudo add-apt-repository ‘deb http://packages.icinga.org/ubuntu icinga-trusty main’

I’m using Ubuntu 14.04 (Trusty). In case you’re using a newer version, replace ‘trusty’ with the name of your distribution.

Update APT caches to make sure the package can be found:

sudo apt-get update

And install Icinga Web 2:

sudo apt-get install icingaweb2

When the installer is done, you should be able to go to your server’s hostname or IP address and add ‘/icingaweb2/setup’ to it and you’ll be met with the setup script for Icinga Web 2:

This asks for a setup token, so make sure you run the server this installation of Icinga Web 2 runs on. Go back to your terminal and run:

sudo icingacli setup token create

This should give you a token. Copy that and put that in the Setup Token field in your browser.

Next, you’re asked which modules to enable:

Just click ‘Next’.

This is where the problems start. For some amazing reason, the installer couldn’t fix some simple things for you, so you’ll have to do that yourself.

I’ve limited the size of the screenshot for convenience. Rest assured, the error and warnings will be there :-)

First of all, open up /etc/php5/apache2/php.ini and look for the following line:

;date.timezone =

Change that into this:

date.timezone = “America/New_York”

Feel free to replace ‘America/New_York’ with your time zone. Please use this list to see which time zones are allowed: http://php.net/manual/en/timezones.php

This should have fixed the ‘Red’ error message. To apply these changes, you need to restart Apache 2, but we’ll do that after the next step.

On to the warnings then. To fix those, install some packages:

sudo apt-get install php5-json php5-gd php5-imagick php5-pgsql php5-intl

Now restart Apache 2:

sudo service apache2 restart

And hit the ‘Refresh’ button at the bottom of the page in your browser. This should give you a nice green list and allow you to click ‘Next’. Do so.

It asks you to select an authentication type:

Select ‘Database’ and hit ‘Next’.

It asks you where you want to store user preferences:

Again, select ‘Database’ and hit ‘Next’.

This will give you the database configuration screen:

Select ‘PostgreSQL’ as the ‘Database Type’, change the ‘Host’ to ‘127.0.0.1’ and change the ‘Port’ to ‘5432’.

Fill out a database name, a username, and a strong password and hit ‘Next’. Remember these details; you may need them later.

At the next screen, just hit ‘Next’: the backend name it has picked should be good.

The creation of the initial administration account is up next:

Fill out these details as you with and hit ‘Next’.

You are presented with some configuration options. You shouldn’t have to change these, so click ‘Next’.

You’ll now get a message that the database details you filled out before are not working. This is logical, because we didn’t create the role and the database yet. From the command line, run these commands:

cd /tmp

sudo -u postgres psql -c “CREATE ROLE < username > WITH LOGIN PASSWORD ‘< password >'”;

sudo -u postgres createdb -O < username > < database name >

This moves you to the /tmp directory so PostgreSQL has rights to write a temporary file. Then it created the role (or user). Please replace the tokens with their appropriate values. Next, it created a database that is owned by the role you just created.

Now, move back to the browser and hit ‘Next’. You’ll now get an overview of what’s about to be written to the database:

Hit ‘Next’ to apply these changes.

But wait, there’s more…! Another module to configure:

What we just configured was Icinga Web 2; now it’s time to configure the connection with Icinga 2. Hit ‘Next’.

Accept the default values at this screen as they shouldn’t require any changes, then hit ‘Next’.

This next screen is where it gets interesting:

You’ll now need some details that you need to look up, but first set the ‘Database Type’ to PostgreSQL, the ‘Host’ to ‘127.0.0.1’, and the ‘Port’ to ‘5432’.

Next, in your terminal, open the following file: /etc/icinga2/features-enabled/ido-pgsql.conf

In here you’ll find the database name, username, and password you’ll need. Please copy-and-paste these to your browser and hit ‘Next’.

Accept the default values and hit ‘Next’.

Once more, accept the default values and hit ‘Next’.

And finally, you are presented with the overview of this configuration as well:

Click ‘Finish’ to make sure all of what just has been prepared becomes reality. The next screen should thus give you good news and a button to log in to your Icinga Web 2 installation! Please do so, and be amazed:

IT’S WORKING!

You’ve worked hard, so enjoy your new (and for the next two weeks completely useless) installation and grab a beer. That’s all for today!

Final notes

Of course the installation isn’t completely useless, because it monitors itself. This kind of supersedes the purpose, but at least you can look at the fancy statistics. Or you could try and add some hosts yourself. But if you want to be sure of what steps are next, come back here in two weeks for part 2!

Thanks for reading!





1 shares