上周我在我的服务器上发现了一个问题,因为磁盘使用率是100%,我发现apache创建了一个60GB的巨大error.log文件.然后我将LogLevel更改为emerg,但是在一周之后它又是1.3GB,这肯定是太多了.此外,我有一个6MB的access.log和167MB的other_vhosts_access.log.所以我发现问题可能是logrotate无法正常工作.实际上,日志的gzip文件有一个非常旧的日期(2月23日).所以我首先尝试更改apache2的logrotate文件的配置,为文件添加最大大小,现在看起来像这样:
/var/log/apache2/*.log {
weekly
size 500M
missingok
rotate 20
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
if /etc/init.d/apache2 status > /dev/null ; then \
/etc/init.d/apache2 reload > /dev/null; \
fi;
endscript
prerotate
if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
run-parts /etc/logrotate.d/httpd-prerotate; \
fi; \
endscript
}
Run Code Online (Sandbox Code Playgroud)
在此之后,我尝试手动强制logrotate运行apache的特定配置
logrotate -f /etc/logrotate.d/apache2
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误:
error: skipping "/var/log/apache2/access.log" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to …Run Code Online (Sandbox Code Playgroud)