什么原因导致仅在执行 rsyslog -d 时写入 /var/log/syslog?

什么原因导致仅在执行 rsyslog -d 时写入 /var/log/syslog?

我有一个系统,其中 /var/log/syslog 按预期写入,而另一个系统则无法写入,除非我停止 rsyslog 服务并使用“rsyslog -d”手动运行它。

我该如何调试这个问题?我尝试删除 /etc/rsyslog.d/ 中的所有内容,然后重新创建它。

我尝试删除并重新安装 rsyslogd

apt-get remove rsyslogd and apt-get install rsyslogd ubuntu-minimal

然后检查服务是否正在运行,但只有其他日志正在更新,而不是 /var/log/syslog。

我只是想让 rsyslog 的默认配置正常工作。

我注意到 /var/log/syslog 是 root:adm 而不是 syslog:adm。syslog 用户的日志文件工作正常。如果我将 /var/log/syslog 设为 syslog:adm,它就会开始工作。也许权限不知何故被破坏了。logrotate 不会更改权限/稍后再次创建这些文件吗?不确定修复是否是永久性的。

答案1

您已经确定这是一个文件权限问题,并且为服务指定的用户/etc/rsyslog.conf无法写入日志文件。但是,您的登录用户(可能是 root)在交互运行时确实有访问权限。以下是rsyslog.conf指定服务用户配置:

#
# Set the default permissions for all log files.
#
$FileOwner syslog
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
$PrivDropToUser syslog
$PrivDropToGroup syslog

至于 logrotate,你可以配置系统日志文件的管理方式,请参阅/etc/logrotate.conf/etc/logrotate.d/rsyslog。以下是示例:

/var/log/syslog
{
        rotate 7
        daily
        missingok
        notifempty
        delaycompress
        compress
        postrotate
                reload rsyslog >/dev/null 2>&1 || true
        endscript
}

在我的测试系统上,logrotate配置文件还包含:

# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

手动旋转

create mode owner group
    Immediately after rotation (before the postrotate script is run) the log file is created (with the same name  as  the  log
    file  just  rotated).   mode specifies the mode for the log file in octal (the same as chmod(2)), owner specifies the user
    name who will own the log file, and group specifies the group the log file will belong to. Any of the log file  attributes
    may  be omitted, in which case those attributes for the new file will use the same values as the original log file for the
    omitted attributes. This option can be disabled using the nocreate option.

因此,就我而言,创造选项决定如何设置新文件属性,因为在/etc/logrotate.d/rsyslog不要覆盖该全局设置。当模式所有者团体未指定,logrotate 使用与原始日志文件相同的值。

希望这能帮助你起步。祝你好运!

相关内容