22juin2009
Installation et Configuration de Monit

Pour une surveillance de votre serveur par interface web simple.
Monit est une application permettant de surveiller l'état des services (notamment http, smtp, ftp, ssh, mysql, etc...) par une interface web, et de notifier l'administrateur si besoin (trop grande charge cpu, redémarrage, indisponibilité...).
J'ai découvert par hasard ce concurrent open source de zabbix et nagios, il est beaucoup plus simple à configurer mais bon il offre moins d'options.
L'interface web :
Téléchargement :
Url du site de Monit : http://mmonit.com/monit/download/
cd /opt/SOURCES wget http://mmonit.com/monit/dist/monit-5.0.3.tar.gz tar xvzf monit-5.0.3.tar.gz
Installation :
cd monit-5.0.3 mkdir /opt/monit503 ln -s /opt/monit503 /opt/monit ./configure --prefix=/opt/monit --with-ssl make make install cd /opt/monit mkdir /opt/monit/etc cp -a monitrc /opt/monit/etc/ vi /opt/monit/etc/monitrc
Confguration :
Le fichier de configuration principal est donc /opt/monit/etc/monitrc
Voici un exemple du contenu :
set daemon 60 # check services at 2-minute intervals
set logfile syslog facility log_daemon
set idfile /opt/monit/var/.monit.id
set statefile /opt/monit/var/.monit.state
set mailserver localhost, # primary mailserver
set mail-format { from: monit@system-linux.eu }
set alert admin@system-linux.eu # receive all alerts
set httpd port 2812 and
allow administrateur:votre-password # require user 'admin' with password 'monit'
check system localhost
if loadavg (1min) > 4 then alert
if loadavg (5min) > 2 then alert
if memory usage > 75% then alert
if cpu usage (user) > 70% then alert
if cpu usage (system) > 30% then alert
if cpu usage (wait) > 20% then alert
check process apache with pidfile /opt/httpd/logs/httpd.pid
start program = "/etc/init.d/httpd start" with timeout 60 seconds
stop program = "/etc/init.d/httpd stop"
if cpu > 70% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if totalmem > 400.0 MB for 5 cycles then restart
if children > 350 then restart
if loadavg(5min) greater than 10 for 8 cycles then stop
if failed host www.system-linux.eu port 80 protocol http
then restart
Configuration du script d'init :
cp -a /opt/SOURCES/monit-5.0.3/contrib/rc.monit /etc/init.d/ cd /etc/init.d/ mv rc.monit monit vi monit (à modifier en concequence selon votre installation, (chemin des fichiers et dossiers etc...)
Les droits et sécurité :
chown -R root: /opt/monit/ * chown root: /etc/init.d/monit
Interface web :
Elle est sous la forme :
http://nom-serveur:2312
Exemple de check à ajouter dans votre fichier /opt/monit/etc/monitrc :
# MySQL check process mysqld 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 host 127.0.0.1 port 3306 then restart if 5 restarts within 5 cycles then timeout # SSH check process sshd with pidfile /var/run/sshd.pid group ssh start program "/etc/init.d/ssh start" stop program "/etc/init.d/ssh stop" if failed host 127.0.0.1 port 222 protocol ssh then restart if 5 restarts within 5 cycles then timeout # 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 then restart if 5 restarts within 5 cycles then timeout # FTP check process proftpd with pidfile /var/run/proftpd.pid group ftp start program = "/etc/init.d/proftpd start" stop program = "/etc/init.d/proftpd stop" if failed port 21 protocol ftp then restart if 5 restarts within 5 cycles then timeout # Disk1 check device sda1 with path /dev/sda1 if space usage > 85% then alert group system # Named check process named with pidfile /opt/bind9/var/run/named/named.pid group bind9 start program = "/etc/init.d/bind9 start" stop program = "/etc/init.d/bind9 stop" if failed port 53 protocol dns then restart if 5 restarts within 5 cycles then timeout
Comme vous pouvez le constater la syntaxe de monit est très abordable et les exemples facile à trouver sur le site officiel.
Vous avez aussi la possibilité de vérifier la syntaxe de votre fichier de configuration après l'avoir modifié, por cela utilisez la commande suivante :
/etc/init.d/monit syntax
Et si vous voulez aller plus loin :


Commentaires
mardi, juin 23 2009 | 08:48
A l'air sympa pour un petit nombre de serveur, par contre pour un parc, il propose m/monit, qui lui n'est malheureusement pas libre
mardi, juin 23 2009 | 09:27
oui tu as raison, je pense que jusqu'a 10 machines ça peut aller au dela dur dur