logrotate cuts tomcat logs and deletes them regularly

When the size of the Tomcat log file catalina.out is greater than 2GB, the Tomcat program may fail to start when it crashes without any error message prompt. In order to avoid this scenario, we need to rotate the catalina.out log file regularly.

Here Xiaobai uses the logrotate program that comes with CentOS6U5 to solve the log rotation problem of catalina.out. This way is relatively simple. Create a new file named tomcat in the /etc/logrotate.d/ directory,

cat >/etc/logrotate.d/tomcat-www<<EOF
/application/apache-tomcat-biz/logs/catalina.out{
copytruncate
daily
rotate 14
missingok
compress
delaycompress
dateext
dateformat .%Y-%m-%d.log
#size 16M
}
EOF

/bin/echo '0 2 find /application/apache-tomcat-www/logs -mtime +17 -name '' -exec rm -rf {} \;' >>/var/spool/cron/root

The above configuration instructions:

/usr/local/apache-tomcat-8.0.28/logs/catalina.out{ # File to be
rotated copytruncate # After creating a new copy of catalina.out, truncate the source catalina.out file
daily # Do the catalina.out file daily rotate
rotate 7 # reserved up to seven copies of
missingok # If you want to rotate the file is missing, continue to rotate without being given
compress # using compressed mode (very useful, saving hard disk space; a 2 ~ 3GB log files can be compressed to about 60MB )
Delaycompress is always used with the compress option. The delaycompress option instructs logrotate not to compress the most recent archive. The compression will be performed in the next round robin.
size 16M # When the catalina.out file is larger than 16MB, it will rotate, the priority is higher than daily

Guess you like

Origin blog.51cto.com/19840202/2546161
Recommended