QueueMetrics > Running QueueMetrics

Setting up Tomcat logrotation on CentOS

(1/1)

emilec:
This details my attempts at setting up logrotation on CentOS 5 for Tomcat when installed from the Loway repo. I believe this is an oversight in the Loway Tomcat deployment and I have created a feature request for this.

If you would like to setup Tomcat logrotation you can do the following:
# vi /etc/logrotate.d/qm-tomcat6

--- Code: ---/usr/local/queuemetrics/tomcat/logs/*.log {
    notifempty
    copytruncate
    daily
    size=+1024k   
    rotate 10
    compress
    missingok
}

/usr/local/queuemetrics/tomcat/logs/catalina.out {
    notifempty
    copytruncate
    dateext
    daily
    size=+1024k   
    rotate 10
    compress
    missingok
}
--- End code ---

If you want to get fancy you can make it take care of cleaning out temp files as well (or just do it from cron as you would normally)

--- Code: ---/usr/local/queuemetrics/tomcat/logs/catalina.out {
    notifempty
    copytruncate
    dateext
    daily
    size=+1024k
    rotate 10
    compress
    missingok
postrotate
       /bin/nice /usr/bin/find /usr/local/queuemetrics/tomcat/temp -type f -mtime +10 -exec /bin/rm {} \; > /dev/null
    endscript
}
--- End code ---

UPDATE: I have subsequently added size=+1024k to my suggestion as this seems to get past the logrotate.conf issues of only rotating logs weekly so you no longer have to follow the steps below (unless you want all your other system logs to rotate daily as well).

I also took some time to delve into the CentOS logrotation settings and would suggest some of the following changes depending on your needs. I found that even if I set the rotation to daily in qm-tomcat6 logrotate.conf overrides it to weekly.
# vi /etc/logrotate.conf
Set weekly to daily

--- Code: ---# rotate log files daily
daily
--- End code ---

Change the backlogs from 4 week to 14 days

--- Code: ---# keep 14 days worth of backlogs
rotate 14
--- End code ---

I like compressed logs

--- Code: ---# uncomment this if you want your log files compressed
compress

--- End code ---

By default logrotation runs at 4am. You can change this by editing /etc/crontab
Set it to 02:02

--- Code: ---02 2 * * * root run-parts /etc/cron.daily
--- End code ---

Additional reading:
http://articles.slicehost.com/2010/6/30/understanding-logrotate-on-centos-part-1
http://articles.slicehost.com/2010/6/30/understanding-logrotate-on-centos-part-2

Comments, suggestions and improvements welcome!  ;D

QueueMetrics:
That's very nice, can we add this to the QueueMetrics Advanced Configuration Manual?
 ;D

emilec:
Sure!  Just remember the karma  :P

emilec:
I have found that setting size=+1024k means you don't have to modify logrotate.conf (first post updated).

QueueMetrics:
+1  ;)

Navigation

[0] Message Index

Go to full version