Linux/logrotate
< Linux
logrotate
logrotate - rotates, compresses, and mails system logs
Installation:
yum install logrotate vixie-cron crontab service crond restart
Configuration files are here:
/etc/cron.daily/logrotate /etc/logrotate.conf /etc/logrotate.d
Last rotate status is kept here:
/var/lib/logrotate.status
Kick off a rotate config:
logrotate -v /etc/logrotate.d/httpd
copytruncate
"To avoid the reload, instead of moving the file, you can copy it and empty the old file. That way apache can keep writing to the same filehandle. You do this by adding the option "copytruncate" to the logrotate config file, like this:"
/apache/*log { copytruncate compress dateext rotate 365 size=+300M olddir /log/old/apache notifempty missingok }
References:
- logrotate - How to avoid apache reload when rotating logs? - Unix & Linux Stack Exchange - http://unix.stackexchange.com/questions/47688/how-to-avoid-apache-reload-when-rotating-logs
CentOS HTTP Example
Suggested add:
/var/log/httpd/*log { size 100M compress ...
ln -s /etc/cron.daily/logrotate /etc/cron.hourly/logrotate
/etc/logrotate.d/httpd
/var/log/httpd/*log { missingok notifempty sharedscripts delaycompress postrotate /sbin/service httpd reload > /dev/null 2>/dev/null || true endscript }
/etc/logrotate.conf
# see "man logrotate" for details # rotate log files weekly weekly # keep 4 weeks worth of backlogs rotate 4 # create new (empty) log files after rotating old ones create # use date as a suffix of the rotated file dateext # uncomment this if you want your log files compressed #compress # RPM packages drop log rotation information into this directory include /etc/logrotate.d # no packages own wtmp and btmp -- we'll rotate them here /var/log/wtmp { monthly create 0664 root utmp minsize 1M rotate 1 } /var/log/btmp { missingok monthly create 0600 root utmp rotate 1 } # system-specific logs may be also be configured here.
/etc/cron.daily/logrotate
/usr/sbin/logrotate /etc/logrotate.conf >/dev/null 2>&1 EXITVALUE=$? if [ $EXITVALUE != 0 ]; then /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]" fi exit 0