Monitoring : monit, munin (Serveur Web sur Debian Lenny)
par Nyro, Mardi 24 Mars 2009 à 14:14:38 :: Serveur
UPDATE : voir la version à jour pour Debian Squeeze pour l'installation de Munin.
UPDATE : voir la version à jour pour Debian Squeeze pour l'installation de Monit.
Notre serveur fonctionne bien, avec quelques bans pour différents services. Mais qu'arrive-t-il si un démon tombe en panne ? Et puis comment connait-on la charge du serveur ?
Monit va répondre à la première question en vérifiant à intervalle régulier tous les services et les redémarrer si besoin.
Munin quant à lui va créer de nombreux graphes sur le serveur pour que vous puissiez vous rendre compte de la charge qu'il encaisse.
Munin
Commençons par activer le server-status d'apache, quis era utilisé par munin pour calculé des stats de processus et requêtes d'apache. Ajouter le fichier /etc/apache2/conf.d/server-status.conf :
ExtendedStatus On
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Puis on peut passé à l'installation (les différents paquets perl sont utilisé par munin) :
apt-get install munin munin-node libhtml-parser-perl libhtml-tagset-perl libhtml-tree-perl liburi-perl libwww-perl
On ajoute quelques plugins à munin qui ne le sont pas par défaut, en appliquant les bons droits :
ln -s /usr/share/munin/plugins/netstat /etc/munin/plugins/netstat
ln -s /usr/share/munin/plugins/postfix_mailstats /etc/munin/plugins/postfix_mailstats
ln -s /usr/share/munin/plugins/apache_accesses /etc/munin/plugins/apache_accesses
ln -s /usr/share/munin/plugins/apache_processes /etc/munin/plugins/apache_processes
ln -s /usr/share/munin/plugins/apache_volume /etc/munin/plugins/apache_volume
ln -s /usr/share/munin/plugins/uptime /etc/munin/plugins/uptime
chown munin:munin /home/var/www/munin
Avec Lenny, le plugin netstat de munin à un problème de droit. Pour le résoudre, on le paramètre pour qu'il s'éxécute en root avec :
echo "[netstat]" > /etc/munin/plugin-conf.d/netstat
echo "user root" >> /etc/munin/plugin-conf.d/netstat
Avec la configuration actuelle, munin place ces fichiers dans /home/var/www/munin. Avec notre configuration actuelle d'apache, on ne pourrait pas y accéder.
Pour plus de simplicité, on va créer un sous-domaine en accès sécurisé pour voir ses stats. On commence par créer le certificat :
openssl req -new -x509 -days 3650 -nodes -out /etc/ssl/certs/munin.crt -keyout /etc/ssl/private/munin.key
On crée ensuite le .htpasswd pour le protéger :
htpasswd -c /home/var/www/munin/.htpasswd user
Puis on configure apache pour ce sous-domaine dans /etc/apache/sites-available/munin.domain.tld :
ServerName munin.domain.tld
# Activation du support SSL
GnuTLSEnable on
GnuTLSPriorities NORMAL
GnuTLSCertificateFile /etc/ssl/certs/munin.crt
GnuTLSKeyFile /etc/ssl/private/munin.key
AuthUserFile /home/var/www/munin/.htpasswd
AuthGroupFile /dev/null
AuthName "Restricted Area"
AuthType Basic
require valid-user
DocumentRoot /home/var/www/munin
ErrorLog /var/log/apache2/munin_error.log
CustomLog /var/log/apache2/munin_access.log combined
On active ce site pour apache, et on redémarre les services :
a2ensite munin.domain.tld
/etc/init.d/munin-node force-reload
/etc/init.d/apache2 force-reload
Monit
Monit va nous permettre de vérifier l'état des démons et d'effectuer les opérations nécessaires à son bon fonctionnement, tout en alertant l'administrateur. Dans la plupart des cas, un simple redémarrage sera effectué et tout ira bien.
On l'installe simplement :
apt-get install monit
On conserve la configuration par défaut :
mv /etc/monit/monitrc /etc/monit/monitrc_default
Pui on configure dans /etc/monit/monitrc :
set daemon 600
set logfile syslog facility log_daemon
set mailserver localhost
set mail-format {
from: me@domain.tld
subject: [monit] $SERVICE: $EVENT
}
set eventqueue basedir /home/var/monit slots 100
set alert server@domain.tld
set httpd port 9999 and
allow user:pass
include /etc/monit/conf.d/*
On le configure avec une interface web accessible sur le port 9999 avec comme nom d'utilisateur user et mot de passe pass. S'il s'avère que l'envoi de mail échoue, monit conservera les messages dans /home/var/monit pour les renvoyer dès que possible. La fréquence des tests est toutes les 10 minutes.
Puis, nous allons devoir configurer chacun des démons que l'on veut monitorer. La plupart du temps il s'agira d'un pid et des commandes de démarrage et d'arrêt du démon. Si le pid change entre 2 tests, monit enverra simplement un email.
mkdir /etc/monit/conf.d
Dans /etc/monit/conf.d/apache :
check process apache with pidfile /var/run/apache2.pid
group www
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if cpu > 60% for 2 cycles then alert
if cpu > 90% for 5 cycles then restart
if totalmem > 500 MB for 5 cycles then restart
if children > 250 then restart
if loadavg(5min) greater than 10 for 8 cycles then stop
if 3 restarts within 5 cycles then timeout
Le fichier de config le plus compliqué, il permet de redémarrer apache s'il prend trop de place en mémoire ou s'il a trop de processus enfant.
Dans /etc/monit/conf.d/clamav :
check process clamav with pidfile /var/run/clamav/clamd.pid
group virus
start program = "/etc/init.d/clamav-daemon start"
stop program = "/etc/init.d/clamav-daemon stop"
if failed host localhost port 3310 then restart
if 5 restarts within 5 cycles then timeout
check process freshclam with pidfile /var/run/clamav/freshclam.pid
group virus
start program = "/etc/init.d/clamav-freshclam start"
stop program = "/etc/init.d/clamav-freshclam stop"
if 5 restarts within 5 cycles then timeout
Dans /etc/monit/conf.d/cron :
check process cron with pidfile /var/run/crond.pid
group system
start program = "/etc/init.d/cron start"
stop program = "/etc/init.d/cron stop"
if 5 restarts within 5 cycles then timeout
Dans /etc/monit/conf.d/dovecot :
check process dovecot with pidfile /var/run/dovecot/master.pid
group mail
start program = "/etc/init.d/dovecot start"
stop program = "/etc/init.d/dovecot stop"
if failed host localhost port 993 type tcpssl sslauto protocol imap then restart
if failed host localhost port 995 type tcpssl sslauto protocol pop then restart
if failed host localhost port 143 protocol imap then restart
if failed host localhost port 110 protocol pop then restart
if 5 restarts within 5 cycles then timeout
Dans /etc/monit/conf.d/dspam :
check process dspam with pidfile /var/run/dspam/dspam.pid
group mail
start program = "/etc/init.d/dspam start"
stop program = "/etc/init.d/dspam stop"
if 5 restarts within 5 cycles then timeout
Dans /etc/monit/conf.d/fail2ban :
check process fail2ban with pidfile /var/run/fail2ban/fail2ban.pid
start program = "/etc/init.d/fail2ban start"
stop program = "/etc/init.d/fail2ban stop"
if failed unixsocket /var/run/fail2ban/fail2ban.sock then restart
if 5 restarts within 5 cycles then timeout
Dans /etc/monit/conf.d/munin :
check process munin-node with pidfile /var/run/munin/munin-node.pid
group system
start program = "/etc/init.d/munin-node start"
stop program = "/etc/init.d/munin-node stop"
if failed host localhost port 4949 then restart
if 5 restarts within 5 cycles then timeout
Dans /etc/monit/conf.d/mysql :
check process mysql with pidfile /var/run/mysqld/mysqld.pid
group database
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed unix "/var/run/mysqld/mysqld.sock" then restart
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout
Dans /etc/monit/conf.d/postfix :
check process postfix with pidfile /var/spool/postfix/pid/master.pid
group mail
start program = "/etc/init.d/postfix start"
stop program = "/etc/init.d/postfix stop"
if failed port 25 protocol smtp for 2 times within 2 cycles then restart
if failed port 465 protocol smtp for 2 times within 2 cycles then restart
if failed port 10026 protocol smtp for 2 times within 2 cycles then restart
if 5 restarts within 5 cycles then timeout
Dans /etc/monit/conf.d/powerdns :
check process powerdns with pidfile /var/run/pdns.pid
start program = "/etc/init.d/pdns start"
stop program = "/etc/init.d/pdns stop"
if failed host localhost port 53 then restart
if 5 restarts within 5 cycles then timeout
check process powerdns-recursor with pidfile /var/run/pdns_recursor.pid
start program = "/etc/init.d/pdns-recursor start"
stop program = "/etc/init.d/pdns-recursor stop"
if failed host localhost port 54 then restart
if 5 restarts within 5 cycles then timeout
Dans /etc/monit/conf.d/rsyslog :
check process rsyslogd with pidfile /var/run/rsyslogd.pid
group system
start program = "/etc/init.d/rsyslog start"
stop program = "/etc/init.d/rsyslog stop"
if 5 restarts within 5 cycles then timeout
Dans /etc/monit/conf.d/sshd :
check process sshd with pidfile /var/run/sshd.pid
start program "/etc/init.d/ssh start"
stop program "/etc/init.d/ssh stop"
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout
Dans /etc/monit/conf.d/vsftpd :
check process vsftpd with pidfile /var/run/vsftpd/vsftpd.pid
start program = "/etc/init.d/vsftpd start"
stop program = "/etc/init.d/vsftpd stop"
if failed port 21 protocol ftp then restart
if 5 restarts within 5 cycles then timeout
Enfin, nous devons activé monit dans /etc/default/monit :
startup=1
CHECK_INTERVALS=600
Et on redémarre le démon pour que le monitoring démarre :
/etc/init.d/monit force-reload
Le serveur est tout à fait opérationnel maintenant ! Il ne reste plus qu'un tout petit peu d'éléments à mettre en place.
Retour au sommaire.
Commentaires.
1. le Vendredi 29 Mai 2009 à 05:16:44, par Ginko
2. le Lundi 08 Novembre 2010 à 05:02:48, par MT4
Ajouter un commentaire.