Linux logrotate 表示在旋转日志/重新创建日志文件时权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6207711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 04:20:04  来源:igfitidea点击:

logrotate says permission denied when rotating log / re-creating log file

linuxfile-permissionschmodpermission-deniedlogrotate

提问by Derick Bailey

I'm new to logrotate on linux machines... here's what I have set up in my app's logrotate.d file:

我是 Linux 机器上 logrotate 的新手……这是我在应用程序的 logrotate.d 文件中设置的内容:

/var/log/myapp.log {
daily
missingok
create 0660 root utmp
rotate 1
}

I set owner permissions on the myapp.log file for the account that runs the app in question, using chmod, directly from the bash shell.

我使用 chmod 直接从 bash shell 为运行相关应用程序的帐户设置了 myapp.log 文件的所有者权限。

when the app first runs, everything is fine. It logs just fine and it's all good. But when the log gets rotated, it deletes the log file and then tries to recreate the log file and it gives a permission denied error:

当应用程序第一次运行时,一切都很好。它记录得很好,一切都很好。但是当日志被轮换时,它会删除日志文件,然后尝试重新创建日志文件,并给出权限被拒绝的错误:

/bin/bash: /var/log/myapp.log: Permission denied

I know I'm doing something wrong with either the logrotate config file or chmod or something... can someone point me in the right direction and help me fix the problem?

我知道我在 logrotate 配置文件或 chmod 或其他方面做错了什么......有人可以指出我正确的方向并帮助我解决问题吗?

采纳答案by Matthew Slattery

I set owner permissions on the myapp.log file for the account that runs the app in question, using chmod, directly from the bash shell.

我使用 chmod 直接从 bash shell 为运行相关应用程序的帐户设置了 myapp.log 文件的所有者权限。

...so unless "the account that runs the app in question" is root, the config option

...所以除非“运行相关应用程序的帐户”是root,配置选项

create 0660 root utmp

is wrong, because that is asking logrotateto create a new myapp.log(after it has rotated the original myapp.logto myapp.log.0) with permissions 0660owned by user rootand group utmp. Replacing these with the attributes required by your app should solve the problem.

是错误的,因为这是要求logrotate创建一个新的myapp.log(在将原始旋转myapp.log到 之后myapp.log.0),其权限0660归 userroot和 group utmp。用您的应用程序所需的属性替换这些应该可以解决问题。