Howto logrotate

Not my own post, put placed here for reference:

Are you administering a Linux/Unix system that’s running out of space? Getting to grips with the logrotate utility can solve a lot of problems for you. Especially when talking about apache logs, your hard disk can fill up quite quickly if you’re running a few busy sites. Just as an example, a typical 100MB log file when gzipped reduces down to 5MB, so why not use logrotate to take keep your logs under control for you.Part of the reason for this tutorial is that Google seems to have little useful information on a search for logrotate with the exception of this brief overview.

The BasicsAll you have to know to manage your logs is 3 basic things:

1. the logrotate utility is installed by default in most Linux/Unix installations, mine on Redhat 7.3 is located at /usr/sbin/logrotate. It is often setup and running by default, but not always with the best configuration for your needs.
2. the generic logrotate configuration file can be found at /etc/logrotate.conf
3. log configurations for individual services are located in /etc/logrotate.d/ with a typical example being /etc/logrotate.d/apache

Logrotate.conf
A typical logrotate.conf file looks like this:

# 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
# 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 -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
rotate 1
}

Setting Paths for Individual Services

As mentioned before, you may want to customise the way logrotate processes the logs for, say, apache. This can be done by editing the /etc/logrotate.d/apache file and adding your own path directives to the existing list. A default config looks something like this:


/var/log/httpd/access_log /var/log/httpd/agent_log /var/log/httpd/error_log /var/log/httpd/referer_log {
missingok
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
endscript
}

Originally posted on: http://www.phpkitchen.com/index.php?/archives/292-HOWTO-logrotate.html

This entry was posted in Notes-to-self, Server. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>