Monday, December 21, 2015

CentOS 7 | Installation and setup of Icinga2 monitoring service - Part 2 - Setting up the Icinga Web 2 interface

This is part 2 of the tutorial where I'll be setting up the Icinga Web 2 web fronted from where we can log into our Icinga2 server and actually monitor our infrastructure.

If you came here from Google than you can find Part 1 here.




Step 1 - Aditional preparations of our server


Install the IDO modules for MySQL:
# yum -y install icinga2-ido-mysql


Prepare the database:
# mysql -u root -p
[ENTER-YOUR-MYSQL-ROOT-PASSWORD]
CREATE DATABASE icinga;
GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON icinga.* TO 'icinga'@'localhost' IDENTIFIED BY 'icinga';

Hit CTRL+C to exit the mysql> prompt.

Import the Icinga2 IDO schema:
# mysql -u root -p icinga < /usr/share/icinga2-ido-mysql/schema/mysql.sql


To enable the IDO MySQL module you will have to update its configuration file:
# vim /etc/icinga2/features-available/ido-mysql.conf

Update that file to looks like this:

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

library "db_ido_mysql"

object IdoMysqlConnection "ido-mysql" {

  user = "icinga"
  password = "icinga"
  host = "localhost"
  database = "icinga"
  port = 3306
  table_prefix = "icinga_"
  instance_name = "icinga2"
  instance_description = "icinga2 instance"

}


In the end enable the ido-mysql feature:
# icinga2 feature enable ido-mysql


Enable the external command pipe so the web interfaces are able to send commands to Icinga2:
# icinga2 feature enable command

Restart Icinga2:
# systemctl restart icinga2


Finaly you will want to add the apache user to the icingacmd group because the command pipe file is owned by that group:
# usermod -a -G icingacmd apache


Verify the apache user:
# id apache
uid=48(apache) gid=48(apache) groups=48(apache),992(icingacmd)

The output should look like mine.




Step 2: Install Icinga Web 2 web interface


You can use the official documentation from Github or use my tutorial as they are pretty much the same.

