標籤:name add 定時任務 內容 tomcat tom 配置 設定檔 就會
建立logrotate設定檔
$ vi /etc/logrotate.d/tomcat
添加以下內容:
/opt/entermediadb/tomcat/logs/catalina.out { copytruncate daily rotate 7 compress missingok dateext size 100m }
參數說明:
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,該檔案每天都會被運行。運行時會調用:
/usr/sbin/logrotate /etc/logrotate.conf
這樣就會rotate掉tomcat的日誌。
如果有多個tomcat執行個體,就需要配置多個單獨的rotation檔案。
也可以手動編寫定時任務:
2 * * * * /usr/sbin/logrotate /etc/mylogrotate.d/tomcat
設定log rotation避免tomcat catalina.out檔案增長過大