Benutzer-Werkzeuge

Webseiten-Werkzeuge


howto:monit

====== Monit ====== \\ Autor: F4RR3LL|sven\\ E-Mail: <sven.richter@nixhelp.de>\\ Stand: 01.04.2015 \\ \\ \\ Monit ist ein nettes Tool mit dem man Systemprozesse überwachen kann. Mann kann auch andere Sachen damit machen... DNS pingen lassen, Rechte auf Ordner überwachen etc. Habe ich alles mal durchprobiert. Ich finde diese *extras* nicht so sinnig da Monit auch ganz schnell mal anfängt zu nerven. Man kann sich bei Änderungen auch per Mail informieren lassen. Man kann es aber auch einfach nur im Browser anschaun, oder man lässt Monit einfach werkeln. \\ ===== Die Installation ===== \\ <code> apt-get install monit </code> \\ Nach der Installation erhalten wir eine Meldung des Systems ->\\ \\ <code> Starting daemon monitor: monit won't be started/stopped unless it it's configured please configure monit and then edit /etc/default/monit and set the "startup" variable to 1 in order to allow monit to start </code> \\ Diese wollen wir natürlich nicht unbeachtet lassen also begeben wir uns auf direktem Weg zu \\ <code> nano /etc/default/monit </code> \\ hier aus **startup=0** eine **1** machen und wieder speichern. (das geht mit strg o)\\ \\ Ab jetzt sollte sich Monit auch starten lassen. Bringt aber noch nix, da wir Monit ja noch gar keine Aufgabe gegeben haben ;)\\ Also machen wir mal weiter.\\ \\ ===== Die Konfiguration ===== \\ Um Monit sinnvoll nutzen zu können müssen wir uns in die Konfigurationsdatei begeben \\ <code> nano /etc/monit/monitrc </code> ==== Das Allgemeine ==== \\ Zuerst passen wir das Intervall an wie oft Monit tätig werden soll, hier 60 Sekunden:\\ <code> aus # set daemon 120 wird set daemon 60 </code> \\ Wir möchten natürlich Logs haben von dem was Monit so treibt:\\ <code> aus # set logfile syslog facility log_daemon wird set logfile /var/log/monit </code> \\ In der folgenden Passage besteht die Möglichkeit, dass ihr euch per Mail informieren lasst was euer Monit so feststellt und treibt. Ich werde mal Beispielhaft die ganze Passage in geändertem Zustand posten. Ich denke dann erkennt ihr leicht was ihr ändern müsst.\\ <code> ## Set list of mailservers for alert delivery. Multiple servers may be ## specified using comma separator. By default monit uses port 25 - it is ## possible to override it with the PORT option. # set mailserver mail.mailserver.tld, # primary mailserver # backup.bar.baz port 10025, # backup mailserver on port 10025 # localhost # fallback relay # # ## By default monit will drop the event alert, in the case that there is no ## mailserver available. In the case that you want to keep the events for ## later delivery retry, you can use the EVENTQUEUE statement. The base ## directory where undelivered events will be stored is specified by the ## BASEDIR option. You can limit the maximal queue size using the SLOTS ## option (if omited then the queue is limited just by the backend filesystem). # # set eventqueue # basedir /var/monit # set the base directory where events will be stored # slots 100 # optionaly limit the queue size # # ## Monit by default uses the following alert mail format: ## ## --8<-- ## From: monit@$HOST # sender ## Subject: monit alert -- $EVENT $SERVICE # subject ## ## $EVENT Service $SERVICE # ## # ## Date: $DATE # ## Action: $ACTION # ## Host: $HOST # body ## Description: $DESCRIPTION # ## # ## Your faithful employee, # ## monit # ## --8<-- ## ## You can override the alert message format or its parts such as subject ## or sender using the MAIL-FORMAT statement. Macros such as $DATE, etc. ## are expanded on runtime. For example to override the sender: # set mail-format { from: monit@mailserver.tld } # # ## You can set the alert recipients here, which will receive the alert for ## each service. The event alerts may be restricted using the list. # set alert wo-es-hinsoll@mailserver.tld # receive all alerts set alert wo-es-hinsoll@mailserver.tld only on { timeout } # receive just service- # # timeout alert # </code> Als nächstes besteht die Möglichkeit sich den ganzen Status von Monit auch im Browser anzuschaun, und dort auch Dienste zu stoppen oder auch zu starten. \\ Also hier nicht sorglose Passwörter verteilen. \\ Die Config ist wie folgt anzupassen:\\ <code> ## Monit has an embedded webserver, which can be used to view the ## configuration, actual services parameters or manage the services using the ## web interface. # set httpd port 12345 and # hier könnt ihr einen Port frei nach Nase wählen ;) # use address localhost # only accept connection from localhost # allow $IP # wer eine feste IP hat oder über OPENVPN auf den Server geht kann hier die feste IP eintragen allow $username:$supergeheimespass # wer das Pass kennt kann viel Mist machen ;) # </code> \\ ==== Das Spezielle ==== \\ Nachdem nun die allgemeinen Einstellungen für Monit vorgenommen sind soll es ja endlich Dienste überwachen. Hierzu einige Beispielconfigs wie man sie am Ende der Konfiguration anhängen kann. Diese Liste kann nach selbem Schema für jeden x beliebigen Dienst erweitert werden. <code> # SSH Server Überwachung # 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 host 127.0.0.1 port 22 protocol ssh then restart if 5 restarts within 5 cycles then timeout </code> <code> # # Lighttpd Server Überwachung # check process lighttpd with pidfile /var/run/lighttpd.pid start program = "/etc/init.d/lighttpd start" stop program = "/etc/init.d/lighttpd stop" if failed host 127.0.0.1 port 80 then restart if failed host 127.0.0.1 port 443 then restart </code> <code> # # MSYSQL Server Überwachung # 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 </code> <code> # # POSTFIX Server Überwachung # 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 host 127.0.0.1 port 25 protocol smtp then restart if 5 restarts within 5 cycles then timeout </code> <code> # # Policyd-Weight Server Überwachung # check process policyd-weight with pidfile /var/run/policyd-weight.pid group mail start program = "/etc/init.d/policyd-weight start" stop program = "/etc/init.d/policyd-weight stop" if failed host 127.0.0.1 port 12525 then restart if 5 restarts within 5 cycles then timeout </code> <code> # # Postgrey Server Überwachung # check process postgrey with pidfile /var/run/postgrey.pid group mail start program = "/etc/init.d/postgrey start" stop program = "/etc/init.d/postgrey stop" if failed host 127.0.0.1 port 60000 then restart if 5 restarts within 5 cycles then timeout </code> <code> # # Dovecot Server Überwachung # check process dovecot with pidfile /var/run/dovecot/master.pid group mail start program = "/etc/init.d/dovecot start" stop program = "/etc/init.d/dovecot stop" if failed host 127.0.0.1 port 110 then restart if 5 restarts within 5 cycles then timeout </code> <code> # # Crons # check process cron with pidfile /var/run/crond.pid group system start program = "/etc/init.d/cron start" stop program = "/etc/init.d/cron stop" if 5 restarts within 5 cycles then timeout </code> <code> # # OpenVPN # check process openvpn with pidfile /var/run/openvpn.server.pid group system start program = "/etc/init.d/openvpn start" stop program = "/etc/init.d/openvpn stop" if 5 restarts within 5 cycles then timeout </code> <code> # # Squid Proxy # check process squid with pidfile /var/run/squid.pid group system start program = "/etc/init.d/squid start" stop program = "/etc/init.d/squid stop" if failed host 127.0.0.1 port 3128 protocol ssh then restart if 5 restarts within 5 cycles then timeout </code> <code> # # Openfire Jabber # check process openfire with pidfile /var/run/openfire.pid group system start program = "/etc/init.d/openfire start" stop program = "/etc/init.d/openfire stop" if failed host 127.0.0.1 port 5222 protocol ssh then restart if 5 restarts within 5 cycles then timeout </code> <code> # # Pure-FTP # check process pure-ftpd with pidfile /var/run/pure-ftpd/pure-ftpd.pid start program "/etc/init.d/pure-ftpd-mysql start" stop program "/etc/init.d/pure-ftpd-mysql stop" if failed host 127.0.0.1 port 21 then restart if 5 restarts within 5 cycles then timeout </code> <code> # # courier pop3 # check process pop3 with pidfile /var/run/courier/pop3d.pid group mail start program = "/etc/init.d/courier-pop start" stop program = "/etc/init.d/courier-pop stop" if failed port 110 then restart if 5 restarts within 5 cycles then timeout </code> <code> # # courier pop3 ssl # check process pop3-ssl with pidfile /var/run/courier/pop3d-ssl.pid group mail start program = "/etc/init.d/courier-pop-ssl start" stop program = "/etc/init.d/courier-pop-ssl stop" if failed port 995 then restart if 5 restarts within 5 cycles then timeout </code> <code> # # courier imap # check process imap with pidfile /var/run/courier/imapd.pid group mail start program = "/etc/init.d/courier-imap start" stop program = "/etc/init.d/courier-imap stop" if failed port 143 then restart if 5 restarts within 5 cycles then timeout </code> <code> # # Spamassassin # check process spamd with pidfile /var/run/spamd.pid start program = "/etc/init.d/spamassassin start" stop program = "/etc/init.d/spamassassin stop" if failed port 783 then restart if 5 restarts within 5 cycles then timeout </code> <code> # # Proftpd Server Überwachung # 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 host 127.0.0.1 port 21 then restart if 5 restarts within 5 cycles then timeout </code> <code> # # Amavis # check process amavis with pidfile /var/run/amavis/amavisd.pid start program = "/etc/init.d/amavis start" stop program = "/etc/init.d/amavis stop" if failed port 10024 then restart if 5 restarts within 5 cycles then timeout </code> <code> # # Bind9 # check process named with pidfile /var/run/named/named.pid start program = "/etc/init.d/bind9 start" stop program = "/etc/init.d/bind9 stop" if failed port 53 then restart if 5 restarts within 5 cycles then timeout </code> <code> # # Apache2 # check process apache2 with pidfile /var/run/apache2.pid start program = "/etc/init.d/apache2 start" stop program = "/etc/init.d/apache2 stop" if failed port 80 then restart if 5 restarts within 5 cycles then timeout </code> <code> # # Nginx # check process nginx with pidfile /var/run/nginx.pid start program = "/etc/init.d/nginx start" stop program = "/etc/init.d/nginx stop" if failed port 80 then restart if 5 restarts within 5 cycles then timeout </code> <code> # # Varnish # check process varnishd with pidfile /var/run/varnishd.pid start program = "/etc/init.d/varnish start" stop program = "/etc/init.d/varnish stop" if failed port 6081 then restart if 5 restarts within 5 cycles then timeout </code> <code> # # php5-fpm # check process php5-fpm with pidfile /var/run/php5-fpm.pid start program = "/etc/init.d/php5-fpm start" stop program = "/etc/init.d/php5-fpm stop" if failed unixsocket /var/run/php5-fpm.sock then restart if 5 restarts within 5 cycles then timeout </code> ===== Der Start ===== Nachdem nun alles in der config drin ist was rein soll kann man mit monit testen ob man auch alles richtig gemacht hat. Mit folgendem Befehl prüft ihr ob die Syntax in eurer config stimmt.\\ <code> /etc/init.d/monit syntax </code> Die Ausgabe sollte sein\\ **Control file syntax OK**\\ \\ Nun ist es soweit wir starten Monit <code> /etc/init.d/monit start </code> \\ Von nun an läuft Monit auf eurem Server und überwacht die Dienste auf eurem Server. Sollte ein Dienst abschmieren wird Monit ihn wieder starten.\\ Wer die Infos per Mail an hat bekommt auch Mails wenn mal eine pid wechselt usw. Das lasse ich meistens aus weil das nur nervt ;)\\ Wer Webzugriff aktiviert hat conected auf seinen Server via:\\ \\ **<nowiki>http://$username:$supergeheimespass@$Serverip:12345</nowiki>** \\ \\ So das wars eigentlich. Viel Spaß mit Monit. Gruß Sven \\ \\ Zurück zum [[:Start|Index]] \\ <html> <center> <script type="text/javascript"><!-- google_ad_client = "ca-pub-8618871073600174"; /* mobiles */ google_ad_slot = "6798354100"; google_ad_width = 320; google_ad_height = 50; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </center> </html>

howto/monit.txt · Zuletzt geändert: 2022/10/11 10:55 (Externe Bearbeitung)

Seiten-Werkzeuge