Under Linux, Tomcat catalina.out files are too large and directory change resolution __linux

Source: Internet
Author: User

Method 1-Split stream

Using the Cronolog tool to slice Tomcat's catalina.out log files

Cronolog a small tool for log segmentation, whose homepage is in http://cronolog.org/, we can also use it to slice Apache logs.

This method is recommended in the following ways

Google first. cronolog-1.6.2.tar.gz

1. Download cronolog-1.6.2.tar.gz

2. Installation

# tar ZXVF cronolog-1.6.2.tar.gz
# cronolog-1.6.2/configure
# make
# make Install

Get!

The default is to install under/usr/local/sbin/.

3. Configure

Here's the point. NOTE!!!

Found in the tomcat/bin/catalian.sh.
Org.apache.catalina.startup.Bootstrap "$@" Start >> "$CATALINA _base"/logs/catalina.out 2&1 &

Change the above to read:
Org.apache.catalina.startup.Bootstrap "$@" Start \
|/usr/local/sbin/cronolog "$CATALINA _base"/logs/catalina.%y-%m-%d.out >>/dev/null 2>&1 &

It's all changed. Reboot

#./catalina.sh start

Now go and see the fruits of labor.

# ls/tomcat/logs/

You will find that there are a few more catalina.2006.06.01.log files under the logs.


Method 2-script stream

Things are just a big file deal problem, powerful bash to fix;
Use Cron to back up the current catalina.out every day, and then empty his 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
Note whether the Cron service on the Linux system is started, is working properly, and the location of the script (reason for temporary secrecy)

Method 3-wretched stream

Opening the catalina.sh file in the bin directory is just a bash file,

Find out, Catalina.out total appeared three times;

Partial screenshot:


Shift

Touch "$CATALINA _base"/logs/catalina.out

If ["$" = "-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 "$@" 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 "$@" Start \

>> "$CATALINA _base"/logs/catalina.out 2>&1 &
Personally think that is here is to write Catalina.out file, let him write to a other empty equipment how.

Notice the original file before the catalina.sh backup yo ~ ...

Modify the code in the above

>> "$CATALINA _base"/logs/catalina.out 2>&1 &
For

>>/dev/null 2>&1 &
Save, and then start Tomcat, now this catalina.out has been empty.

This method is I think of, personally think more courageous, at present has not been tested in the production environment. The virtual machine test is passed.

Method 4-crowd

This method is actually the Linux system Administrator manual to delete, manual operation, referred to as "people";

It is best to stop Tomcat services before removing them;

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.