【问题标题】:error: error creating state file /var/lib/logrotate/status: Permission denied错误:创建状态文件时出错 /var/lib/logrotate/status: Permission denied
【发布时间】:2012-06-01 10:53:52
【问题描述】:

尝试使用 logrotate,但在为 logrotate.d 中的特定定义运行日志轮换脚本时出现以下错误

error: error creating state file /var/lib/logrotate/status: Permission denied

/var/lib/logrotate$ ls -lah
total 12K
drwxr-xr-x  2 root root 4.0K 2012-05-11 06:25 .
drwxr-xr-x 43 root root 4.0K 2012-05-18 08:07 ..
-rw-r--r--  1 root root  911 2012-05-25 06:25 status

我没有接触过那个路径,所以我想知道为什么它默认会产生错误......

【问题讨论】:

    标签: ubuntu logrotate


    【解决方案1】:

    不要chmod默认状态文件为666。如果你chmod 它,系统上的每个用户都可以使用logrotate 作为攻击向量。

    只需使用选项[-s|--state file] 为您的用户(假设您尝试以普通用户身份运行它)定义一个(私有)状态文件。

    【讨论】:

      【解决方案2】:

      您确定以 root 身份运行此命令吗...? ;) 如果是,请检查系统上是否有 AppArmour - 如果是,请检查它的配置或卸载它(Ubuntu 案例)。

      【讨论】:

      • 不确定,最后我将 status chmod 为 666 并且它起作用了。你可能是对的,所以我会接受答案:)
      【解决方案3】:

      在 crontab 中有这一行:

      *  *  *  *  *   root    logrotate -s /var/run/logrotate.status /etc/logrotate.conf
      

      即使它以 root 身份运行,我也无法摆脱“错误:错误创建状态文件 /var/run/logrotate/status: Permission denied”错误。

      所以我只是使用了不同的目录:

      *  *  *  *  *    root    /usr/sbin/logrotate -s /var/log/logrotate.status -v /etc/logrotate.conf >/tmp/logrotate.out 2>&1
      

      使用了https://serverfault.com/questions/762587/daily-logrotate-error-creating-unique-temp-file-permission-denied 的调试思想,但对其进行了更改,因此输出文件不会无限增长,这很讽刺。

      在这种情况下,详细模式没有提供任何其他信息,顺便说一下,它正在读取的配置文件和相同的错误消息。但最好将输出放在该文件而不是 /var/mailspool 中。

      【讨论】:

        猜你喜欢
        • 2014-09-08
        • 1970-01-01
        • 1970-01-01
        • 2020-10-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-11
        相关资源
        最近更新 更多