Debian Jessie mit systemd: aufgeblähte Protokolldateien werden niemals gelöscht

838
Thom Nichols

Ich habe eine relativ kleine, minimale Debian Jessie-Distribution, in der Protokolldateien /var/log(scheinbar willkürlich) gedreht, aber nie gelöscht werden:

$ sudo du -sk /var/log/* | sort -rn 4167364 /var/log/daemon.log.1 1710535 /var/log/daemon.log 596240 /var/log/syslog.1 521091 /var/log/syslog 19905 /var/log/daemon.log.2.gz 15803 /var/log/syslog.4.gz 15187 /var/log/syslog.5.gz 14598 /var/log/syslog.7.gz 14595 /var/log/syslog.6.gz 14545 /var/log/syslog.3.gz 14496 /var/log/syslog.2.gz 1365 /var/log/messages.1 476 /var/log/kern.log.1 403 /var/log/messages 286 /var/log/lastlog 229 /var/log/auth.log.1 128 /var/log/syslog.1.gz 95 /var/log/auth.log 56 /var/log/wtmp 35 /var/log/debug.1 24 /var/log/faillog 19 /var/log/messages.2.gz 11 /var/log/kern.log.2.gz 3 /var/log/fsck 3 /var/log/debug.2.gz 3 /var/log/auth.log.2.gz 3 /var/log/apt 2 /var/log/kern.log 1 /var/log/sysstat 1 /var/log/dpkg.log 1 /var/log/dmesg 1 /var/log/alternatives.log 0 /var/log/debug 0 /var/log/btmp 

Nach meiner Lektüre der Dokumentation von journald.conf ist der Standardwert SystemKeepFree15% und SystemMaxuse10%. Ich verstehe nicht, warum diese so groß werden. Mein Root-Mount ist eigentlich nur 8 GB, also habe ich dies entdeckt, weil meine Rootfs-Nutzung tatsächlich 100% erreicht hat:

$ df Filesystem 1K-blocks Used Available Use% Mounted on /dev/root 7529518 7525422 0 100% / .... 

Ich kam mir vor, dass rsyslog derjenige sein könnte, der diese Dateien darunter schreibt, /var/logund es gibt einen Bestand /etc/ryslog.conf. Aber warum werden Dateien in einigen Fällen gedreht, aber nie gelöscht?

/etc/rsyslog.conf als Referenz:

$ cat /etc/rsyslog.conf  # /etc/rsyslog.conf Configuration file for rsyslog. # # For more information see # /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html   ################# #### MODULES #### #################  $ModLoad imuxsock # provides support for local system logging $ModLoad imklog # provides kernel logging support #$ModLoad immark # provides --MARK-- message capability  # provides UDP syslog reception #$ModLoad imudp #$UDPServerRun 514  # provides TCP syslog reception #$ModLoad imtcp #$InputTCPServerRun 514   ########################### #### GLOBAL DIRECTIVES #### ###########################  # # Use traditional timestamp format. # To enable high precision timestamps, comment out the following line. # $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat  # # Set the default permissions for all log files. # $FileOwner root $FileGroup adm $FileCreateMode 0640 $DirCreateMode 0755 $Umask 0022  # # Where to place spool and state files # $WorkDirectory /var/spool/rsyslog  # # Include all config files in /etc/rsyslog.d/ # $IncludeConfig /etc/rsyslog.d/*.conf   ############### #### RULES #### ###############  # # First some standard log files. Log by facility. # auth,authpriv.* /var/log/auth.log *.*;auth,authpriv.none -/var/log/syslog #cron.* /var/log/cron.log daemon.* -/var/log/daemon.log kern.* -/var/log/kern.log lpr.* -/var/log/lpr.log mail.* -/var/log/mail.log user.* -/var/log/user.log  # # Logging for the mail system. Split it up so that # it is easy to write scripts to parse these files. # mail.info -/var/log/mail.info mail.warn -/var/log/mail.warn mail.err /var/log/mail.err  # # Logging for INN news system. # news.crit /var/log/news/news.crit news.err /var/log/news/news.err news.notice -/var/log/news/news.notice  # # Some "catch-all" log files. # *.=debug;\ auth,authpriv.none;\ news.none;mail.none -/var/log/debug *.=info;*.=notice;*.=warn;\ auth,authpriv.none;\ cron,daemon.none;\ mail,news.none -/var/log/messages  # # Emergencies are sent to everybody logged in. # *.emerg :omusrmsg:*  # # I like to have messages displayed on the console, but only on a virtual # console I usually leave idle. # #daemon,mail.*;\ # news.=crit;news.=err;news.=notice;\ # *.=debug;*.=info;\ # *.=notice;*.=warn /dev/tty8  # The named pipe /dev/xconsole is for the `xconsole' utility. To use it, # you must invoke `xconsole' with the `-file' option: #  # $ xconsole -file /dev/xconsole [...] # # NOTE: adjust the list below, or you'll go crazy if you have a reasonably # busy site.. # daemon.*;mail.*;\ news.err;\ *.=debug;*.=info;\ *.=notice;*.=warn |/dev/xconsole 

(nichts unter /etc/rsyslog.d/)

Stock conf bei /etc/systemd/journald.conf:

# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Entries in this file show the compile time defaults. # You can change settings by editing this file. # Defaults can be restored by simply deleting this file. # # See journald.conf(5) for details.  [Journal] #Storage=auto #Compress=yes #Seal=yes #SplitMode=uid #SyncIntervalSec=5m #RateLimitIntervalSec=30s #RateLimitBurst=1000 #SystemMaxUse= #SystemKeepFree= #SystemMaxFileSize= #SystemMaxFiles=100 #RuntimeMaxUse= #RuntimeKeepFree= #RuntimeMaxFileSize= #RuntimeMaxFiles=100 #MaxRetentionSec= #MaxFileSec=1month #ForwardToSyslog=yes #ForwardToKMsg=no #ForwardToConsole=no #ForwardToWall=yes #TTYPath=/dev/console #MaxLevelStore=debug #MaxLevelSyslog=debug #MaxLevelKMsg=notice #MaxLevelConsole=info #MaxLevelWall=emerg 

Und ich habe tatsächlich eine Datei unter journald.conf.d hinzugefügt:

$ cat /etc/systemd/journald.conf.d/custom.conf  # See: https://www.freedesktop.org/software/systemd/man/journald.conf.html # vi: ft=dosini  [Journal] MaxFileSec=0 SystemMaxUse=5M Compress=yes # Uncomment this to never write to FS: #Storage=volatile 

Es findet also eine gewisse Rotation statt, die jedoch nicht konsequent ist und nicht auf das festgelegt ist, was Journald sagt, dass es sein sollte.

Hinweis Ich verwende systemd-230 von jessie-backports.

Fragen

  • Was dreht die Dateien schon?
  • Warum wird die Gesamtnutzung nicht erwartungsgemäß begrenzt?
  • Schreibt Journald tatsächlich diese Dateien oder ist es RSYSLOG? (Ich sehe eigentlich keinen anderen Ort, an /vardem Journald Daten speichert, binär oder anderweitig.)
  • Kann ich in rsyslog config Dateigrößenbeschränkungen festlegen?
  • Benötige ich eine Logrotate, um dies für mich zu tun? Ich würde es vorziehen, wenn journald oder rsyslogd dies direkt handhaben könnte.

Vielen Dank!

Update Obwohl in der Dokumentation ForwardToSyslog=novon journald.conf standardmäßig vorgeschlagen wird, näher auf die von mir veröffentlichte Aktie journald.conf hinzuweisen, wird behauptet, dass der Standardwert "compiliert" ist ForwardToSyslog=yes. Es sieht also so aus, als ob Rsyslog seine Sache tut/var/log

0

1 Antwort auf die Frage

1
ivanivan

logrotatedverwaltet diese Protokolle (für rsyslog und andere). Aber ... Sie sehen ständig dieselben Dateinamen, so dass Sie vielleicht denken. Die Standardkonfiguration enthält 4 oder 7 alte Protokolle und das aktuelle Protokoll. Hier ist die Standardkonfiguration - Sie können sehen, dass / var / log / syslog 7 und das aktuelle Protokoll enthält, die anderen 4.

debian@templatevm:~$ cat /etc/logrotate.d/rsyslog  /var/log/syslog { rotate 7 daily missingok notifempty delaycompress compress postrotate invoke-rc.d rsyslog rotate > /dev/null endscript }  /var/log/mail.info /var/log/mail.warn /var/log/mail.err /var/log/mail.log /var/log/daemon.log /var/log/kern.log /var/log/auth.log /var/log/user.log /var/log/lpr.log /var/log/cron.log /var/log/debug /var/log/messages { rotate 4 weekly missingok notifempty compress delaycompress sharedscripts postrotate invoke-rc.d rsyslog rotate > /dev/null endscript } 

Wenn Sie nur basierend auf der Größe drehen möchten, ändern Sie den dailyParameter in den Bereich, size NNNNin dem N eine Größe mit einer Größe von 100 M hat - also size 100Mauf 100 MB

Wenn Ihre Protokolldateien dazu neigen, schnell zu wachsen, können Sie die Häufigkeit ändern, wie oft logrotate-Überprüfungen durchgeführt werden, indem Sie den symbolischen Link /etc/cron.hourlyanstelle von einfügen/etc/cron.daily

So /etc/logrotate.d/rsyslogkönnte Ihre neue Datei aussehen

/var/log/syslog { rotate 7 daily missingok notifempty delaycompress compress postrotate invoke-rc.d rsyslog rotate > /dev/null endscript }  /var/log/mail.info /var/log/mail.warn /var/log/mail.err /var/log/mail.log /var/log/daemon.log /var/log/kern.log /var/log/auth.log /var/log/user.log /var/log/lpr.log /var/log/cron.log /var/log/debug /var/log/messages { rotate 4 size 25M missingok notifempty compress delaycompress sharedscripts postrotate invoke-rc.d rsyslog rotate > /dev/null endscript }  
Ah irgendwie habe ich das vermisst; "welches logrotate" lässt mich glauben, dass es nicht installiert wurde, weil ich "sudo which .." nicht gemacht habe! Vielen Dank. Die standardmäßige logrotate-Konfiguration hat also keine Größenbegrenzung - aber ich weiß zumindest, wo ich sie hinzufügen muss. Vielen Dank! Thom Nichols vor 6 Jahren 0
Ja, Sie können vor dem Drehen eine maximale Größe angeben, usw. Wenn Sie dies tun möchten, können Sie die Häufigkeit des Aufrufens von Logrotate erhöhen ... Ich habe eine PHP-Klasse gelehrt und natürlich hätten die Schüler Fehler in endlosen Schleifen, die dazu führen Ich würde das Laufwerk mit Protokolldateien füllen und den Klassenserver unbrauchbar machen, also begann ich Größenbegrenzungen vorzunehmen und jede Stunde per cron auf Rotation zu prüfen / zu prüfen. Ich werde zurückgehen und meine Antwort bearbeiten, um Informationen dazu hinzuzufügen ... ivanivan vor 6 Jahren 1
Großartig! Das ist alles wirklich unkompliziert. Mein Hauptgrund für die Verwirrung war, zu glauben, dass Logrotate nicht installiert war, und ich habe die Konfigurationsdateien bereits in `/ etc / logrotate.d /` nicht bemerkt - ich denke, die Standardannahme ist, dass Ihre Dateien nicht verwendet werden Tanken Sie so schnell, dass Sie 7 Tage lang keine Protokolle verarbeiten können! Thom Nichols vor 6 Jahren 0