Tomcat log cutting and Regular deletion

Source: Internet
Author: User
Tags apache tomcat

Tomcat log cutting and Regular deletion

In the Tomcat software environment, if we allow unlimited growth of log files, the disk will be full one day (nonsense ). Especially when log files grow rapidly, it is necessary to cut and delete log files by log. The following describes how to cut log files.

Chapter 3 system environment
1.1 Operating System Environment
[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

1.2 jdk Environment
[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)

1.3 tomcat Environment
[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 # <== tomcat-7.5.57
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

Chapter 4 Cutting Tool cronolog
2.1 Introduction to cronolog
Cronolog is a filter program that reads log file entries from standard input and writes each entry to the output file specified by the file name template and the current log. When the extension file name changes, close the current file and open a new file. Cronolog is used with Web servers such as Apache to classify access logs into daily or monthly logs.

2.2 installing cronolog
2.2.1 download cronolog
Cd/usr/local/src
Wget https://files.cnblogs.com/files/crazyzero/cronolog-1.6.2.tar.gz
[Root @ kafka01 src] # md5sum cronolog-1.6.2.tar.gz
A44564fd5a5b061ada-1b9a837d04979 cronolog-1.6.2.tar.gz # <= cronolog MD5 code

2.2.2 compilation and Installation
[Root @ kafka01 src] # tar xf cronolog-1.6.2.tar.gz
[Root @ kafka01 src] # cd cronolog-1.6.2
[Root @ kafka01 cronolog-1.6.2] #./configure # <= compile, before the installation of cmake and other compilation tools
[Root @ kafka01 cronolog-1.6.2] # make & make install # <= Installation
[Root @ kafka01 cronolog-1.6.2] # which cronolog # <== check whether the installation is successful, if any, the installation is successful
/Usr/local/sbin/cronolog

2.3 cronolog command

[Root @ server1 ~] # Which cronolog
/Usr/local/sbin/cronolog # <= storage path of the cronolog command
Run the man help command to view cronolog usage Syntax:
[Root @ server1 ~] # Man cronolog
NAME
Cronolog-write log messages to log files named according to a template

SYNOPSIS
Cronolog [OPTION]... template

Chapter 4 configure tomcat log Cutting
To configure log cutting, you only need to modify the configuration file catalina. sh (for windows, the configuration file catalina. bat is used. windows is not described here. About 380th rows and 390th rows in the catalina file are modified as follows:

(1) content:

Org. apache. catalina. startup. Bootstrap "$ @" start \
> "$ CATALINA_OUT" 2> & 1 "&"

Replace:

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

(2) content:

Org. apache. catalina. startup. Bootstrap "$ @" start \
> "$ CATALINA_OUT" 2> & 1 "&"

Replace:

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

After the configuration is complete, restart tomcat !!!!

Chapter 4 regularly Delete expired logs
Here, we directly use the built-in crontab scheduled task tool in linux to execute the delete task at every day and delete the log files from the past seven days.

Crontab-e # <= directly enter this command to add a scheduled task plan
00 00 ***/bin/find/opt/gdyy/tomcat7/logs/-type f-mtime + 7 | xargs rm-f &>/dev/null # <= find the log files under tomcat/logs, delete the logs generated seven days ago. After adding the logs, save the logs and exit !!

[Root @ server1 ~] # Crontab-l # <= view scheduled task plans
# Remove gw log 7 days ago by liutao at 2012-02-08
00 00 ***/bin/find/opt/gw/tomcat7/logs/-type f-mtime + 7 | xargs-I mv {}/data/bak/gw_log /& >/dev/null

Tomcat logs are cut and regularly deleted !!!

This article permanently updates link: https://www.bkjia.com/Linux/2018-03/151187.htm

Related Article

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.