Debian Tomcat日志清理频率建议
推荐频率与保留策略
| 日志类型 | 建议轮转频率 | 保留周期 | 触发条件 | 压缩与清理 |
|---|---|---|---|---|
| catalina.out | 每日 | 7–14天 | 同时设置size 100–200MB触发 | 启用compress,到期自动删除 |
| catalina/localhost 按日期日志 | 由JULI按日期自动生成 | 7–14天 | 无需额外触发 | 可配合find … -mtime +N清理 |
| localhost_access_log 访问日志 | 由AccessLogValve按日期生成 | 7–30天 | 无需额外触发 | 可配合find … -mtime +N清理 |
安全清理与自动化配置
/opt/tomcat/logs/catalina.out {
daily
rotate 14
copytruncate
compress
missingok
notifempty
size 100M
}
# 保留最近14天
0 2 * * * find /opt/tomcat/logs/ -type f -name "*.log" -mtime +14 -delete
0 2 * * * find /opt/tomcat/logs/ -type f -name "*.txt" -mtime +14 -delete
按负载与磁盘的微调
补充 减少日志量的配置
1catalina.org.apache.juli.AsyncFileHandler.level = WARNING
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs"
prefix="localhost_access_log"
suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />