Serveur Monitoring · 7 min read · Jan 06, 2026
Surveillance de serveur avec Munin et Monit sur Ubuntu 16.04 LTS (Xenial Xerus) - Page 2
6 Installer et configurer Monit
Pour installer Monit, nous faisons ceci :
apt-get -y install monitMaintenant, nous devons éditer /etc/monit/monitrc. Le fichier par défaut /etc/monit/monitrc contient de nombreux exemples, et vous pouvez trouver plus d’exemples de configuration sur http://mmonit.com/monit/documentation/. Cependant, dans mon cas, je veux surveiller proftpd, sshd, mysql, apache et postfix, je veux activer l’interface web de Monit sur le port 2812, je veux une interface web https, je veux me connecter à l’interface web avec le nom d’utilisateur admin et le mot de passe howtoforge, et je veux que Monit envoie des alertes par e-mail à root@localhost, donc mon fichier ressemble à ceci (j’ai ajouté des exemples pour d’autres démons à la configuration afin que vous puissiez ajuster le fichier à vos besoins) :
cp /etc/monit/monitrc /etc/monit/monitrc_orig
cat /dev/null > /etc/monit/monitrc
nano /etc/monit/monitrcset daemon 60
set logfile syslog facility log_daemon
set mailserver localhost
set mail-format { from: [email protected] }
set alert root@localhost
set httpd port 2812 and
SSL ENABLE
PEMFILE /var/certs/monit.pem
allow admin:howtoforge
check process sshd with pidfile /var/run/sshd.pid
start program "/usr/sbin/service ssh start"
stop program "/usr/sbin/service ssh stop"
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout
check process apache with pidfile /var/run/apache2/apache2.pid
group www
start program = "/usr/sbin/service apache2 start"
stop program = "/usr/sbin/service apache2 stop"
if failed host localhost port 80 protocol http
and request "/monit/token" then restart
if cpu is greater than 60% for 2 cycles then alert
if cpu > 80% 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
#check process mysql with pidfile /var/run/mysqld/mysqld.pid
# group database
# start program = "/usr/sbin/service mysql start"
# stop program = "/usr/sbin/service mysql stop"
# if failed host 127.0.0.1 port 3306 then restart
# if 5 restarts within 5 cycles then timeout
#check process proftpd with pidfile /var/run/proftpd.pid
# start program = "/usr/sbin/service proftpd start"
# stop program = "/usr/sbin/service proftpd stop"
# if failed port 21 protocol ftp then restart
# if 5 restarts within 5 cycles then timeout
#
#check process postfix with pidfile /var/spool/postfix/pid/master.pid
# group mail
# start program = "/usr/sbin/service postfix start"
# stop program = "/usr/sbin/service postfix stop"
# if failed port 25 protocol smtp then restart
# if 5 restarts within 5 cycles then timeout
#
#check process nginx with pidfile /var/run/nginx.pid
# start program = "/usr/sbin/service nginx start"
# stop program = "/usr/sbin/service nginx stop"
# if failed host 127.0.0.1 port 80 then restart
#
#check process memcached with pidfile /var/run/memcached.pid
# start program = "/usr/sbin/service memcached start"
# stop program = "/usr/sbin/service memcached stop"
# if failed host 127.0.0.1 port 11211 then restart
#
#check process pureftpd with pidfile /var/run/pure-ftpd/pure-ftpd.pid
# start program = "/usr/sbin/service pure-ftpd-mysql start"
# stop program = "/usr/sbin/service pure-ftpd-mysql stop"
# if failed port 21 protocol ftp then restart
# if 5 restarts within 5 cycles then timeout
#
#check process named with pidfile /var/run/named/named.pid
# start program = "/usr/sbin/service bind9 start"
# stop program = "/usr/sbin/service bind9 stop"
# if failed host 127.0.0.1 port 53 type tcp protocol dns then restart
# if failed host 127.0.0.1 port 53 type udp protocol dns then restart
# if 5 restarts within 5 cycles then timeout
#
#check process ntpd with pidfile /var/run/ntpd.pid
# start program = "/usr/sbin/service ntp start"
# stop program = "/usr/sbin/service ntp stop"
# if failed host 127.0.0.1 port 123 type udp then restart
# if 5 restarts within 5 cycles then timeout
#
#check process mailman with pidfile /var/run/mailman/mailman.pid
# group mail
# start program = "/usr/sbin/service mailman start"
# stop program = "/usr/sbin/service mailman stop"
#
#check process amavisd with pidfile /var/run/amavis/amavisd.pid
# group mail
# start program = "/usr/sbin/service amavis start"
# stop program = "/usr/sbin/service amavis stop"
# if failed port 10024 protocol smtp then restart
# if 5 restarts within 5 cycles then timeout
#
#check process courier-imap with pidfile /var/run/courier/imapd.pid
# group mail
# start program = "/usr/sbin/service courier-imap start"
# stop program = "/usr/sbin/service courier-imap stop"
# if failed host localhost port 143 type tcp protocol imap then restart
# if 5 restarts within 5 cycles then timeout
#
#check process courier-imap-ssl with pidfile /var/run/courier/imapd-ssl.pid
# group mail
# start program = "/usr/sbin/service courier-imap-ssl start"
# stop program = "/usr/sbin/service courier-imap-ssl stop"
# if failed host localhost port 993 type tcpssl sslauto protocol imap then restart
# if 5 restarts within 5 cycles then timeout
#
#check process courier-pop3 with pidfile /var/run/courier/pop3d.pid
# group mail
# start program = "/usr/sbin/service courier-pop start"
# stop program = "/usr/sbin/service courier-pop stop"
# if failed host localhost port 110 type tcp protocol pop then restart
# if 5 restarts within 5 cycles then timeout
#
#check process courier-pop3-ssl with pidfile /var/run/courier/pop3d-ssl.pid
# group mail
# start program = "/usr/sbin/service courier-pop-ssl start"
# stop program = "/usr/sbin/service courier-pop-ssl stop"
# if failed host localhost port 995 type tcpssl sslauto protocol pop then restart
# if 5 restarts within 5 cycles then timeout
#
#check process dovecot with pidfile /var/run/dovecot/master.pid
# group mail
# start program = "/usr/sbin/service dovecot start"
# stop program = "/usr/sbin/service dovecot stop"
# if failed host localhost port 143 type tcp protocol imap then restart
# if 5 restarts within 5 cycles then timeoutLe fichier de configuration est assez explicite ; si vous n’êtes pas sûr d’une option, jetez un œil à la documentation de Monit : http://mmonit.com/monit/documentation/monit.html
Dans la partie apache de la configuration de Monit, vous trouvez ceci :
if failed host localhost port 80 protocol http
and request "/monit/token" then restartce qui signifie que Monit essaie de se connecter à localhost sur le port 80 et essaie d’accéder au fichier /monit/token qui est /var/www/html/monit/token car la racine de document de notre site web est /var/www/html. Si Monit ne réussit pas, cela signifie qu’Apache ne fonctionne pas, et Monit va le redémarrer. Maintenant, nous devons créer le fichier /var/www/html/monit/token et y écrire une chaîne aléatoire :
mkdir /var/www/html/monit
echo "hello" > /var/www/html/monit/tokenEnsuite, nous créons le certificat pem ( /var/certs/monit.pem) dont nous avons besoin pour l’interface web Monit chiffrée SSL :
mkdir /var/certs
cd /var/certsNous avons besoin d’un fichier de configuration OpenSSL pour créer notre certificat. Il peut ressembler à ceci :
nano /var/certs/monit.cnf# créer des certificats RSA - Serveur
RANDFILE = ./openssl.rnd
[ req ]
default_bits = 2048
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
[ req_dn ]
countryName = Nom du pays (code à 2 lettres)
countryName_default = MO
stateOrProvinceName = Nom de l'état ou de la province (nom complet)
stateOrProvinceName_default = Monitoria
localityName = Nom de la localité (par exemple, ville)
localityName_default = Monittown
organizationName = Nom de l'organisation (par exemple, entreprise)
organizationName_default = Monit Inc.
organizationalUnitName = Nom de l'unité organisationnelle (par exemple, section)
organizationalUnitName_default = Dept. des technologies de surveillance
commonName = Nom commun (FQDN de votre serveur)
commonName_default = server.monit.mo
emailAddress = Adresse e-mail
emailAddress_default = [email protected]
[ cert_type ]
nsCertType = serverMaintenant, nous créons le certificat comme ceci :
openssl req -new -x509 -days 365 -nodes -config ./monit.cnf -out /var/certs/monit.pem -keyout /var/certs/monit.pemopenssl gendh 1024 >> /var/certs/monit.pemopenssl x509 -subject -dates -fingerprint -noout -in /var/certs/monit.pemchmod 600 /var/certs/monit.pemEnfin, nous pouvons démarrer Monit :
service monit restartMaintenant, pointez votre navigateur vers https://www.example.com:2812/ (assurez-vous que le port 2812 n’est pas bloqué par votre pare-feu), connectez-vous avec admin et howtoforge, et vous devriez voir l’interface web de Monit. Cela devrait ressembler à ceci :

(Écran principal)

(Page d’état du système)
Selon votre configuration dans /etc/monit/monitrc, Monit redémarrera vos services s’ils échouent et enverra des e-mails de notification si les ID de processus des services changent, etc.
Pour obtenir le statut de Monit dans le shell, exécutez la commande “monit status” :
monit statusLa commande affichera le statut de tous les services surveillés.

7 Configurer Monit dans ISPConfig
Le panneau de contrôle ISPConfig peut afficher les données Monit dans son module Monitor. Pour activer cette fonction dans ISPConfig, connectez-vous à ISPConfig en tant qu’utilisateur Administrateur (admin), allez dans Système > Configuration du serveur, remplissez l’URL, le nom d’utilisateur et le mot de passe pour Monit comme indiqué ci-dessous.

8 Liens
- munin: http://munin-monitoring.org/
- monit: http://mmonit.com/monit/
Recevez de nouveaux articles dans votre boîte de réception.
Aucun spam. Désabonnez-vous à tout moment.