zoukankan      html  css  js  c++  java
  • 设置log rotation避免tomcat catalina.out文件增长过大

    创建logrotate配置文件

    $ vi /etc/logrotate.d/tomcat
    

    添加以下内容:

    /opt/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/logrotate.d/tomcat
    

      

    也可以顺便将tomcat的临时文件删除掉:

    /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
    }
    

      

  • 相关阅读:
    SharePoint与RMS集成中关于权限的一个技术点
    SharePoint Alert
    SharePoint Explorer View
    在查看network traffic的时候, TCP Chimney offload的影响
    SharePoint Profile Import
    为SharePoint添加Event Receiver
    通过Telnet来发送邮件
    如何查看扩展出来的web application?
    Windows Host 文件
    Wscript.Shell 对象详细介绍
  • 原文地址:https://www.cnblogs.com/abclife/p/6278273.html
Copyright © 2011-2022 走看看