PHP 业务日志
shell> vim /etc/logrotate.d/log-file
/var/log/log-file {
hourly
rotate 2
maxsize 512M
missingok
compress
delaycompress
notifempty
create 664 www-data www-data
}
PHP-FPM 日志
shell> vim /etc/logrotate.d/php7.2-fpm
/var/log/php7.2-fpm.log {
weekly
rotate 12
missingok
notifempty
compress
delaycompress
postrotate
/usr/lib/php/php7.2-fpm-reopenlogs
endscript
}
Nginx 日志
shell> vim /etc/logrotate.d/nginx
/var/log/nginx/*.log {
hourly
rotate 1
maxsize 512M
missingok
compress
delaycompress
notifempty
create 644 www-data www-data
postrotate
/etc/init.d/nginx reload
endscript
}
Linux 系统日志
shell> vim /etc/logrotate.d/rsyslog
/var/log/syslog {
rotate 7
daily
missingok
notifempty
delaycompress
compress
postrotate
invoke-rc.d rsyslog rotate > /dev/null
endscript
}
/var/log/mail.info
/var/log/mail.warn
/var/log/mail.err
/var/log/mail.log
/var/log/daemon.log
/var/log/kern.log
/var/log/auth.log
/var/log/user.log
/var/log/lpr.log
/var/log/cron.log
/var/log/debug
/var/log/messages {
rotate 4
weekly
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
invoke-rc.d rsyslog rotate > /dev/null
endscript
}
手动运行 logrotate
shell> logrotate /etc/logrotate.conf
查看使用帮助
shell> man logrotate