Tomcat 自动清理日志和缓存

  改方案针对apache-tomcat-9.0.17版本

1、catalina、host-manager、localhost、manager日志修改

  (1)在tomcat/conf/logging.properties文件下修改“maxDays”,系统默认是90天,对于高并发大访问量的服务,将保存的天数设置为最短。

  (2)将level级别设置成WARNING就可以大量减少日志的输出,一般日志的级别有: 
SEVERE (highest value) > WARNING > INFO > CONFIG > FINE > FINER > FINEST (lowest value),这里建议设置成“ WARNING”。

1catalina.org.apache.juli.AsyncFileHandler.level =  WARNING
1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.
1catalina.org.apache.juli.AsyncFileHandler.maxDays = 90
1catalina.org.apache.juli.AsyncFileHandler.encoding = UTF-8

2localhost.org.apache.juli.AsyncFileHandler.level =  WARNING
2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.
2localhost.org.apache.juli.AsyncFileHandler.maxDays = 90
2localhost.org.apache.juli.AsyncFileHandler.encoding = UTF-8

3manager.org.apache.juli.AsyncFileHandler.level =  WARNING
3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.AsyncFileHandler.prefix = manager.
3manager.org.apache.juli.AsyncFileHandler.maxDays = 90
3manager.org.apache.juli.AsyncFileHandler.encoding = UTF-8

4host-manager.org.apache.juli.AsyncFileHandler.level =  WARNING
4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager.
4host-manager.org.apache.juli.AsyncFileHandler.maxDays = 90
4host-manager.org.apache.juli.AsyncFileHandler.encoding = UTF-8

2、localhost_access_log日志禁用

  在tomcat/conf/server.xml文件中注释掉“localhost_access_log”日志生成

        

3、catalina.out日志禁用

  catalina.out与按天的catalina.xxxx.log重复,所以这里直接禁用。

  在tomcat/bin/catalina.sh中找到下面位置

if [ -z "$CATALINA_OUT" ] ; then
  CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out

   修改到dev/null,当路径不存在时,catalina.out日志也就被禁用

if [ -z "$CATALINA_OUT" ] ; then
  CATALINA_OUT="$CATALINA_BASE"/dev/null

4、清理tomcat缓存 

1.进入tomcat/bin目录下,执行sh shutdown.sh命令关闭tomcat。
2.然后执行命令 ps -aux | grep tomcat 命令​,查看tomcat命令是否真的关闭
3.如果没有关闭执行 kill -9 #pid 来彻底关闭tomcat(#pid是tomcat的进程ID)​
root    17505    0.0        0.0    63344  768    pts/1    S+  10:22  0:00 grep tomcat​
USER    PID    %CPU  %MEM  VSZ  RSS    TTY  STAT  START TIME COMMAND​
4.最后进入tomcat/work目录下​,执行 rm -rf Catalina 来删除缓存文件
5.执行ls ​确认是否删除,如果work目录下没有Catalina文件夹说明删除成功。
6.在进入tomcat/bin目录下,执行./startup.sh命令来重启tomcat。

  即停止tomcat、进入tomcat/work目录下​——>执行 rm -rf Catalina 来删除缓存文件——>启动tomcat = OK

你可能感兴趣的:(tomcat)