我正在为某些Web应用程序编写自己的logrotate配置:
/home/me/public_html/logs/*.log {
daily
missingok
rotate 15
compress
delaycompress
notifempty
create 0660 me www-data
nosharedscripts
}
但是为这些文件运行logrotate会导致:
$ sudo logrotate -d -v *.log
Ignoring logfile1.log because of bad file mode.
Ignoring logfile2.log because of bad file mode.
Ignoring otherlogfile.log because of bad file mode.
Handling 0 logs
$ ls -l
-rw-rw---- 1 me www-data 893584 Jan 27 16:01 logfile1.log
-rw-rw---- 1 me www-data 395011 Jan 27 16:01 logfile2.log
-rw-rw---- 1 me www-data 4949115 Jan 27 16:01 otherlogfile.log
这与使用create 0660 me www-data
指定的权限的目录中的实际日志文件的文件权限相关吗?
如果我将文件权限更改为-rw-r-----
,将create
行更改为
create 0640 me www-data
我得到了
$ sudo logrotate -d -v *.log
Ignoring logfile1.log because the file owner is wrong (should be root).
Ignoring logfile2.log because the file owner is wrong (should be root).
Ignoring otherlogfile.log because the file owner is wrong (should be root).
Handling 0 logs
我的系统是debian测试/ jessie。
答案 0 :(得分:13)
$ sudo logrotate -d -v /etc/logrotate.d/my-app
日志文件的父目录不是全局可写的(------rw-
)并且不能由任何非root
组(---rw----
)写入,这一点很重要。否则,你会看到:
error: skipping "/home/me/public_html/logs/logfile1.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.