Installation d'Icinga sur une Debian Lenny

Ce billet va (tenter de) reprendre la procédure que j'ai lancé pour installer Icinga, un fork de Nagios, célèbre système de supervision de machines, et le tout en Français.

Cette installation comprend :

  • L'installation/configuration d'Icinga-core avec IDOUtils
  • L'installation des plugins Nagios
  • L'installation/configuration d'Icinga-web
  • L'installation/configuration d'Icinga-mobile

Après m'être pas mal battu avec la documentation anglaise, voici un petit tutoriel pour mettre en place une plateforme Icinga.

Nous partirons du postulat suivant :

  • Apache2 est installé et configuré sur le serveur sur lequel nous allons travailler
  • MySQL est également installé et vous avez des droits pour créer des bases de données et utilisateurs
  • Vous avez un peu de temps devant vous

Icinga-core

Installation

Tout d'abord, on vérifie que les paquets pré-requis sont installés :

root@> aptitude install git-core build-essential libgd2-xpm-dev
root@> aptitude install libjpeg62 libjpeg62-dev libpng12-0 libpng12-dev
root@> aptitude install libdbi0 libdbi0-dev libdbd-mysql

On crée le compte qui servira a faire tourner Icinga :

root@> /usr/sbin/useradd -m icinga
root@> passwd icinga

