tomcat分割日志并定时清除
配置方法
#安装crontab
yum install cronie -y
#每天凌晨1点1分执行(注意Llinux定时器的时间设置是从分开始,没有秒的)
echo "1 1 * * * /app/tomcat/logs/dellog.sh " >> /var/spool/cron/root
dellog.sh 内容
#!/bin/bash
#定义tomcat日志文件目录
log_path=/app/tomcat/logs
#定义当前日期
d=`date +%Y-%m-%d`
#定义15天前的日期
d15=`date -d'15 day ago' +%Y-%m-%d`
#跳转到tomcat日志文件夹,复制catalina.out到catalina.out.${d}.log
cd ${log_path} && cp catalina.out ${log_path}/catalina.out.${d}.log
#清空cat文件alina.out
echo > catalina.out
#删除15天前的catalina.out.${d15}.log
rm -rf ${log_path}/catalina.out.${d15}.log
find ${log_path} -mtime +15 -name "localhost_access_log.*" -exec rm -rf {} \;
find ${log_path} -mtime +15 -name "localhost.*" -exec rm -rf {} \;
find ${log_path} -mtime +15 -name "manager.*" -exec rm -rf {} \;
find ${log_path} -mtime +15 -name "catalina.*" -exec rm -rf {} \;
find ${log_path} -mtime +15 -name "host-manager.*" -exec rm -rf {} \;
参考博客
Linux 定期切割Tomcat catalina.out和清理log日志:https://www.cnblogs.com/wobuchifanqie/p/12790660.html
- 以下3个删除不包括 localhost_access_log.2020-07-26.txt 类型的
一键配置tomcat定期日志清理功能:http://www.manongjc.com/detail/8-dtdfxudowgnnpbq.html
超简单方式实现tomcat的catalina.out日志文件切割:https://blog.csdn.net/DaySurprise/article/details/88657479
关于tomcat切割catalina.out日志的三种方式:https://blog.csdn.net/woshiji594167/article/details/80923795