清理Apache日志节省空间可采用以下方法:
/var/log/apache2/),用find命令删除指定天数前的日志,如:find . -type f -mtime +3 -name "*.log" -delete。sudo apt-get install logrotate(Debian/Ubuntu)或sudo yum install logrotate(CentOS/RHEL)。/etc/logrotate.d/apache2),设置轮转策略(如每天轮转、保留7天、压缩旧日志):/var/log/apache2/*.log {
daily
rotate 7
compress
missingok
notifempty
create 640 root adm
}
然后手动运行sudo logrotate -f /etc/logrotate.conf测试,或通过cron定时任务自动执行。httpd.conf中使用rotatelogs指令,如:ErrorLog "|/usr/sbin/rotatelogs /var/log/apache2/error_%Y%m%d.log 86400",重启Apache生效。httpd.conf中修改LogLevel为warn或更高,减少冗余日志。注意:操作前建议备份重要日志,避免误删。