Subject: Logrotate configuration file
Author: AwsEC2
In response to: How to Rotate Apache Log Files in AWS Linux EC2 Instance
Posted on: 09/06/2012 02:13:52 AM
A simple configuration file looks like this:
# sample logrotate configuration file compress
/var/log/messages {
rotate 5
weekly
postrotate
/sbin/killall -HUP syslogd
endscript
}
"/var/log/httpd/access.log" /var/log/httpd/error.log {
rotate 5
mail www@my.org
size=100k
sharedscripts
postrotate
/sbin/killall -HUP httpd
endscript
}
/var/log/news/news.crit {
monthly
rotate 2
olddir /var/log/news/old
missingok
postrotate
kill -HUP cat /var/run/inn.pid
endscript
nocompress
}
The first section of the config files defined how to handle the log file
/var/log/messages. The log will go through five weekly rotations before being removed. After the log file has been rotated (but before the old version of the log has been compressed), the command
/sbin/killall -HUP syslogd will be executed.
The next section defines the parameters for both
/var/log/httpd/access.log and
/var/log/httpd/error.log. They are rotated whenever is grows over 100k is size, and the old logs files are mailed (uncompressed) to www@my.org after going through 5 rotations, rather then being removed. The sharedscripts means that the postrotate script will only be run once(after the old logs have been compressed), not once for each log which is rotated. Note that the double quotes around the first filename at the beginning of this section allows logrotate to rotate logs with spaces in the name. Normal shell quoting rules apply, with , ", and \ characters supported.
The last section defines the parameters for all of the files in /var/log/news. Each file is rotated on a monthly basis. This is considered a single rotation directive and if errors occur for more then one file, the log files are not compressed.
Please use wildcards with caution. If you specify *, logrotate will rotate all files, including previously rotated ones. A way around this is to use the olddir directive or a more exact wildcard (such as *.log).
>
> On 09/06/2012 02:10:31 AM
AwsEC2 wrote:
On even a moderately busy server, the quantity of information stored in the log files is very large. The access log file typically grows 1 MB or more per 10,000 requests. It will consequently be necessary to periodically rotate the log files by moving or deleting the existing logs. This cannot be done while the server is running, because Apache will continue writing to the old log file as long as it holds the file open. Instead, the server must be restarted after the log files are moved or deleted so that it will open new log files.
A typical scenario that simply rotates the logs and compresses the old logs to save space is:
mv access_log access_log.old
mv error_log error_log.old
apachectl graceful
sleep 600
gzip access_log.old error_log.old
Another way to perform log rotation is using logrotate utility tool:
logrotate [-dv] [-f|--force] [-s|--state file] config_file+
References: