Solve the problem that Tomcat Catalina. Out keeps growing, leading to excessive Archives

Source: Internet
Author: User

Method 1-stream Separation

Use cronolog to split Tomcat's Catalina. Out Log File

Cronolog a small tool for log splitting, its home page in http://cronolog.org/(but found that this domain name has expired, you can download the http://download.csdn.net/detail/wayne173/8096321 here ),, we can also use it to split Apache logs.

This method is recommended as follows:

1. Download cronolog-1.6.2.tar.gz

2. Installation

# Tar zxvf cronolog-1.6.2.tar.gz
# Cronolog-1.6.2
# Cd configure
# Make
# Make install

Done!

Installed in/usr/local/sbin/by default.

3. Configuration

The point is. Note !!!

In tomcat/bin/catalian. Sh, find
Org. Apache. Catalina. startup. Bootstrap "[email protected]" Start \> "$ catalina_base"/logs/Catalina. out 2 & 1 &

Change the above content:
Org. Apache. Catalina. startup. Bootstrap "[email protected]" Start \
|/Usr/local/sbin/cronolog "$ catalina_base"/logs/Catalina. % Y-% m-% d. Out>/dev/null 2> & 1 &

Modified. Restart

#./Catalina. Sh start

Now let's take a look at the labor results.

# Ls/tomcat/logs/

You will find several more files under logs, such as catalina.2014.10.28.log. The Catalina. Out file also exists, but the size is always 0.


Method 2-script stream

After all, this is just a big file processing problem. It can be done with powerful Bash;
Use cron to back up the current Catalina. out every day, and then clear its content;

The reference script is as follows:

#! /Bin/sh
Y = 'date "+ % Y "'
M = 'date "+ % m "'
D = 'date "+ % d "'
CD/path/tomcat/logs
CP Catalina. out Catalina. Out. $ y $ M $ d
Echo
> Catalina. Out
Exit
Check whether the cron service in Linux is started, whether it works properly, and the script storage path (the reason is confidential for the moment)

Method 3-refer to the cumbersome stream

Open the Catalina. Sh file in the bin directory. After all, it is just a bash file,

Find out, Catalina. Out appears three times in total;

Part:


Shift

Touch "$ catalina_base"/logs/Catalina. Out

If ["$1" = "-Security"]; then

Echo "using security manager"

Shift

"$ _ Runjava" $ java_opts "$ logging_config" $ catalina_opts \

-Djava. endorsed. dirs = "$ java_endorsed_dirs"-classpath "$ classpath "\

-Djava. Security. Manager \

-Djava. Security. Policy = "$ catalina_base"/CONF/Catalina. Policy \

-Dcatalina. base = "$ catalina_base "\

-Dcatalina. Home = "$ catalina_home "\

-Djava. Io. tmpdir = "$ catalina_tmpdir "\

Org. Apache. Catalina. startup. Bootstrap "[email protected]" Start \

> "$ Catalina_base"/logs/Catalina. out 2> & 1 &


If [! -Z "$ catalina_pid"]; then

Echo $! > $ Catalina_pid

Fi

Else

"$ _ Runjava" $ java_opts "$ logging_config" $ catalina_opts \

-Djava. endorsed. dirs = "$ java_endorsed_dirs"-classpath "$ classpath "\

-Dcatalina. base = "$ catalina_base "\

-Dcatalina. Home = "$ catalina_home "\

-Djava. Io. tmpdir = "$ catalina_tmpdir "\

Org. Apache. Catalina. startup. Bootstrap "[email protected]" Start \

> "$ Catalina_base"/logs/Catalina. out 2> & 1 &
In my opinion, this is where the Catalina. Out file is written. How can I write it to another empty device?

Note the backup of Catalina. Sh in the original file before modification ~!!

Modify

> "$ Catalina_base"/logs/Catalina. out 2> & 1 &
Is

>>/ DEV/null 2> & 1 &
Save and start Tomcat. Currently, this Catalina. Out is empty.

I think this method is brave and has not been tested in the production environment yet. Virtual Machine testing is successful.

Method 4-People Flow

In fact, this method is manually deleted by the Linux system administrator ";

It is best to stop Tomcat services before deleting them;

Solve the problem that Tomcat Catalina. Out keeps growing, leading to excessive Archives

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.