squid log files mit cron und logrotate regelmässig entfernen

piotr

Well-Known Member
Hallo

Ich habe freeBSD 6.1 und SQUID version 2.6.STABLE13:
Code:
bsd# uname -a
FreeBSD bsd.ch.bluee.net 6.1-RELEASE FreeBSD 6.1-RELEASE #0: Sun May  7 04:32:43 UTC 2006     root@opus.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386
bsd# squid -v
Squid Cache: Version 2.6.STABLE13

Wie kann ich squid log files mit cron und logrotate älter als 1 woche regelmässig entfernen ?

Piotr
 
Zuletzt bearbeitet:
Mit:
squid -k rotate
läßt man die Protokolle rotieren und mit
rm /pfad/zu/squid/log/*
entfernt man alle Protokolldateien.
 
habe in squid.conf file:
Code:
logfile_rotate 7
und als root in crontab generiert:
Code:
04 5 * * *  /usr/local/sbin/squid -k rotate
 
Zuletzt bearbeitet:
andere Möglichkeit:

da ist ein sehr gutes Manual:

Managing Unix log files using logrotate:

http://teklimbu.wordpress.com/2007/10/16/managing-your-linuxunix-log-files-using-logrotate/


(1.) Make and Install from ports:

cd /usr/ports/sysutils/logrotate

(2.) Configure and Compile

make install clean

If all goes well, we are done and logrotate is installed.

(3.) Create a new logrotate.conf file.

vi /usr/local/etc/logrotate.conf

# Added the following to rotate Apache and Squid logs

# see “man logrotate” for details
# rotate log files weekly
#weekly
daily

# keep 4 weeks worth of backlogs
rotate 7

# send errors to root
#errors root

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
compress

# RPM packages drop log rotation information into this directory
include /usr/local/etc/logrotate.d

/var/log/lastlog {
monthly
rotate 12
}

# system-specific logs may be configured here

(4.) Create a directory for specific logrotate files

mkdir -p /usr/local/etc/logrotate.d

(5.) First, create a logrotate file for Squid to rotate it’s access.log files for 90 days and cache.log for 7 days.

cd /usr/local/etc/logrotate.d/

vi /usr/local/etc/logrotate.d/squid

#Copy and paste the following

/var/log/squid/access.log {
daily
rotate 90
copytruncate
compress
notifempty
missingok
}
/var/log/squid/cache.log {
daily
rotate 7
copytruncate
compress
notifempty
missingok
}

(6.) Create the necessary directories and files for logrotate and test and debug logrotate

mkdir /var/lib/

touch /var/lib/logrotate.status

/usr/local/sbin/logrotate -d /usr/local/etc/logrotate.conf
/usr/local/sbin/logrotate -f /usr/local/etc/logrotate.conf

(7.) Next, we will rotate and manage Apache logs

vi /usr/local/etc/logrotate.d/apache

#Add the following to rotate and manage Apache access_log and error_log for 30 days.

#Note: If your Apache logs may be in a different directory, simply change the directory.

/var/log/apache/access_log {
daily
rotate 30
copytruncate
compress
notifempty
missingok
}
/var/log/apache/error_log {
daily
rotate 30
copytruncate
compress
notifempty
missingok
}

If all goes well, that’s it. Your Apache and Squid logs should be rotated.

The last thing is to add an entry into crontab and letting the cron daemon rotate your Apache and Squid logs automatically.

(8.) Automating logrotate using crontab

vi /etc/crontab

#Add the following to rotate your logs at 1 AM in the morning

#Logrotate
0 1 * * * root /usr/local/sbin/logrotate /usr/local/etc/logrotate.conf > /dev/null 2>&1


schöne Feiertage !
Piotr
 
Zuletzt bearbeitet:
oder vielleicht ganz einfach folgende linie in /etc/newsyslog.conf hinzufügen:

/usr/local/squid/logs/*.log nobody:wheel 644 10 1024 * ZB /var/run/squid.pid 30
 
Zurück
Oben