【问题标题】:Problems with permissions for logrotatelogrotate 权限问题
【发布时间】:2015-03-29 19:29:45
【问题描述】:

我正在为一些 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 testing/jessie。

【问题讨论】:

    标签: logrotate


    【解决方案1】:

    好吧,愚蠢的情况。 logrotate 命令必须在配置文件而不是日志文件上执行。

    $ 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.
    

    【讨论】:

    • 会喜欢 sudo chmod [numbers] [files] 这里作为一个实际的解决方案。现在我必须看得更远。
    • 我已将其更改为 wiki 答案。你能添加相应的chmod 命令吗?
    • 这就是重点 - 我不知道八进制和chmod 足够好:( 如果我找到了,我会添加它。
    • 我假设您必须按照上面的示例运行 chown root /home/me/public_html/logs/logfile1.logchmod 600 /home/me/public_html/logs/logfile1.log。如果您可以尝试一下,可以将其添加到答案中。
    • 问题是很多系统都有一个上层全局配置文件。因此,仅使用该配置文件通常是错误的!为了解决这个问题,我有一个脚本“logrotate_one”,它将两者合并然后进行 logrotate...antofthy.gitlab.io/software/logrotate_one.sh.txt
    猜你喜欢
    • 1970-01-01
    • 2013-12-12
    • 2011-10-02
    • 2011-06-03
    • 2011-05-12
    • 2020-09-14
    • 2019-05-11
    • 2014-04-20
    • 2011-03-10
    相关资源
    最近更新 更多