Linux – Apache log files rotation

apache-2.2linux

I have /etc/logrotate.d directory populated with files; each service, such as httpd, gets it's own logrotate config file.

The contents in the /etc/logrotate.d dir are configured to rotate after 5k.

I also have a /etc/logrotate.conf file which is not in cron yet. It's configured to:
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 { monthly create 0664 root utmp minsize 1M rotate 1 }

Below is a typical config file in the /etc/logrotate.d/ directory:

/var/log/httpd/*log { size 5k 
missingok 
notifempty 
sharedscripts 
compress 
sharedscripts 
postrotate /sbin/service httpd reload > /dev/null 2>/dev/null || true endscript }

My questions is where else on the server that I have to configure so that the files in
the /etc/logrotate.d directory are rotated after 5k. And that /etc/logrotate.conf is configured to rotate as configured?

Best Answer

That all looks good to me. You shouldn't have to change anything at all. Once logrotate starts getting executed things should start getting rotated as expected. One caveat is that it may take one full rotation cycle before things actually start getting rotated. There are built-in safeguards to prevent rotating a file too often. You can monitor the process by checking out the logrotate state file: /var/lib/logrotate.status. It contains a list of all files that logrotate is managing and when each one was last rotated.