ts2009 发表于 2017-1-18 10:06:05

How to rotate tomcat logs

  If catalina.out becomes 2GB in size, tomcat crashes and fails to start without any error message. To avoid this scenario you should rotate catalina.out frequently. This article describes how to setup autorotation of catalina.out on a linux/unix machine.
How to automatically rotate catalina.out dail
  1. Create this file
1./etc/logrotate.d/tomcat


  2.Copy the following contents into the above file
/var/log/tomcat/catalina.out { 
copytruncate 
daily 
  dateext 

rotate 7 
compress 
missingok 
}


  About the above configuration:

[*]Make sure that the path /var/log/tomcat/catalina.outabove is adjusted to point to your tomcat’s catalina.out
[*]daily- rotates the catalina.out daily
[*]rotate– keeps at most 7log files
[*]compress –compressesthe rotated files
[*]dateext: 在归档文件后,将会使用日期进行标注。如果这参数不指定的话,归档文件将会标注为数字。
  You don’t need to do anything else.
How it works

[*]Every night the cron daemon runs jobs listed in the /etc/cron.daily/directory
[*]This triggers the /etc/cron.daily/logrotatefile which is generally shipped with linux installations. It runs the command“/usr/sbin/logrotate /etc/logrotate.conf“
[*]The /etc/logrotate.confincludes all scripts in the/etc/logrotate.d/ directory.
[*]Thistriggers the /etc/logrotate.d/tomcatfile thatyou wrote in the previous step.
Run logrotate manually
  Run the following command to run the cron job manually
1./usr/sbin/logrotate /etc/logrotate.conf


More logrotate options
  To see all logrotate options on your system, see the manual:
manlogrotate



你可以看到在 Tomcat 的日志目录下创建了一个文件:
-rw-rw-r-- 1 tomcat tomcat   133540 Jul 13 09:39 catalina.out-20110713
If no dateext specified, 如下面的内容:
-rw-rw-r-- 1 tomcat tomcat 33790228 Jul 13 09:33 catalina.out.1

  
页: [1]
查看完整版本: How to rotate tomcat logs