設定log rotation避免tomcat catalina.out檔案增長過大

來源:互聯網
上載者:User

標籤: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檔案增長過大

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.