Centos logrotate truncate the log file tomcat

1. Set the rotated log file logrotate

tomcat log directory: /usr/local/tomcat/apache-tomcat-8.5.34/logs

Create a tomcat directory file /etc/logrotate.d/

we /etc/logrotate.d/tomcat

/usr/local/tomcat/apache-tomcat-8.5.34/logs/catalina.out {# rotary file

  After copytruncate # Create a new catalina.out, cut off the source file catalina.out

  daily # catalina.out file rotation carried out every day

  rotate 30 # reserved up to 30 copies

  missingok # If the rotary file is missing, continue to rotate without error

  Use compression compress #

  When the size 100M # files larger than 100M to rotate catalina.out  

}

: Wq save and exit

 

2. logrotate rotate tomcat error log file

error: error opening /usr/local/tomcat/apache-tomcat-8.5.34/logs/catalina.out: Permission denied

Error content will be sent to / var / spool / mail / root file via e-mail

we / var / spool / mail / root 

 

Error prompt is catalina.out file permissions problem, tomcat is copied from elsewhere over, catalina.out initial permissions to 644

chmod 666 catalina.out

Wait for the next cycle logrotate results

 

3. Hand Solution

logrotate /etc/logrotate.conf  

logrotate --force /etc/logrotate.d/tomcat  

Set the timer task:

crontab -e

30 0 * * * /sbin/logrotate --force /etc/logrotate.d/tomcat

 

4. Remarks

# Cutting large files, each 100M

split -b 100m catalina.out.1 catalina.out.1_

# Clean up 60 days prior to the log file

find -mtime +60 -exec rm -f {} \;

 

Guess you like

Origin www.cnblogs.com/sonnyBag/p/11624898.html