If everything has been set up corectly so far (that is if you've used this guide 100%) than you can install Icingaweb2 right away using yum:
# yum -y install icingaweb2 icingacli


The rest of the setup is from the web interface. First we have to generate a setup token:
# icingacli setup token create
The newly generated setup token is: 6026d7efb8ae6df2

Note: Your token will be different than mine.

Restart your Apache server
# systemctl restart httpd

Paste your key somewhere safe and then proceed to the web interface using your server IP address. My IP address is 192.168.10.25
http://192.168.10.25/icingaweb2/setup

... and use your token to begin the setup.


Step 3: Setup Icingaweb2


After you will paste your token and click next you will notice a section with checklists. Make sure everything here is green. If it is yellow or red than you have to fix it before proceeding further. So far for me only the PHP default timezone was missing so I decided to update the /etc/php.ini file. If you have followed my guide all the way probably your's will be to so go on and update the file with your correct time zone. Mine is Europe/Paris. For a list of available timezone consult with the PHP Documentation: http://php.net/manual/en/timezones.php.

Find your timezone and than edit the PHP config file:
# vim /etc/php.ini

Find this section:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
; date.timezone = 

... change it to:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Europe/Paris"

Remember to put the parentheses around the timezone otherwise you will brake the PHP interpreter. Save and exit the vi editor and than restart the httpd service.

If everything is green that you may proceed with the setup. First let's create the database and the user which the web application will use to store it's configuration:

# mysql -u root -p
[ENTER-YOUR-MYSQL-ROOT-PASSWORD]

MariaDB [(none)]> CREATE DATABASE icingaweb_db;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON icingaweb_db.* TO 'icingaweb_db'@'localhost' IDENTIFIED BY 'icingaweb_db';
Query OK, 0 rows affected (0.00 sec)


Click next on the web setup to the Authentication page:

Authentication type: DATABASE

Click next, the Database Resource page will be displayed. Fill the fields with the parameters we have created before:




Click next, on the database setup page you will be asked for credentials. Put your database root username and password here.

Click next. On the authentication back-end page select a name for this authentication backend. I've named mine icingaweb2_db. The trick here is that later you may decide that you will want to use an Active Directory authentication backend and authenticate your users against an LDAP database so you will name that one for example, icingaweb2_ad and so on.

Click next, on the administration page create your first username account with administrative privileges. I've named mine admin. Put a password of your choice.

Click next and on the application configuration verify the settings and click next.

On the last verification page review your settings.

The next page will configuration of the monitoring module for Icinga Web 2. We installed IDO module for our purpose and that is the only option to choose for now.

On the Monitoring IDO Resource enter the IDO settings from before:

These are the settings that we've created previously:



Click next on all of the rest of the pages. In the end you should be presented with the congratulations page.



Now login to Icinga Web 2 and you are good to go!


Final notes:

If on the end when you log in you are presented with an error:
Page not found. Enabling the "setup" module might help!

Then just log out, then log in again. Go to Configuration -> Modules; click on the Setup module and enable it.

Enjoy your new Icinga2 server and happy monitoring.

Up next: Adding various hosts to the Icinga2 service for monitoring.



Resources used to put this stuff all-together:


Icinga2 documentation:
http://docs.icinga.org/icinga2/latest/doc/module/icinga2/toc


Icingaweb2 Github documentation:
https://github.com/Icinga/icingaweb2/blob/master/doc/installation.md


17 comments:

  1. Thanks Tom, Appreciate your efforts and detailed step-by-step part 1 and 2 post.
    Cheers

    ReplyDelete
  2. Great tutorial dude, many thanks it helped me where other 2 failed.
    Thank you very much.
    Cheers,
    Cristi

    ReplyDelete
  3. Hi,

    I am able to bring up the icinga web portal. But I'm seeing below issue.
    "/etc/icingaweb2", if not explicitly set in the environment variable "ICINGAWEB_CONFIGDIR".
    The directory /etc/icingaweb2 is not writable. Can you please help me

    ReplyDelete
    Replies
    1. It seems that you have permissions issue with the mentioned directory.
      Can you try and give it a write permissions.

      # cd /etc/
      # chmod +w icingaweb2

      Delete
  4. Thanks for your reply actually I gave permission before but forgot to restart httpd and icinga. After restart everything looks good. Thanks Again. Your blog is excellent and very helpful.

    ReplyDelete
  5. Hi, I am seeing one more issue on the final of configuration. Can you please help me. Below is the error.

    Authentication configuration has been successfully written to: /etc/icingaweb2/authentication.ini
    Unable to create account "icinga". An error occured:
    ERROR: Zend_Db_Adapter_Exception in /usr/share/php/Zend/Db/Adapter/Pdo/Abstract.php:144 with message: SQLSTATE[28000] [1045] Access denied for user 'icingaweb_db'@'localhost' (using password: YES)
    Account "icinga" has been successfully defined as initial administrator.

    User Group Backend configuration has been successfully written to: /etc/icingaweb2/groups.ini
    Unable to create user group "Administrators". An error occured:
    ERROR: Zend_Db_Adapter_Exception in /usr/share/php/Zend/Db/Adapter/Pdo/Abstract.php:144 with message: SQLSTATE[28000] [1045] Access denied for user 'icingaweb_db'@'localhost' (using password: YES)

    ReplyDelete
  6. Remember to put the parentheses around the timezone otherwise you will brake the PHP interpreter. Save and exit the vi editor and than restart the httpd service.
    Should be:
    Remember to put the quotation marks around the timezone otherwise you will break the PHP interpreter. Save and exit the vi editor and than restart the httpd service.

    ReplyDelete
  7. Hi...
    Great tutorial and i did it. My server now running. Btw, how could i monitoring router (mikrotik) and switches?

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. would you mind to make a post about intsalling Graphite inside Icingaweb2 ?

    ReplyDelete
  10. That was a great work! It helped me a lot. Thank you very much.

    ReplyDelete
  11. Hi Tom,

    Its nice explanation, Thanks.if you explain the How to add the Server Host & other Host also.....

    ReplyDelete
  12. Awesome tutorial!
    It greatly help me setup icinga on host servers but I am having hard time with configuring for services/processes.
    I am trying to setup sql_slow_query and other server apps.
    I need a little push or point me to where I can get so help. I been looking but having no luck.
    Thank you so much!

    ReplyDelete
  13. nice this blog.
    You put really very helpful information. Keep it up. Keep blogging. I’m looking to reading your next post.

    โกเด้นสล็อต

    ReplyDelete