Combat Tomcat log file Catalina.out file too big problem

Source: Internet
Author: User

As the project runs, Tomcat's log file Catalina.out is growing in size and now has several gigabytes. If we do not do any processing, the Catalina.out file size will continue to increase, until the hard disk space of our system can be burst.


When Tomcat's log file Catalina.out size is larger than 2GB, the Tomcat program crashes with the possibility of a startup failure and no error message prompts. To avoid this scenario, we will periodically rotate the Catalina.out log file.


Here small white uses the Centos6u5 own logrotate program to solve the Catalina.out log rotation problem. This method is relatively simple. Create a new file named Tomcat under the/etc/logrotate.d/directory.

Cat >/etc/logrotate.d/tomcat <<eof/usr/local/apache-tomcat-8.0.28/logs/catalina.out{copytruncate Daily Rotate 7 Missingok Compress size 16m}eof


The above configuration description:

/usr/local/apache-tomcat-8.0.28/logs/catalina.out{# to rotate a file Copytruncate # After creating a new catalina.out copy, truncate the source Catalina.out file Dai LY # catalina.out files are rotated rotate 7 # at most 7 copies Missingok # If the files to be rotated are lost, keep rotating without error compress # Use compression (very useful , save hard disk space; A 2~3GB log file can be compressed to about 60MB) size 16M # When the Catalina.out file is larger than 16MB, rotate}


How does the above work?

    1. Every night the Crond daemon runs a list of tasks in the/etc/cron.daily directory;

    2. Scripts related to Logrotate are also in the/etc/cron.daily directory. The mode of operation is "/usr/bin/logrotate/etc/logrotate.conf";

    3. The/etc/logrotate.conf file include all files under the/etc/logrotate.d/directory. Also includes the Tomcat file we just created above;

    4. The/etc/logrotate.d/tomcat file will trigger the rotation of the/usr/local/apache-tomcat-8.0.28/logs/catalina.out file.



The above is the automatic completion of the program, do not need our intervention. Of course, we can also use the manual way to carry out the Logrotate program. Run the following on the command line:

Logrotate/etc/logrotate.conf

Or just rotate the tomcat configuration file just to run it:

Logrotate--force/etc/logrotate.d/tomcat


To get more help with the Logrotate program, you can view its man page,

Mans Logrotate


You can look at the file size before and after the catalina.out rotation,

Before rotation:

Du-sh * ... 2.0gcatalina.out # File size before rotation ...


File size after rotation:

# du-sh Catalina.out*2.0mcatalina.out60mcatalina.out.1.gz # After the rotation, compression, the log file becomes smaller


In addition to the Tomcat logs directory, a lot of log files are generated every day, we can also regularly manually or using scheduled tasks to delete the log files 7 days ago, here, using a manual way to demonstrate,

Cd/usr/local/apache-tomcat-8.0.28/logsfind-mtime +7-exec rm-f {} \;


All right, here we go. Hope to help the children in need of shoes.

This article is from the "solid-state Drive" blog, make sure to keep this source http://lavenliu.blog.51cto.com/5060944/1765791

Combat Tomcat log file Catalina.out file too big problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.