Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
monit [2011/01/28 12:07] TuxGasy créée |
monit [2016/02/16 23:11] (Version actuelle) |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ===== À propos ===== | ||
+ | |||
+ | Monit est un outil permettant de vérifier l'état des processus. | ||
+ | |||
+ | ===== Installation et configuration ===== | ||
+ | |||
+ | Pour l'installer : | ||
+ | <code># aptitude install monit</code> | ||
+ | |||
+ | Éditer le fichier **/etc/default/monit** et modifier l'option **startup** (mettre 1). | ||
+ | |||
+ | Ensuite, il faut éditer son fichier de configuration **/etc/monit/monitrc** : | ||
+ | * Pour lancer monit en tant daemon, décommenter **set daemon 120** ; | ||
+ | * Décommenter aussi la ligne **set logfile syslog facility log_daemon** pour avoir les logs de monit ; | ||
+ | * Pour recevoir les alertes de monit par mail, ajouter l'option **set alert admin@exemple.net** (adapter le mail avec le votre) et **set mailserver localhost** ; | ||
+ | * Monit peut être contrôler depuis un navigateur. Pour cela : | ||
+ | <code> | ||
+ | set httpd port 2812 and | ||
+ | allow username:password | ||
+ | </code> | ||
+ | |||
+ | Enfin, on doit configurer chaque processus qu'on veut surveiller. Pour chaque daemon à surveiller, créer son fichier de configuration dans **/etc/monit/conf.d/**. Voici une liste d'exemple : | ||
+ | * Apache2 | ||
+ | <code> | ||
+ | check process apache2 with pidfile /var/run/apache2.pid | ||
+ | start program = "/etc/init.d/apache2 start" | ||
+ | stop program = "/etc/init.d/apache2 stop" | ||
+ | |||
+ | if cpu is greater than 60% for 2 cycles then alert | ||
+ | if cpu > 80% for 5 cycles then restart | ||
+ | if totalmem > 240.0 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 | ||
+ | </code> | ||
+ | |||
+ | * MySql | ||
+ | <code> | ||
+ | check process mysql with pidfile /var/run/mysqld/mysqld.pid | ||
+ | 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 | ||
+ | </code> | ||
+ | |||
+ | * Fail2ban | ||
+ | <code> | ||
+ | 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 | ||
+ | </code> | ||
+ | |||
+ | * Postfix | ||
+ | <code> | ||
+ | check process postfix with pidfile /var/spool/postfix/pid/master.pid | ||
+ | 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 5 restarts within 5 cycles then timeout | ||
+ | </code> | ||
+ | |||
+ | * Courier-Imap (SSL) | ||
+ | <code> | ||
+ | check process imapd-ssl with pidfile /var/run/courier/imapd-ssl.pid | ||
+ | start program = "/etc/init.d/courier-imap-ssl start" | ||
+ | stop program = "/etc/init.d/courier-imap-ssl stop" | ||
+ | |||
+ | if 5 restarts within 5 cycles then timeout | ||
+ | </code> | ||
+ | |||
+ | * Sshd (serveur SSH) | ||
+ | <code> | ||
+ | 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 | ||
+ | </code> | ||
+ | |||
+ | D'autres exemples sont disponibles sur le [[http://mmonit.com/wiki/Monit/ConfigurationExamples|Wiki de Monit]]. | ||
+ | |||
+ | ===== Sources ===== | ||
+ | |||
http://linux.die.net/man/1/monit | http://linux.die.net/man/1/monit | ||