Monitoring serveur avec monit
Installer Monit
sudo apt update
sudo apt install monit
#Commandes pour gérer le service monit
service monit start / stop / status / restart
#Démarrer tous les services
sudo monit start all
#Configurer Monit
sudo vim /etc/monit/monitrc
#cherchez la ligne set httpd, et remplacez avec les configs suivantes :
set httpd port 2812 and
use address xxx.xxx.xxx.xxx # only accept connection from localhost
allow 0.0.0.0/0.0.0.0 # allow localhost to connect to the server and
allow admin:monit # require user 'admin' with password 'monit'
#port 2812 : il faut ouvrir ce port dans le parefeu
#xxx.xxx.xxx.xxx : l'adresse IP du serveur sur lequel monit est installé.
#0.0.0.0/0.0.0.0 : permet l'accès à l'interface web de monit depuis n'importe quelle IP
#il faut changer le mot de passe à autre chose
#config mail pour recevoir des notifications par mail dans le fichier monitrc :
set mailserver mail.yourmailserver.com port 587
username "[email protected]" password "mypassword"
using tlsv1
with timeout 30 seconds
#cherchez la ligne suivante, puis indiquez l'adresse d'envoi. L'adresse doit être la même que celle ci-dessus.
set mail-format { from: [email protected] }
#cherchez la ligne suivante pour indiquer le mail pour recevoir les notifiations :
set alert [email protected]
#Sauvegardez les modifs, vérifiez la config de monit, puis redémarrez-le
monit -t
service monit restart
#on pourra maintenant accéder à monit sur xxx.xxx.xxx.xxx:2812
#les configs pour monitor les différents services sont ici : /etc/monit/conf-available
#il suffit de copier le fichier config du service qu'on a besoin avec cette commande :
ln -s /etc/monit/conf-available/apache2 /etc/monit/conf-enabled/
#puis faire :
monit -t
service monit restart
Configs services monit
#modifiez le fichier config : vim /etc/monit/conf-available/apache2 #et indiquez la suivante avant la ligne start program, puis sauvegardez alert [email protected] only on { timeout,nonexist,resource,pid,connection } #créez un fichier resource dans /etc/monit/conf-available avec le contenu suivant : vim resource #avec ce contenu, puis sauvegardez : check system mon.hostname if memory usage > 90% then alert if cpu usage > 90% for 4 cycles then alert if swap usage > 95% for 4 cycles then alert #remplacez mon.hostname par votre hostname en tapant la commande : hostname -f #sauvegardez le fichier, puis créez un autre fichier php-fpm : vim php-fpm #avec ce contenu, puis sauvegardez : check process php7-fpm with pidfile /run/php/php7.2-fpm.pid start program = "/usr/sbin/service php7.2-fpm start" with timeout 60 seconds stop program = "/usr/sbin/service php7.2-fpm stop" if failed host 127.0.0.1 port 9009 type tcp for 3 cycles then restart #Pour avoir les infos ci-dessus, tapez : grep "listen =" /etc/php/7.2/fpm/pool.d/www.conf sudo find /run -iname php*.pid
Ref :
Installation et config monit :
https://dzone.com/articles/how-to-install-monit-monitoring-tool-on-ubuntu-160
https://websiteforstudents.com/install-monit-system-monitor-on-ubuntu-18-04-16-04-lts/
https://www.alibabacloud.com/blog/how-to-install-monit-monitoring-tool-on-ubuntu-16-04_594339Configs php-fpm :
https://guides.wp-bullet.com/use-monit-monitor-restart-php7-fpm-service-automatically/
Configs ressources serveur :
https://tuxbyte.com/monit-monitoring-solution/
Configs mail :
https://serverfault.com/questions/506861/monit-send-email-does-not-work
