Installing Icinga-2 Monitoring Tool on Ubuntu

In this tutorial, we will install an open source monitoring system ICINGA2, on ubuntu 14.04. Firstly we will configure some basic configuration to monitor network and services of host resources via the web interface.
We would be needing one server and no. of clients that we want to monitor. Here we are using Icinga version 2.x. Icinga Monitoring tool is completely plug-in based.

Why this tutorial?

I know there are some official tutorials available for its installation, but here are some tweaks which will make your work easier.

So lets begin.

Step 1: Add the Icinga repository and install icinga2.

# add-apt-repository ppa:formorer/icinga
# apt-get update
# apt-get install icinga2
Step 2: Install MySQL and client.
# apt-get install mysql-server mysql-client
Step 3: Install icinga database.
# apt-get install icinga2-ido-mysql
Step 4: Login in MySQL and create a database for storing data.
CREATE DATABASE icinga;
GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON icinga.* TO 'icinga'@'localhost' IDENTIFIED BY 'icinga';
quit 
Step 5: Enable livestatus feature and restart Icinga deamon.
# icinga2 feature enable livestatus
# service icinga2 restart
Step 6: Add user to the group for permissions.
# usermod -a -G nagios www-data
Step 7: Enable compat log and database feature and restart Icinga.
# icinga2 feature enable compatlog
# icinga2 feature enable ido-mysql
# icinga2 feature enable command
# service icinga2 restart

“Installation of Icinga is complete now we have to install web interface of Icinga.”

Step 1: Clone Icinga web repository from Github.
# git clone git://git.icinga.org/icingaweb2.git
Step 2: Move cloned directory to /usr/share/icingaweb and navigate to it.
# mv icingaweb2 /usr/share/icingaweb
# cd /usr/share/icingaweb
Step 3: Install lamp server
# tasksel install lamp-server
Step 4: Configure apache, run the following command and copy paste the generated output in sites-enabled.
# ./bin/icingacli setup config webserver apache --document-root /usr/share/icingaweb/public
# service apache2 restart
# a2enmod rewrite
# service apache2 restart
Step 5: Create a directory in which icinga web will keep all of its authentication files
# mkdir /etc/icingaweb2
Step 6: Change its permission to 777
 # chmod 777 -R /etc/icingaweb2
Step 7: Open your browser and navigate to localhost/icingaweb2/setup.
It will ask for setup token, you can  generate it by running the following command on the terminal.
su www-data --shell=/bin/bash -c "mkdir -m 2770 /etc/icingaweb2; head -c 12 /dev/urandom | base64 | tee /etc/icingaweb2/setup.token; chmod 0660 /etc/icingaweb2/setup.token;";
In next screen it will be asking to resolve some problems like, time zone and some php dependencies, change time zone to “Asia/Kolkata” in /etc/php5/apache2/php.ini file 
Step 8: Resolve php dependencies.
# apt-get install php5-ldap
# service apache2 restart
# apt-get install php5-intl
# apt-get install php5-gd php5-imagick
# service apache2 restart 
“Congratulations! You have successfully setup Icinga2 on your system.”
Now our main task is to check services running on our remote host(client), for that we can download require plugin from 
Download the require plugin and store it in /usr/lib/nagios/plugins.
Add execute permission to it
# chmod +x /var//lib/nagios/plugins/<filemame>
For using particular plugin, you have define its command in /etc/icinga2/conf.d/commands.conf
object CheckCommand "<identification name>"{
        import "plugin-check-command"
        command = [ PluginDir + "/<file name stored in plugin directory>" ]
        arguments = {
                /*define all require arguments*/
                "-H" = "$address$"
            }
    }
Configuring /etc/icinga2/conf.d/services.conf  for using it for the host you want to monitor.
apply Service "<name you want to display for this service on interface>" {
  import "generic-service"
  check_command = "identification name"
  assign where host.name == "icinga-3"
}
Now we have to define our host named icinga-3 in /etc/icinga2/conf.d/host.conf
object Host "icinga-3" {
        import "generic-host"
        address = "address of host"
}
Open your web browser and navigate to Icinga web interface and you can see the monitoring data on the interface 😉
Advertisements