Debian Server mit Monit überwachen

Mit dem Tool Monit kann man ganz schnell und unkompliziert, eine komplexe Überwachung seines Servers bzw. der Dienste darauf realisieren. Monit schickt dann eine E-Mail mit Informationen darüber, was gerade nicht läuft, neugestartet wurde oder ähnliches
Zuerst wird monit installiert:

apt-get install monit

Daraufhin werden die zu überwachenden Dienste in der Konfigurationsdatei

/etc/monit/monitrc

festgelegt. Am besten sichern wir zuerst die Originaldatei:

mv /etc/monit/monitrc /etc/monit/monitrc_original

und legen eine neue, leere Datei an die wir bearbeiten

nano /etc/monit/monitrc

Hier eine Beispieldatei:

set daemon 60
set logfile syslog facility log_daemon
set mailserver localhost
set mail-format { from: monit@yourdomain.tld }
set alert admin-who-gets-alert@yourdomain.tld

check process proftpd with pidfile /var/run/proftpd.pid
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

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

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 host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout

check process apache2 with pidfile /var/run/apache2.pid
group www
start program = "/etc/init.d/apache2 start"
stop program = "/etc/init.d/apache2 stop"
if failed host 127.0.0.1 port 80 then alert
if cpu is greater than 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if totalmem > 1500 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 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 failed port 25 protocol smtp then alert
if 5 restarts within 5 cycles then timeout

Die Konfiguration ist eigentlich selbsterklärend, deswegen zerlege ich nur nochmal kurz die SSH Konfiguration:
check process sshd with pidfile /var/run/sshd.pid

überprüft ob die PID File des Prozesses SSHD vorhanden ist, wenn nicht wird das Programm nicht ausgeführt
start program "/etc/init.d/ssh start"

legt fest, wie das Programm im Fehlerfall durch Monit gestartet werden kann

start program "/etc/init.d/ssh stop"

legt fest, wie das Programm im Fehlerfall durch Monit gestoppt werden kann

if failed port 22 protocol ssh then restart

gibt an, dass der Dienst neu gestartet werden soll, falls er nicht vorhanden ist

if 5 restarts within 5 cycles then timeout

alamiert den Administrator über einen Timeout, falls der Dienst innerhalb 5 Neustarts bei 5 Versuchen nicht läuft.

Nun aktivieren wir Monit indem wir in der Datei
/etc/default/monit

den Wert

startup=0

auf

startup=1

ändern und starten Monit nun mit

/etc/init.d/monit start

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert