设置log rotation避免tomcat catalina.out文件增长过大
2017-01-12 14:56 abce 阅读(2495) 评论(0) 编辑 收藏 举报创建logrotate配置文件
1 | $ vi /etc/logrotate.d/tomcat |
添加以下内容:
1 2 3 4 5 6 7 8 9 | /opt/tomcat/logs/catalina .out { copytruncate daily rotate 7 compress missingok dateext size 100m } |
参数说明:
1 2 3 4 5 6 7 8 | specify the path to the log file . copytruncate – creates a copy of the log file and then truncates the original to an empty file so that the service can keep on logging uninterrupted. daily – rotates the catalina.out daily. rotate – keeps at most 7 log files. compress – create a gzip compressed file of the rotated files. missingok – suppresses error messages if the file does not exist. dateext – add the date to the filename of the archived log file . size – rotates if the size of catalina.out is bigger than 100m. |
在大多数linux系统上都可以找到文件:/etc/cron.daily/logrotate,该文件每天都会被运行。运行时会调用:
1 | /usr/sbin/logrotate /etc/logrotate .conf |
这样就会rotate掉tomcat的日志。
如果有多个tomcat实例,就需要配置多个单独的rotation文件。
也可以手动编写定时任务:
1 | 2 * * * * /usr/sbin/logrotate /etc/logrotate .d /tomcat |
也可以顺便将tomcat的临时文件删除掉:
1 2 3 4 5 6 7 8 9 10 11 12 | /opt/tomcat/logs/catalina .out { notifempty copytruncate dateext daily rotate 10 compress missingok postrotate /bin/nice /usr/bin/find /opt/tomcat/temp - type f -mtime +10 - exec /bin/rm {} \; > /dev/null endscript } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
2016-01-12 python笔记-print输出
2016-01-12 python笔记-列表和元组
2016-01-12 python笔记-字符串