Table des matières

Munin - Installation d'un outil d'analyse des ressources

CréationNicolas THOREZ 2020/02/21 14:23

munin collecte et analyse les ressources utilisées par les serveurs qu'il surveille. Dans le cadre du MCO, l'outil permet à l'administrateur de connaître l'état précis des ressources d'un serveur et leurs évolutions dans le temps.

Environnement

Cette procédure a été réalisée et testée sur une VM debian 10 (serveur et client) et une VM Windows 10 (client).

Droits

Cette procédure nécessite des droits root. Faîtes donc attention à ce que vous faîtes.

Prérequis

apt-get update

apt-get install -y apache2 libcgi-fast-perl libapache2-mod-fcgid libwww-perl

a2enmod fcgid

Installation du serveur

apt-get update

apt-get install -y munin

Configuration

nano /etc/munin/munin.conf

mkdir -p /var/www/munin

chown munin:munin /var/www/munin

cd /etc/apache2/conf-available/
ln -s /etc/munin/apache24.conf ./munin.conf

nano /etc/apache2/conf-available/munin.conf

# Munin configuration for apache2
#
# Apache can serve munin's files that are either statically generated
# (in a cron job) or generated on demand (via cgi).
# The relevant munin settings are "html_strategy" and "graph_strategy".
# The related apache settings can be adjusted at the end of this file.
#
# See /usr/share/doc/munin/README.Debian for details.


# ***** COMMON SETTINGS FOR ALL STRATEGIES *****

ScriptAlias /munin-cgi/munin-cgi-graph /usr/lib/munin/cgi/munin-cgi-graph
Alias /munin/static/ /var/www/munin/static/

<Directory /var/www/munin>
    Require all granted
    Options FollowSymLinks SymLinksIfOwnerMatch
</Directory>

<Directory /usr/lib/munin/cgi>
    Require all granted
    Options FollowSymLinks SymLinksIfOwnerMatch
    <IfModule mod_fcgid.c>
        SetHandler fcgid-script
    </IfModule>
    <IfModule !mod_fcgid.c>
        SetHandler cgi-script
    </IfModule>
</Directory>


# ***** SETTINGS FOR CGI/CRON STRATEGIES *****

# pick _one_ of the following lines depending on your "html_strategy"
# html_strategy: cron (default)
Alias /munin /var/www/munin
# html_strategy: cgi (requires the apache module "cgid" or "fcgid")
#ScriptAlias /munin /usr/lib/munin/cgi/munin-cgi-html

systemctl restart munin.service
systemctl restart munin-node.service
systemctl restart apache2.service

Installation

Félicitations, vous devriez désormais avoir accès à votre serveur munin via l'adresse http://ip_du_serveur_munin/munin.

Sécurisation

Dans le cas où munin devrait être accessible sur Internet et du fait des données sensibles qu'il présente, on peut rajouter une demande de mot de passe pour accéder au site. Pour cela :

# Munin configuration for apache2
#
# Apache can serve munin's files that are either statically generated
# (in a cron job) or generated on demand (via cgi).
# The relevant munin settings are "html_strategy" and "graph_strategy".
# The related apache settings can be adjusted at the end of this file.
#
# See /usr/share/doc/munin/README.Debian for details.


# ***** COMMON SETTINGS FOR ALL STRATEGIES *****

ScriptAlias /munin-cgi/munin-cgi-graph /usr/lib/munin/cgi/munin-cgi-graph
Alias /munin/static/ /var/www/munin/static/

<Directory /var/www/munin>
    AllowOverride all
    Require all granted
    Options FollowSymLinks SymLinksIfOwnerMatch
</Directory>

<Directory /usr/lib/munin/cgi>
    Require all granted
    Options FollowSymLinks SymLinksIfOwnerMatch
    <IfModule mod_fcgid.c>
        SetHandler fcgid-script
    </IfModule>
    <IfModule !mod_fcgid.c>
        SetHandler cgi-script
    </IfModule>
</Directory>


# ***** SETTINGS FOR CGI/CRON STRATEGIES *****

# pick _one_ of the following lines depending on your "html_strategy"
# html_strategy: cron (default)
Alias /munin /var/www/munin
# html_strategy: cgi (requires the apache module "cgid" or "fcgid")
#ScriptAlias /munin /usr/lib/munin/cgi/munin-cgi-html

nano /var/www/munin/.htaccess

AuthType Basic
AuthName "Members Only"
AuthUserFile /var/www/munin/htpasswd.users
<limit GET PUT POST>
   require valid-user
</limit>

chown www-data:www-data /var/www/munin/.htaccess
chmod 400 /var/www/munin/.htaccess

htpasswd -c /var/www/munin/htpasswd.users muninadmin

service apache2 restart

Sécurité

Voilà, l'accès à munin est désormais protégé par un mot de passe.

Installation d'un client sous Linux

apt-get update

apt-get install -y munin-node munin-plugins-extra

munin-node-configure --suggest

cd /etc/munin/plugins/
ln -s /usr/share/munin/plugins/acpi .

Astuce

Vous pouvez activer tous les modules conseillés avec la commande :
munin-node-configure --suggest --shell | sh

nano /etc/munin/munin-node.conf

allow ^192\.168\.20\.54$

service munin-node restart

cd /etc/munin/munin-conf.d

touch bdd.conf

nano bdd.conf

[srv-mysql.bdd]
  address 192.168.20.55
  use_node_name yes

systemctl restart apache2.service

Collecte de données

munin collecte les données toutes les 5 min par défaut. C'est le temps qu'il vous faudra attendre pour voir apparaître le nouveau client sur la page web.

Installation d'un client sous Windows

Add-WindowsCapability -Online -Name "SNMP.Client~~~~0.0.1.0"

Paramétrages

Si les onglets Agent, Interruptions et/ou Sécurité n'apparaissent pas, redémarrer le service, voire le client Windows.

apt update && apt install -y libnet-snmp-perl

Résolution de nom d'hôte

Si votre réseau n'a pas de serveur DNS (Workgroup par exemple), n'hésitez pas à mettre le nom du client dans le fichier /etc/hosts.

 munin-node-configure -snmp windows.shyrka.sys

Plugin                     | Used | Suggestions                            
------                     | ---- | -----------                            
snmp__cpuload              | no   | yes (+windows.shyrka.sys)              
snmp__df                   | no   | yes (+windows.shyrka.sys)              
snmp__df_ram               | no   | yes (+windows.shyrka.sys)              
snmp__fc_if_               | no   | no [[[ plugin has neither autoconf not suggest support ]]]
snmp__fc_if_err_           | no   | no [[[ plugin has neither autoconf not suggest support ]]]
snmp__if_                  | no   | yes (+windows.shyrka.sys/22 +windows.shyrka.sys/25)
snmp__if_err_              | no   | yes (+windows.shyrka.sys/22 +windows.shyrka.sys/25)
snmp__if_multi             | no   | yes (+windows.shyrka.sys)              
snmp__load                 | no   | no [[[ plugin has neither autoconf not suggest support ]]]
snmp__memory               | no   | yes (+windows.shyrka.sys)              
snmp__netapp_diskusage_    | no   | no [[[ plugin has neither autoconf not suggest support ]]]
snmp__netapp_inodeusage_   | no   | no [[[ plugin has neither autoconf not suggest support ]]]
snmp__netstat              | no   | yes (+windows.shyrka.sys)              
snmp__print_pages          | no   | no [[[ plugin has neither autoconf not suggest support ]]]
snmp__print_supplies       | no   | no [[[ plugin has neither autoconf not suggest support ]]]
snmp__processes            | no   | yes (+windows.shyrka.sys)              
snmp__rdp_users            | no   | yes (+windows.shyrka.sys)              
snmp__sensors_fsc_bx_fan   | no   | no [[[ plugin has neither autoconf not suggest support ]]]
snmp__sensors_fsc_bx_temp  | no   | no [[[ plugin has neither autoconf not suggest support ]]]
snmp__sensors_fsc_fan      | no   | no [[[ plugin has neither autoconf not suggest support ]]]
snmp__sensors_fsc_temp     | no   | no [[[ plugin has neither autoconf not suggest support ]]]
snmp__sensors_mbm_fan      | no   | no [[[ plugin has neither autoconf not suggest support ]]]
snmp__sensors_mbm_temp     | no   | no [[[ plugin has neither autoconf not suggest support ]]]
snmp__sensors_mbm_volt     | no   | no [[[ plugin has neither autoconf not suggest support ]]]
snmp__swap                 | no   | yes (+windows.shyrka.sys)              
snmp__uptime               | no   | yes (+windows.shyrka.sys)              
snmp__users                | no   | yes (+windows.shyrka.sys)              
snmp__winload              | no   | yes (+windows.shyrka.sys)              
snmp__winmem               | no   | yes (+windows.shyrka.sys)

ln -s /usr/share/munin/plugins/snmp__cpuload /etc/munin/plugins/snmp_windows.shyrka.sys_cpuload

ln -s /usr/share/munin/plugins/snmp__if_ /etc/munin/plugins/snmp_windows.shyrka.sys_if_22
ln -s /usr/share/munin/plugins/snmp__if_ /etc/munin/plugins/snmp_windows.shyrka.sys_if_25

[windows.shyrka.sys]
  address 127.0.0.1
  use_node_name no

service munin-node restart
service apache2 restart

Erreurs et Corrections

Failed to restart munin.service: Unit munin.service is masked.

ls -l /lib/systemd/system/munin.service

# Retour
lrwxrwxrwx 1 root root    9 mars   3  2017 munin.service -> /dev/null

rm -f /lib/systemd/system/munin.service

systemctl daemon-reload

systemctl status munin.service

# Retour correct :
● munin.service - LSB: Create /var/run/munin on boot
   Loaded: loaded (/etc/init.d/munin; generated; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:systemd-sysv-generator(8)

systemctl start munin.service
systemctl status munin.service

# Retour
● munin.service - LSB: Create /var/run/munin on boot
   Loaded: loaded (/etc/init.d/munin; generated; vendor preset: enabled)
   Active: active (exited) since Mon 2020-04-06 10:29:03 CEST; 6s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 6678 ExecStart=/etc/init.d/munin start (code=exited, status=0/SUCCESS)

avril 06 10:29:03 mlb-monitor-2 systemd[1]: Starting LSB: Create /var/run/munin on boot...
avril 06 10:29:03 mlb-monitor-2 systemd[1]: Started LSB: Create /var/run/munin on boot.