Logrotate rotiert und schreibt alte Log weiter voll

Alle weiteren Dienste, die nicht in die drei oberen Foren gehören.
Antworten
weasel3456
Beiträge: 2
Registriert: 10.05.2013 09:52:40

Logrotate rotiert und schreibt alte Log weiter voll

Beitrag von weasel3456 » 10.05.2013 10:23:49

Hallo!

Ich betreibe einen Homeserver auf einem Igel Thin Clienten mit C7 CPU.
Vor ein paar Tagen habe ich ein Upgrade von Debian Spueeze 6.0.7 auf Wheezy 7.0 gemacht, alles lief soweit ohne Fehler, doch mein Logrotate möchte einfach nicht korrekt Arbeiten! Das ganze hat bis zu dem Upgrade auf Wheezy wunderbar funktioniert!

Und zwar ist mir aufgefallen das die Logdatei "syslog" auf über 10 MB anwächst, obwohl ich angegeben habe das sie nicht mehr als 8 MB haben sollte. Das ganze geht mit fast allen Logdateien so. Die Logdateien vom Apache2 werden wie sie sollten Rotiert und laufen dann in eine apache2_error.log.1 über und es wird eine neue apache2_error.log erstellt in der weiter geschrieben wird.
Bei der syslog ist es so das zwar bei 8 MB größe eine neue syslog erstellt wird, doch wird einfach weiter in die syslog.1 weiter geschrieben so das sie immer weiter anwächst.

Natürlich habe ich mich selbst schon auf Fehlersuche begeben. Da wollte ich mal Logrotate neu Installieren, doch es war garnicht Installiert! Also habe ich es Installiert mit dem Dienst anachron. Doch keinerlei Abhilfe!

Ganz Schalu daraus werde ich einfach nicht. Im CRON sind auch einige Einträge doch ob die so richtig sind kann ich nicht sagen. Ich Poste hier mal so ziemlich alles von dem ich denke das es Helfen könnte.

Die CRON.Hourly

Code: Alles auswählen

#!/bin/sh

test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf
Der Befehl: "logrotate -d /etc/logrotate.conf" gibt aus:

Code: Alles auswählen

reading config file /etc/logrotate.conf
including /etc/logrotate.d
reading config file apache2
reading config file apt
reading config file aptitude
reading config file dpkg
reading config file exim4-base
reading config file exim4-paniclog
reading config file fail2ban
reading config file rsyslog

Handling 14 logs

