【问题标题】:How to debug rsyslog on centos7centos7上如何调试rsyslog
【发布时间】:2021-04-28 22:25:21
【问题描述】:

我有一个将 rsyslogs 转发到外部服务的机制。

/etc/rsyslog.d下我创建了一个.conf文件。

这是文件:

$ModLoad imfile
$InputFilePollInterval 1
$InputFileName /var/log/secure
$InputFileTag securelogs:
$InputFileStateFile securelogs
$InputFileFacility local0
$InputRunFileMonitor
:syslogtag, isequal, "securelogs:" {
  :msg, contains, "sshd" {
    local0.* /var/log/forward_securelogs_audit.log
    local0.* @@<server-ip>:514
  }
  stop
}

我在多台服务器上都有相同的配置,但其中 2 台无法正常工作。

如何调试?

我尝试按照此处的说明进行操作 - https://www.rsyslog.com/how-to-use-debug-on-demand/

但是没有文件-/etc/rc.d/init.d/rsyslog

也没有文件-/var/run/rsyslogd.pid

在获取版本rsyslogd -v 时,我得到以下信息

0726.220297821:7f4d57c22780: Note: debug on demand turned on via configuraton file, use USR1 signal to activate.
rsyslogd 8.24.0-57.el7_9, compiled with:
        PLATFORM:                               x86_64-redhat-linux-gnu
        PLATFORM (lsb_release -d):
        FEATURE_REGEXP:                         Yes
        GSSAPI Kerberos 5 support:              Yes
        FEATURE_DEBUG (debug build, slow code): No
        32bit Atomic operations supported:      Yes
        64bit Atomic operations supported:      Yes
        memory allocator:                       system default
        Runtime Instrumentation (slow code):    No
        uuid support:                           Yes
        Number of Bits in RainerScript integers: 64

但同样,我在调试文件中看不到任何东西,在终端上也看不到。

任何帮助将不胜感激。

【问题讨论】:

    标签: linux debugging centos7 rsyslog


    【解决方案1】:

    您链接到的文档非常旧,RedHat 和 CentOS 现在使用 systemd 来启动守护程序,因此这些文件不再存在。如果你这样做了

    systemctl status rsyslog 
    

    您应该会看到包含类似内容的行

       Active: active (running) since ...
     Main PID: 738 (rsyslogd)
    

    您可以将 USR1 信号发送到此编号的进程以切换调试。在这种情况下,它将是:

    sudo kill -USR1 738
    

    默认情况下,我认为调试输出应该在 stdout 上,在我的 Fedora systemd 上,它针对 rsyslogd 被定向到 /dev/null,所以这可能没有帮助。 我没有 CentOS,但可能类似。 您可以使用以下命令查看 systemd 单元:

    systemctl cat rsyslog
    

    就我而言,这包括以下几行:

    EnvironmentFile=-/etc/sysconfig/rsyslog
    StandardOutput=null
    

    如果是这种情况,您可以在文件/etc/sysconfig/rsyslog 中添加选项,例如:

    RSYSLOG_DEBUGLOG=/tmp/rsyslogdebug
    

    然后重新启动 rsyslogd 并尝试再次发出信号以切换调试。

    【讨论】:

    • 感谢您的回复。打开 /etc/sysconfig/rsyslog 时,我看到以下评论 -> # Options for rsyslogd # Syslogd 选项自 rsyslog v3 以来已弃用。 # 如果要使用它们,请通过“-c 2”切换到兼容模式 2 # 更多详细信息请参见 rsyslogd(8) 无论如何,我尝试了 export RSYSLOG_DEBUGLOG=/tmp/rsyslogdebug ,但由于未创建文件,因此无法正常工作。干杯!
    • /etc/sysconfig/rsyslog 不是由 shell 读取,而是由 systemd 读取。您不能在RSYSLOG_DEBUGLOG=/tmp/rsyslogdebug 行中使用单词export。仅当您使用kill -USR1 发出进程信号时才会创建该文件。
    猜你喜欢
    • 2015-11-06
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    • 2016-04-21
    • 2017-07-05
    • 1970-01-01
    • 2015-07-22
    相关资源
    最近更新 更多