November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Tomcat log cutting and regular deletion

Tomcat log cutting and regular deletion

In Tomcat’s software environment, if we allow log files to grow indefinitely, one day the disk is full (crap).
Especially in the case of log file growth is very fast, cutting log files by log and delete, is a very necessary work, the following describes the method of cutting log files.

[root@server1 ~]# cat /etc/RedHat-release
CentOS release 6.5 (Final)
[root@server1 ~]# uname -r
2.6.32-431.el6.x86_64
[root@server1 ~]# uname -m
x86_64

[root@server1 ~]# java -version
java version “1.7.0_67”
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) Server VM (build 24.65-b04, mixed mode)

[root@server1 ~]# /opt/gw/tomcat7/bin/catalina.sh version
Using CATALINA_BASE: /opt/gw/tomcat7
Using CATALINA_HOME: /opt/gw/tomcat7
Using CATALINA_TMPDIR: /opt/gw/tomcat7/temp
Using JRE_HOME: /usr/local/jdk1.7
Using CLASSPATH: /opt/gw/tomcat7/bin/bootstrap.jar:/opt/gw/tomcat7/bin/tomcat-juli.jar
Server version: Apache Tomcat/7.0.57
Server built: Nov 3 2014 08:39:16 UTC
Server number: 7.0.57.0
OS Name: Linux
OS Version: 2.6.32-431.el6.x86_64
Architecture: i386
JVM Version: 1.7.0_67-b01
JVM Vendor: Oracle Corporation

cd /usr/local/src
wget https://files.cnblogs.com/files/crazyzero/cronolog-1.6.2.tar.gz
[root@mohan src]# md5sum cronolog-1.6.2.tar.gz
a44564fd5a5b061a5691b9a837d04979 cronolog-1.6.2.tar.gz

[root@mohan src]# tar xf cronolog-1.6.2.tar.gz
[root@mohan src]# cd cronolog-1.6.2
[root@mohan cronolog-1.6.2]# ./configure
[root@mohan cronolog-1.6.2]# make && make install
[root@mohan cronolog-1.6.2]# which cronolog
/usr/local/sbin/cronolog

[root@server1 ~]# which cronolog
/usr/local/sbin/cronolog

Chapter 3 configuration tomcat log cutting
Configuration log cutting, simply modify the configuration file catalina.sh (if windows is catalina.bat, here does not introduce the case of windows) can be.
Probably in the catalina file on the 380th and 390th lines, amended as follows:

org.apache.catalina.startup.Bootstrap “$@” start \
>> “$CATALINA_OUT” 2>&1 “&”

org.apache.catalina.startup.Bootstrap “$@” start \
2>&1 |/usr/local/sbin/cronolog “$CATALINA_BASE/logs/catalina-%Y-%m-%d.out” &

org.apache.catalina.startup.Bootstrap “$@” start \
>> “$CATALINA_OUT” 2>&1 “&”

org.apache.catalina.startup.Bootstrap “$@” start \
2>&1 |/usr/local/sbin/cronolog “$CATALINA_BASE/logs/catalina-%Y-%m-%d.out” &

00 00 * * * /bin/find /opt/gdyy/tomcat7/logs/ -type f -mtime +7 | xargs rm -f &>/dev/null

remove gw log 7 days ago by liutao at 2018-02-08
00 00 * * * /bin/find /opt/gw/tomcat7/logs/ -type f -mtime +7 | xargs -i mv {} /data/bak/gw_log/ &>/dev/null

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>