rotating pattern: /var/log/apache2/*.log  weekly (2 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/apache2/access.log
  log does not need rotating
considering log /var/log/apache2/error.log
  log does not need rotating
considering log /var/log/apache2/other_vhosts_access.log
  log does not need rotating
not running prerotate script, since no logs will be rotated
not running postrotate script, since no logs were rotated

rotating pattern: /var/log/apt/term.log  monthly (2 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/apt/term.log
  log does not need rotating

rotating pattern: /var/log/apt/history.log  monthly (2 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/apt/history.log
  log does not need rotating

rotating pattern: /var/log/aptitude  monthly (2 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/aptitude
  log /var/log/aptitude does not exist -- skipping

rotating pattern: /var/log/dpkg.log  monthly (2 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/dpkg.log
  log does not need rotating

rotating pattern: /var/log/alternatives.log  monthly (2 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/alternatives.log
  log does not need rotating

rotating pattern: /var/log/exim4/mainlog /var/log/exim4/rejectlog  after 1 days (1 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/exim4/mainlog
considering log /var/log/exim4/rejectlog

rotating pattern: /var/log/exim4/paniclog  1048576 bytes (1 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/exim4/paniclog

rotating pattern: /var/log/fail2ban.log  weekly (3 rotations)
empty log files are rotated, old logs are removed
considering log /var/log/fail2ban.log
  log does not need rotating
not running postrotate script, since no logs were rotated

rotating pattern: /var/log/syslog
 1048576 bytes (1 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/syslog
  log does not need rotating
not running postrotate script, since no logs were rotated

rotating pattern: /var/log/rsyslog
/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/cronauth.log
/var/log/messages
 1048576 bytes (1 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/rsyslog
  log /var/log/rsyslog does not exist -- skipping
considering log /var/log/mail.info
  log does not need rotating
considering log /var/log/mail.warn
  log does not need rotating
considering log /var/log/mail.err
  log does not need rotating
considering log /var/log/mail.log
  log /var/log/mail.log does not exist -- skipping
considering log /var/log/daemon.log
  log /var/log/daemon.log does not exist -- skipping
considering log /var/log/kern.log
  log /var/log/kern.log does not exist -- skipping
considering log /var/log/auth.log
  log does not need rotating
considering log /var/log/user.log
  log /var/log/user.log does not exist -- skipping
considering log /var/log/lpr.log
  log /var/log/lpr.log does not exist -- skipping
considering log /var/log/cron.log
  log /var/log/cron.log does not exist -- skipping
considering log /var/log/debug
  log /var/log/debug does not exist -- skipping
considering log /var/log/cronauth.log
  log does not need rotating
considering log /var/log/messages
  log does not need rotating
not running postrotate script, since no logs were rotated
not running postrotate script, since no logs were rotated
not running postrotate script, since no logs were rotated
not running postrotate script, since no logs were rotated

rotating pattern: /var/log/wtmp  monthly (1 rotations)
empty log files are rotated, old logs are removed
considering log /var/log/wtmp
  log does not need rotating

rotating pattern: /var/log/btmp  monthly (1 rotations)
empty log files are rotated, old logs are removed
considering log /var/log/btmp
  log /var/log/btmp does not exist -- skipping
Im Ordner /etc/logrotate.d/rsyslog sind noch ein paar mehr Dateien, doch nur die rsyslog Interessiert hier:

Code: Alles auswählen

/var/log/syslog
{
	rotate 1
	size 1M
	missingok
	notifempty
	delaycompress
	compress
	postrotate
		invoke-rc.d rsyslog reload > /dev/null
	endscript
}

/var/log/rsyslog
/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/cronauth.log
/var/log/messages
{
	rotate 1
	size 1M
	missingok
	notifempty
	compress
	delaycompress
	sharedscripts
	postrotate
		invoke-rc.d rsyslog reload > /dev/null
	endscript
}
Ja, ich habe die Log´s mal auf 1 MB beschränkt damit es schneller zum rotieren kommt. (Was aber nicht funktioniert)

Es scheint mir das ich wenn ich per Hand einen Logrotate anstoße alles läuft. Doch will es einfach nicht über den Crontab laufen.

Leider bin ich "noch" nicht so bewandert in Linux Systemen, (deshalb nur der Homeserver) aber ich will es werden. Ich habe dieses Betriebssystem lieben gelernt. Doch das hier Nervt mich obwohl es auch eine herrausvorderung für mich ist da ich den Fehler ja wunderbar selbst suchen sollte.
Aber ich komme einfach nicht mehr weiter, ich vermute der Fehler liegt irgendwo im CRON. Habt ihr eine Idee was da los ist?

Liebe Grüße!

P.S.

Hier noch ein Log aus messeges:

Code: Alles auswählen

May  9 21:40:59 server rsyslogd: [origin software="rsyslogd" swVersion="5.8.11" x-pid="29460" x-info="http://www.rsyslog.com"] rsyslogd was HUPed
May 10 10:06:30 server rsyslogd: [origin software="rsyslogd" swVersion="5.8.11" x-pid="29460" x-info="http://www.rsyslog.com"] rsyslogd was HUPed
Ich kann aber auch keinen Eintrag in der syslog Entdecken der rsyslog oder logrotate als CRON verarbeitet. Nur exim4 schreit da etwas rum, was ich aber später noch beheben werde.

Die crontab: (auszug)

Code: Alles auswählen

17 *	* * *	root    cd / && run-parts --report /etc/cron.hourly
25 6	* * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6	* * 7	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6	1 * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
Da fällt mir eben noch ein. Meine /var/log/ läuft in einer TMPFS. Um die CF Karte als Festplattenersatz zu schonen.


Die Ausgabe von: logrotate -f /etc/logrotate.d/rsyslog

Code: Alles auswählen

Usage: /etc/init.d/rsyslog {start|stop|rotate|restart|force-reload|status}
invoke-rc.d: initscript rsyslog, action "reload" failed.
error: error running non-shared postrotate script for /var/log/syslog of '/var/log/syslog
'
Usage: /etc/init.d/rsyslog {start|stop|rotate|restart|force-reload|status}
invoke-rc.d: initscript rsyslog, action "reload" failed.
error: error running shared postrotate script for '/var/log/rsyslog
/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/cronauth.log
/var/log/messages
'

rendegast
Beiträge: 15041
Registriert: 27.02.2006 16:50:33
Lizenz eigener Beiträge: MIT Lizenz

Re: Logrotate rotiert und schreibt alte Log weiter voll

Beitrag von rendegast » 10.05.2013 12:07:36

Bei der syslog ist es so das zwar bei 8 MB größe eine neue syslog erstellt wird, doch wird einfach weiter in die syslog.1 weiter geschrieben so das sie immer weiter anwächst.
Kontrolle 'lsof | grep var/log'.
Die Dateien sind geöffnet.
wenn Du mit einem anderen Tool als rsyslog darauf zugreifst, dazu gehören logrotate oder Deine "Verschiebung",
bleibt der Zugriff dennoch erhalten.

Aus dem Grund steht in den logrotate.conf ja auch sowas:
postrotate
invoke-rc.d rsyslog reload > /dev/null
endscript
Bei der syslog ist es so das zwar bei 8 MB
Wenn Deine Datei so stark anwächst, stimmt da was nicht?
Bei normaler Zuwachsrate hast Du das Problem schon eine Weile schleifen lassen.
Oder Problemfälle lassen die Datei sehr schnell anwachsen -> mal in die Logdatei reinschauen,
eventuelle debug-Schalter wieder deaktivieren.



Die CRON.Hourly
/var/log/syslog
{
rotate 1
size 1M
missingok
notifempty
delaycompress
compress
postrotate
invoke-rc.d rsyslog reload > /dev/null
endscript
}
Deine Konfig an sich funktioniert, es gäbe dann aber nur
/var/log/syslog
/var/log/syslog.1
und keine komprimierten Exemplare, da diese erst als *.2.gz entstünden.

Damit hättest Du aber auch immer nur Rückblick auf die letzten 1-2MB des Log.
Logdateien lassen sich sehr gut komprimieren, Faktor 10.
Ich würde da eher sowas ansetzen

Code: Alles auswählen

...
   rotate 10
   size 100k
   missingok
   notifempty
   delaycompress
   compress
...
Da fällt mir eben noch ein. Meine /var/log/ läuft in einer TMPFS. Um die CF Karte als Festplattenersatz zu schonen.
Log-Dateien sind im Fehlerfall interessant.
Mit der Methode hast Du gute Chancen, daß dann gar keine Logs bereitstehen.
-> Logs auf einen USB-Stick?
mfg rendegast
-----------------------
Viel Eifer, viel Irrtum; weniger Eifer, weniger Irrtum; kein Eifer, kein Irrtum.
(Lin Yutang "Moment in Peking")

weasel3456
Beiträge: 2
Registriert: 10.05.2013 09:52:40

Re: Logrotate rotiert und schreibt alte Log weiter voll

Beitrag von weasel3456 » 10.05.2013 13:00:29

Hallo! Erst einmal vielen Dank für deine Ausführliche Antwort!
Das hat mir schon sehr viel weiter geholfen.
Doch jetzt ist mir mal aufgefallen das dieses "invoke-rc.d rsyslog reload" wohl nicht ganz funktioniert hat, weil der Befehl "reload" nicht Akzeptiert wird. Aus dem Reload habe ich ein "force-reload" gemacht. Und siehe da keine Fehlermeldung mehr!

Ob die Logs jetzt richtig rotiert werden muss ich noch sehen, aber ich bin guter dinge!

Kann es sein das die neueste Version aus Wheezy den einfachen "reload" Befehl nicht mehr annimmt wie noch unter Squeeze?!

Es sollte ja keinen Unterschied machen ob "reload" oder "force-reload".

Das mit den Logs auf einem USB Stick werde ich die Tage mal machen. Es sollte ja möglich sein die im RAM zu halten und alle paar Minuten auf den Stick zu Schreiben.

rendegast
Beiträge: 15041
Registriert: 27.02.2006 16:50:33
Lizenz eigener Beiträge: MIT Lizenz

Re: Logrotate rotiert und schreibt alte Log weiter voll

Beitrag von rendegast » 10.05.2013 13:07:50

weasel3456 hat geschrieben: "invoke-rc.d rsyslog reload" wohl nicht ganz funktioniert hat, weil der Befehl "reload" nicht Akzeptiert wird. Aus dem Reload habe ich ein "force-reload" gemacht.

In der logrotade.d/rsyslog (wheezy) steht ja auch:

Code: Alles auswählen

                invoke-rc.d rsyslog rotate > /dev/null
Und das ist durchaus gültig:

Code: Alles auswählen

# invoke-rc.d rsyslog reload
Usage: /etc/init.d/rsyslog {start|stop|rotate|restart|force-reload|status}
invoke-rc.d: initscript rsyslog, action "reload" failed.
mfg rendegast
-----------------------
Viel Eifer, viel Irrtum; weniger Eifer, weniger Irrtum; kein Eifer, kein Irrtum.
(Lin Yutang "Moment in Peking")

Antworten