How to control the size of the Tomcat catalina.out

 catalina.out file, the main source of data: information System.out and System.err directly on the console output.

Encoding should be avoided System.out.println () and e.printStackTrace (), as far as possible using the logging mechanism logs.

This article says that the use of cronolog tool to split the file catalina.out

1, the installation tool
provides two ways total
1) can directly use yum to install, simple, it is recommended to use this method, but the installation path need to look at with cronolog Which
yum -y install httpd cronolog

2) Download the source code to install
the official URL: http: //cronolog.org/download/index.html
Enter the following steps:
wget http://cronolog.org/download/cronolog-1.6.2.tar.gz
tar XF 1.6-cronolog .2.tar.gz
cd cronolog-1.6.2
./configure
the make the make install &&

With which cronolog installation path can be found, the default should be / usr / local / sbin / cronolog, this will be the path to be used when modifying catalina.sh.

2、修改Tomcat启动脚本catalina.sh
1)
修改:
 if [ -z "$CATALINA_OUT" ] ; then
       CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
fi
为:
    if [ -z "$CATALINA_OUT" ] ; then
      CATALINA_OUT="$CATALINA_BASE"/logs/catalina.%Y-%m-%d.out
fi

2) delete the log files are generated
comment:
Touch "$ CATALINA_OUT"
   as:
#touch "$ CATALINA_OUT"

3) Modify the startup script parameters, there should be two
modifications:
      org.apache.catalina.startup.Bootstrap "$ @" Start \
      >> "$ CATALINA_OUT" 2> & 1 "&"
is:     
org.apache.catalina.startup. Bootstrap "$ @" Start 2> & 1 \
| / usr / sbin / cronolog "$ CATALINA_OUT" >> / dev / null &

Note: / usr / sbin / cronolog the address you want to use to view the subject which cronolog

3, restart Tomcat
Tomcat log file output division successfully, the output log file format: catalina.2020-01-09.out type.

4, shell scripting , save the file to /home/java/auto_del_log.sh (address at random), the script reads as follows:
the Find / Home / the Java / Tomcat-ADMIN / logs -name "* the .out" The -type f -mtime + 30 -exec rm -rf {} \; > / dev / null 2> & 1

5 configuration cron , regularly delete automatically deletes older than 30 days out log files can be, if not cron, self Baidu install
crontab -e
add 0 3 * * * /home/java/auto_del_log.sh back to the task
: wq to save and exit

6 Last Best restart the cron task 

service crond restart

You're done, so never have to worry log becomes larger and larger, leading to the hard disk becomes full! ! !

 

Guess you like

Origin www.cnblogs.com/fj99/p/12172274.html