Ubuntu下Apache日志分割主要有以下两种方法:
/etc/apache2/apache2.conf或/etc/httpd/conf/httpd.conf),在ErrorLog和CustomLog指令中使用管道符|调用rotatelogs,指定日志路径和分割间隔(如86400秒为每天分割)。例如:ErrorLog "|/usr/sbin/rotatelogs /var/log/apache2/error_%Y%m%d.log 86400"
CustomLog "|/usr/sbin/rotatelogs /var/log/apache2/access_%Y%m%d.log 86400" combined
重启Apache服务生效:sudo systemctl restart apache2。/etc/logrotate.d/apache2),定义日志轮转规则,包括轮转频率(如daily)、保留天数(如rotate 7)、压缩选项(如compress)等。例如:/var/log/apache2/*.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
/usr/sbin/service apache2 reload > /dev/null
endscript
}
该工具会自动按规则分割并管理日志文件。