Une fois le mot de passe choisi (qu'on essaiera de retenir...) créez un groupe icinga-cmd et y inclure l'utilisateur qui fait tourner votre serveur Web (chez moi www-data):

root@> /usr/sbin/groupadd icinga-cmd
root@> /usr/sbin/usermod -a -G icinga-cmd icinga
root@> /usr/sbin/usermod -a -G icinga-cmd www-data

Ensuite, on prépare un espace pour compiler Icinga depuis les sources :

root@> mkdir /usr/src
root@> cd !$

Puis on récupère les dernières sources à partir du dépôt GIT d'Icinga :

root@> git clone git://git.icinga.org/icinga-core.git
root@> git submodule init
root@> git submodule update

On configure le tout :

root@> cd /usr/src/icinga-core/
root@> ./configure --with-command-group=icinga-cmd --enable-idoutils 

On compile :

root@> make all

Et on installe :

root@> make fullinstall

Configuration

Ouvrez le fichier /usr/local/icinga/etc/objects/contacts.cfg et changez les lignes :

root@> vi /usr/local/icinga/etc/objects/contacts.cfg

# email        votremail@domaine.tld

Allez ensuite créer et éditer la configuration pour IDOUtils :

root@> cd /usr/local/icinga/etc/
root@> cp idomod.cfg-sample idomod.cfg && chmod 644 idomod.cfg && chown icinga:icinga idomod.cfg
root@> cp ido2db.cfg-sample ido2db.cfg && chmod 644 ido2db.cfg && chown icinga:icinga ido2db.cfg

Ouvrez ensuite le fichier de configuration d'Icinga et décommentez la ligne suivante :

root@> vi /usr/local/icinga/etc/icinga.cfg

#broker_module=/usr/local/icinga/bin/idomod.o config_file=/usr/local/icinga/etc/idomod.cfg

Préparons maintenant les bases / tables / utilisateurs MySQL :

root@> mysql -u root -p
mysql> CREATE DATABASE icinga;
mysql> GRANT USAGE ON icinga.* TO 'icinga'@'localhost' IDENTIFIED BY 'un_mot_de_passe' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0;
mysql> GRANT SELECT , INSERT , UPDATE , DELETE ON icinga.* TO 'icinga'@'localhost';
mysql> FLUSH PRIVILEGES ;
mysql> \q
root@> cd /usr/src/icinga-core/module/idoutils/db/mysql
root@> mysql -u root -p icinga < mysql.sql

Une fois l'utilisateur créé avec un_mot_de_passe nous allons éditer le fichier de configuration IDOUtils précédemment copiés depuis les exemples et modifier les lignes indiquées :

root@> vi /usr/local/icinga/etc/ido2db.cfg
 db_servertype=mysql
 db_port=3306
 db_user=icinga
 db_pass=un_mot_de_passe

Plugins Nagios

Icinga fonctionne avec les plugins édités par Nagios. Ces fichiers peuvent être trouvés sur le site Nagios Plugins.

Téléchargez les dans /usr/src/. Une fois fait, nous allons les installer :

root@/usr/src/> tar -zxvf nagios-plugins-1.4.15.tar.gz 
root@/usr/src/> cd nagios-plugins-1.4.15
root@/usr/src/nagios-plugins-1.4.15/> ./configure --prefix=/usr/local/icinga --with-cgiurl=/icinga/cgi-bin --with-htmurl=/icinga --with-nagios-user=icinga --with-nagios-group=icinga
root@/usr/src/nagios-plugins-1.4.15/> make
root@/usr/src/nagios-plugins-1.4.15/> make install

Démarrez enfin Ido2db :

root@> /etc/init.d/ido2db start

Puis Icinga, après vérification des fichiers de configuration :

root@> /usr/local/icinga/bin/icinga -v /usr/local/icinga/etc/icinga.cfg
root@> /etc/init.d/icinga start

Icinga Web

Icinga propose une superbe interface Web pour consulter l'état de nos serveurs et services.

Tout d'abord, vérifions que nous avons tous les modules php nécessaires :

root@> aptitude install php5 php5-cli php-pear php5-xmlrpc 
root@> aptitude install php5-xsl php5-pdo php5-gd php5-ldap php5-mysql

Ensuite, il faut récupérer le dernière version de leur dépôt GIT :

root@> cd /usr/src/
root@/usr/src/> git clone git://git.icinga.org/icinga-web.git

Puis compiler et installer le tout :

root@/usr/src/> cd icinga-web
root@/usr/src/icinga-web/> ./configure \
                --prefix=/usr/local/icinga-web \
                --with-web-user=www-data \
                --with-web-group=www-data \
                --with-web-path=/icinga-web \
                --with-web-apache-path=/etc/apache2/conf.d \
                --with-db-type=mysql \
                --with-db-host=localhost \
                --with-db-port=3306 \
                --with-db-name=icinga \
                --with-db-user=icinga \
                --with-db-pass=un_mot_de_passe \
                --with-icinga-api=/usr/local/icinga/share/icinga-api \
                --with-api-type=CONNECTION_IDO \
                --with-api-subtype=mysql \
                --with-api-host=localhost \
                --with-api-port=3306 \
                --with-api-socket=
root@/usr/src/icinga-web/> make install
root@/usr/src/icinga-web/> make install-apache-config
root@/usr/src/icinga-web/> make install-javascript
root@/usr/src/icinga-web/> make install-done
root@/usr/src/icinga-web/> make testdeps

Si vous avez les magic_quotes_gpc actives, pensez à les désactiver :

root@> vi /etc/php5/apache/php.ini
   magic_quotes_gpc = off
   safe_mode = off
root@> /etc/php5/cli/php.ini
   magic_quotes_gpc = off

Initialisez la base de données pour un premier démarrage :

root@/usr/src/icinga-web/> make db-initialize

Vérifiez ensuite que la configuration est correcte. Dans le fichier /usr/local/icinga-web/app/config/databases.xml vous devriez avoir ceci vers le début du fichier :

<database name="icinga_web" class="AgaviDoctrineDatabase">
 
         <!--
                Doctrine dsn strings:
 
                http://www.doctrine-project.org/documentation/manual/1_1/en/introduction-to-connections
         -->
         <ae:parameter name="dsn">mysql://icinga:un_mot_de_passe@127.0.0.1:3306/icinga</ae:parameter>
 
         <!-- Generic credentials  -->
         <!-- <ae:parameter name="username">
icinga</ae:parameter> -->
         <!-- <ae:parameter name="password">
un_mot_de_passe</ae:parameter> -->
 
         <!-- DB encoding type -->
         <ae:parameter name="charset">utf8</ae:parameter>
 
         <!--
                 Doctrine_Manager configuration
         -->
         <ae:parameter name="manager_attributes">
                 <!-- This allows lazy loading of the models -->
                 <ae:parameter name="Doctrine_Core::ATTR_MODEL_LOADING">CONSERVATIVE</ae:parameter>
         </ae:parameter>
 
         <!-- The path to our models -->
         <ae:parameter name="load_models">%core.module_dir%/AppKit/lib/database/models/generated</ae:parameter>
         <ae:parameter name="models_directory">%core.module_dir%/AppKit/lib/database/models</ae:parameter>
 
</database>

Enfin, configurez le fichier de l'API Icinga /usr/local/isinga-web/app/modules/Web/config/icinga-io.xml pour qu'il ressemble à ceci :

<!--
        See doc/icinga-api-types.txt for options
-->
<setting name="api.interfaces.data">
        <!-- IcingaApi connection interface -->
        <ae:parameter name="api_type">IcingaApi::CONNECTION_IDO</ae:parameter>
 
        <!-- Suits for all interfaes -->
        <ae:parameter name="config_type">mysql</ae:parameter>
        <ae:parameter name="config_host">localhost</ae:parameter>
        <ae:parameter name="config_port">3306</ae:parameter>
 
        <!-- ###BEGIN_CONNECTION_IDO### -->
        <!-- Database specific (IcingaApi::CONNECTION_IDO) -->
        <ae:parameter name="config_database">icinga</ae:parameter>
        <ae:parameter name="config_user">icinga</ae:parameter>
        <ae:parameter name="config_password">un_mot_de_passe</ae:parameter>
        <ae:parameter name="config_table_prefix">icinga_</ae:parameter>
        <!-- ###END_CONNECTION_IDO### -->
 
</setting>

Redémarrez Apache et connectez-vous à votre Interface Web !

root@> /etc/init.d/apache2 restart

L'URL de votre interface est http://localhost/icinga-web/. Les identifiants de passe sont root / password. Ne tardez pas à les changer !

Icinga Mobile

Comme le reste des éléments Icinga, commencez par récupérer la dernière version de l'interface mobile Icinga :

root@> cd /usr/src/
root@/usr/src/> wget -O icinga-mobile-0.1.0.zip http://sourceforge.net/projects/icinga/files/icinga-mobile/0.1.0/icinga-mobile-0.1.0.zip/download
root@/usr/src/> unzip icinga-mobile-0.1.0.zip
root@/usr/src/> cp -a icinga-mobile-0.1.0 /usr/local/icinga-mobile

Editez le fichier /etc/apache2/conf.d/icinga-mobile.conf (créez-le s'il n'existe pas) et faites en sorte qu'il ressemble à ceci :

root@> vi /etc/apache2/conf.d/icinga-mobile.conf
#
# icinga-mobile apache configuration
# - Enable all options .htaccess
# - Add extjs library to alias
#

Alias /icinga-mobile/js/ext3 /usr/local/icinga-mobile/lib/ext3
Alias /icinga-mobile /usr/local/icinga-mobile

<Directory /usr/local/icinga-mobile/lib/ext3>
    Order allow,deny
    Allow from all
</Directory>

<Directory /usr/local/icinga-mobile>
    DirectoryIndex index.html
    Options FollowSymLinks
    AllowOverride all
    Order allow,deny
    Allow from all
</Directory>

Ouvrez ensuite le fichier de configuration /usr/local/icinga-mobile/lib/Model/IcingaConfiguration.js et modifiez les lignes suivantes :

var cfg_defaults = {
            'hasSetup' : 'true',
            'defaultViewTpl': 'pregnancyTest',
            'icinga_apikey' : 'ma_cle_API',
            'icinga_url' : 'http://votre.domaine.tld/icinga-web',
            'noStartup' : 'true'
        }

Vous noterez qu'il y a ici une clé que l'on va devoir renseigner et se souvenir.

Connectez-vous à votre interface web standard (http://votre.domaine.tld/icinga-web/) avec un compte admin, et créez un compte qui aura pour méthode d'authentification auth_key et qui, dans les droits principaux, aura le droit appkit.api.access comme présenté sur la capture suivante :

Redémarrez Apache :

root@> /etc/init.d/apache2 restart

Et connectez-vous à l'adresse : http://votre.domaine.tld/icinga-mobile/

Vous accèderez alors à la version Mobile de l'interface Web d'Icina !

Cas particulier

Il se peut que vous ayez installé votre serveur en sécurisant votre machine par le montage de /usr en lecture seule.

Pas de panique, il vous suffit de tout déplacer dans un autre point de montage (e.g /srv), et de créer des liens symboliques :

root@> /etc/init.d/icinga stop
root@> cp -a /usr/local/icinga* /srv
root@> rm -rf /usr/local/icinga
root@> ln -s /srv/icinga
root@> rm -rf /usr/local/icinga-web
root@> ln -s /srv/icinga-web
root@> rm -rf /usr/local/icinga-mobile
root@> ln -s /srv/icinga-mobile
root@> /etc/init.d/icinga start

Voilà, c'est tout !

Bonne utilisation !

Commentaires

1. Le mardi, novembre 2 2010, 17:49 par Sébastien Palma

Des corrections post-relecture ont été faites.

Logiquement tout est bon maintenant, il ne reste qu'à suivre !

Transcription en DocBook pour l'intégrer dans la doc officielle Icinga FR

2. Le vendredi, novembre 5 2010, 15:23 par tmmt

Intéressant tout ça !

Ajouter un commentaire

Le code HTML est affiché comme du texte et les adresses web sont automatiquement transformées.

Fil des commentaires de ce billet