Apache和logrotateconfiguration

上周我在我的服务器上发现了一个问题,因为磁盘使用率是100%,我发现Apache创build了一个60GB的巨大error.log文件。 我改变了然后LogLevel出现,但一个星期后,又是1.3GB,这绝对是太多了。 此外,我有一个6MB的access.log和一个167MB的other_vhosts_access.log。 所以我发现问题可能是logrotate不工作。 实际上日志的gzip文件有一个非常旧的date(2月23日)。 所以我首先尝试改变apache2的logrotate文件的configuration,为文件添加一个最大大小,现在看起来像这样:

/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运行特定的configuration为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. 

奇怪的是,在某种程度上它运行旋转,创build一个空的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哪个用户使用旋转? 如何?

只需将su root adm添加到配置文件中:

 /var/log/apache2/*.log { # … su root adm } 

遵循来自网站的指示,我刚刚更改了logrotate配置文件,添加了所需的su指令,如下所示,现在它以正确的方式旋转。

 su <user> <group> 

试图强制旋转系统日志时,我有“父目录有不安全的权限”。
这是我如何解决它:

 cat /etc/logrotate.conf ... # use the syslog group by default, since this is the owning group # of /var/log/syslog. su root syslog vim /etc/logrotate.d/rsyslog # Add to top: su root syslog logrotate -f /etc/logrotate.d/rsyslog # No errors now, log is rotated.