logrotate 无法旋转日志:错误设置所有者

hdf*_*hdf 6 permissions users logrotate groups

最近我注意到logrotate它不会旋转我的日志。

user1@host:~$ /usr/sbin/logrotate /home/user1/logrotate.conf -v 给我一个错误:

error: error setting owner of /home/logs/mylog.log.1 to uid 10111 and gid 10111: 
Operation not permitted
error: error creating output file /var/lib/logrotate/status.tmp:
Permission denied
Run Code Online (Sandbox Code Playgroud)

gid让我user1很困惑,因为只有一个具有不同gid:

user1@host:~$ id
uid=10111(user1) gid=1001(mygroup) groups=1001(mygroup)
Run Code Online (Sandbox Code Playgroud)

但是,还有另一个名为 的组user1,但是,正如我所提到的,实际用户user1不是其成员:

user1@host:~$ cat /etc/group | grep user1
user1:x:10111
Run Code Online (Sandbox Code Playgroud)

这里很简单,但我看不到。

更新:这是 logrotate.conf 的样子:

/home/logs/*.log { rotate 7 daily copytruncate compress notifempty }

user1@host:~$ ls -al /home/logs/ -rw-r--r-- 1 user1 mygroup 190826983 Dec 18 06:05 mylog.log

the*_*fog 1

您可以尝试使用 logrotatescreate指令来设置新创建的日志文件的权限。要使用它你

/home/logs/*.log {
    rotate 7
    daily
    create 0777 user1 user1
    ^^^^^^^^^^^^^^^^^^^^^^
    copytruncate
    compress
    notifempty
 }
Run Code Online (Sandbox Code Playgroud)

man logrotate

 create mode owner group, create owner group
Run Code Online (Sandbox Code Playgroud)

轮换后(运行 postrotate 脚本之前),将立即创建日志文件(与刚刚轮换的日志文件同名)。mode 以八进制指定日志文件的模式(与 chmod(2) 相同),owner 指定将拥有日志文件的用户名,group 指定日志文件所属的组。任何日志文件属性都可以省略,在这种情况下,新文件的这些属性将使用与原始日志文件相同的值来表示省略的属性。可以使用 nocreate 选项禁用此选项。