【发布时间】:2014-12-16 10:42:30
【问题描述】:
上周我在我的服务器上发现了一个问题,因为磁盘使用率为 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
}
在此之后,我尝试手动强制 logrotate 为 apache 运行特定配置
logrotate -f /etc/logrotate.d/apache2
我得到了这个错误:
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 tell logrotate which user/group should be used for rotation.
error: skipping "/var/log/apache2/error.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 tell logrotate which user/group should be used for rotation.
error: skipping "/var/log/apache2/other_vhosts_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 tell logrotate which user/group should be used for rotation.
奇怪的是,它以某种方式运行轮换,创建了一个空的 error.log 文件,但具有与旧文件不同的权限,并且不压缩现有的 error.log。
查看apache日志目录,现在是这样的:
-rwxrwxrwx 1 root adm 6.3M Oct 21 10:54 access.log
-rwxrwxrwx 1 root adm 22K Feb 18 2014 access.log.1
-rwxrwxrwx 1 root adm 7.0K Feb 16 2014 access.log.2.gz
-rwxrwxrwx 1 root adm 4.0K Feb 9 2014 access.log.3.gz
-rw------- 1 amministratore amministratore 0 Oct 21 10:32 error.log
-rw-r--r-- 1 root root 1.3G Oct 21 10:57 error.log.1
-rwxrwxrwx 1 root adm 167M Oct 21 10:57 other_vhosts_access.log
-rwxrwxrwx 1 root adm 225K Feb 23 2014 other_vhosts_access.log.1
-rwxrwxrwx 1 root adm 16K Feb 15 2014 other_vhosts_access.log.2.gz
-rwxrwxrwx 1 root adm 3.2K Feb 8 2014 other_vhosts_access.log.3.gz
那么正确的方法是什么?
我应该更改 /var/log/apache2 目录的权限吗? (现在是777)我没有设置这些权限,也不知道对不对。
或者我应该告诉 logrotate 使用哪个用户进行轮换?怎么做?
【问题讨论】:
-
尊敬的访问者,Apache 配置在 Stack Overflow 上是题外话。请访问unix.stackexchange.com,那里有话题。
-
@peterh Apache 配置问题在这里是题外话,这根本不是真的。 Stack Overflow 上有数千个。见What topics can I ask about here?。在其他 SE 站点上询问有关特定配置问题(例如安全性或性能)的一些问题可能(或可能不)更合适,但在这里断言所有配置问题都无关紧要是荒谬的。您的声明也是不诚实的,因为您选择编辑问题并告诉所有人这是题外话!
-
@peterh 如果您真的担心 Stack Overflow 上 Apache 配置问题的有效性,请在 Stack Overflow Meta 上提出问题以进行澄清。..
标签: apache ubuntu apache2 logrotate