rsyslogd ist ein moderner und leistungsfähiger Syslog Daemon unter Linux. Er implementiert das standardisierte [[Syslog]] Protokoll (nach RFC 3164 und RFC 5424) und dient als zentrale Komponente zur Erfassung, Verarbeitung und Speicherung von Logmeldungen aus dem gesamten System. Siehe auch [[journald]]. apt install rsyslog Je nach Distribution legt rsyslogd verschiedene Dateien unter /var/log/ an. Beispiele: ^Datei^Beschreibung^ |/var/log/syslog|Allgemeine Systemmeldungen (z. B. Ubuntu/Debian)| |/var/log/messages|Systemmeldungen (z. B. CentOS/RHEL)| |/var/log/auth.log|Authentifizierungs- und Sicherheitsmeldungen| |/var/log/kern.log|Kernel-Meldungen| |/var/log/mail.log|Mailserver-bezogene Logs| |/var/log/daemon.log|Logs von Hintergrunddiensten| =====Konfiguration===== rsyslog liest standardmäßig die Konfiguration aus der Hauptdatei: /etc/rsyslog.conf Und allen Dateien im Verzeichnis: /etc/rsyslog.d/*.conf In den individuellen Config Files muss am Ende "& stop" stehen damit keine weiteren Dateien evaluiert werden. Ein typischer Eintrag sieht so aus: * Links: Filter (Facility und Priority) * Rechts: Ziel (Datei, Remote Host, Pipe, Programm usw.) auth,authpriv.* /var/log/auth.log *.*;auth,authpriv.none -/var/log/syslog Bedeutung des Minuszeichens (-) vor dem Dateinamen # rsyslog schreibt synchron in die Datei -> jeder Logeintrag wird sofort auf die Platte geschrieben (fsync() nach jedem Write). Das ist sicherer, aber langsamer, weil jeder Eintrag eine I/O-Operation erzwingt. *.* /var/log/syslog # Minuszeichen davor # Schreibe asynchron: rsyslog puffert Einträge im Speicher und schreibt sie blockweise. Das ist schneller (gerade bei hohem Logaufkommen, z. B. HAProxy, mail, syslog), aber theoretisch etwas unsicherer, im Fall eines Absturzes oder Stromausfalls könnten die letzten paar Logzeilen verloren gehen. *.* -/var/log/syslog =====Remote Logging===== rsyslogd kann Logmeldungen über das Netzwerk empfangen oder weiterleiten, z. B. an einen zentralen Logserver (rsyslog.conf): # TCP-Empfang aktivieren module(load="imtcp") input(type="imtcp" port="514") # UDP-Empfang aktivieren module(load="imudp") input(type="imudp" port="514") # Beispiel mit Verschlüsselung # module(load="imtcp" StreamDriver.Name="gtls" StreamDriver.Mode="1" StreamDriver.AuthMode="x509/name") # Logs in Datei schreiben $template RemoteLogs,"/var/log/remote/%HOSTNAME%.log" *.* ?RemoteLogs Auf dem Client *.* @@(o)logserver.example.com:514 =====Templates===== Ein Template in rsyslog definiert, wie und wohin Logmeldungen geschrieben oder weitergeleitet werden. Man kann das Ausgabeformat, den Dateiname oder Nachrichteninhalt anpassen. Siehe [[https://www.rsyslog.com/doc/configuration/templates.html|rsyslog.com - Templates]] ^Template Typ^Beschreibung^ |List template type|map fields one by one (rename keys, add or drop fields, inject constants) and build JSON safely with jsonf or jsonftree.| |Subtree template type|serialize a prepared JSON tree (for example, after JSON Structured Content Extraction Module (mmjsonparse) or LEEF Structured Content Extraction Module (mmleefparse) populated $!ecs).| |String template type|simple text records (legacy syslog lines, CSV, or other plain-text formats).| |Plugin template type|special encodings provided by modules.| # Syntax $template , "" # Beispiel $template RemoteLogs,"/var/log/remote/%HOSTNAME%.log" *.* ?RemoteLogs Das Fragezeichen ? sagt "Benutze ein Template, um den Zieldateinamen zu bestimmen.". Das Beispiel oben schreibt also alle Meldungen (*.*) in die Datei, die das Template vorgibt (/var/log/remote/%HOSTNAME%.log). ^Platzhalter^Bedeutung^ |%HOSTNAME%|Hostname der Quelle| |%FROMHOST-IP%|IP-Adresse des Absenders| |%syslogtag%|Tag des Prozesses (z. B. sshd[1234]:)| |%syslogseverity-text%|Severity als Text (z. B. "info")| |%syslogfacility-text%|Facility als Text (z. B. "auth")| |%$YEAR%, %$MONTH%, %$DAY%|Datumskomponenten| |%msg%|eigentliche Lognachricht| $template DailyLogs,"/var/log/remote/%HOSTNAME%/%$YEAR%-%$MONTH%-%$DAY%.log" *.* ?DailyLogs # Ergebnis # /var/log/remote/web01/2025-11-11.log # /var/log/remote/db01/2025-11-11.log Templates lassen sich auch für Nachrichtenformatierung verwenden. $template CustomFormat,"%timestamp% %HOSTNAME% %syslogtag% %msg%\n" *.* /var/log/custom.log;CustomFormat # Dateiname dynamisch nach Host + Datum $template DynamicFile,"/var/log/remote/%HOSTNAME%/%$YEAR%-%$MONTH%-%$DAY%.log" # Format der Logzeilen $template CustomFormat,"%timestamp% %HOSTNAME% %syslogtag% %msg%\n" # Regel: Alle Logs speichern *.* ?DynamicFile;CustomFormat Oder in RainerScript # dynamischer Dateiname: /var/log/remote//YYYY-MM-DD.log template(name="DynDailyFile" type="list") { constant(value="/var/log/remote/") property(name="hostname") constant(value="/") property(name="timereported" dateFormat="year") constant(value="-") property(name="timereported" dateFormat="month") constant(value="-") property(name="timereported" dateFormat="day") constant(value=".log") } # Zeilenformat: => template(name="LineFormat" type="list") { property(name="timestamp" dateFormat="rfc3339") constant(value=" ") property(name="hostname") constant(value=" ") property(name="syslogtag") constant(value=" ===> ") property(name="msg" dropLastLf="on") constant(value="\n") } #### RULES #### # Eine einzige Catch-all-Regel (verhindert Doppellogging) *.* action( type="omfile" dynaFile="DynDailyFile" template="LineFormat" createDirs="on" ) ====List Templates==== [[https://www.rsyslog.com/doc/reference/templates/templates-type-list.html]] =====Links===== * [[https://www.rsyslog.com/doc/|Documentation]]