AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 701535
Accepted
Appleoddity
Appleoddity
Asked: 2022-05-06 07:55:21 +0800 CST2022-05-06 07:55:21 +0800 CST 2022-05-06 07:55:21 +0800 CST

为什么 rsyslog 无法正常工作?

  • 772

rsyslog 无法向/var/log/messages外部 syslog 收集器发送消息或向其发送消息,如下所述。

我有一个 AWS EC2 RHEL 7 实例和一个本地 RHEL 7 实例。它们都是最小安装、标准 AMI 等。rsyslog除了添加.conf文件/etc/rsyslog.d/以将日志记录发送到外部 syslog 收集器外,配置是默认配置。本地实例将系统日志发送到本地收集器。AWS 实例将其发送到基于 EC2 的收集器。两个收集器在相同的配置中运行相同的软件,并从其他来源接收事件,否则正常运行。

/etc/rsyslog.conf在两个实例之间是相同的。以下是未注释的行:

# grep -v "^#\|^$" /etc/rsyslog.conf
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imjournal # provides access to the systemd journal
$WorkDirectory /var/lib/rsyslog
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$IncludeConfig /etc/rsyslog.d/*.conf
$OmitLocalLogging on
$IMJournalStateFile imjournal.state
*.*;mail.none;authpriv.none;cron.none                /var/log/messages
authpriv.*                                              /var/log/secure
mail.*                                                  -/var/log/maillog
cron.*                                                  /var/log/cron
*.emerg                                                 :omusrmsg:*
uucp,news.crit                                          /var/log/spooler
local7.*                                                /var/log/boot.log

在云实例上添加了/etc/rsyslog.d/21-cloudinit.conf:

# Log cloudinit generated log messages to file
:syslogtag, isequal, "[CLOUDINIT]" /var/log/cloud-init.log

# comment out the following line to allow CLOUDINIT messages through.
# Doing so means you'll also get CLOUDINIT messages in /var/log/syslog
& stop

在这两种情况下还有/etc/rsyslog.d/listen.conf:

# cat /etc/rsyslog.d/listen.conf
$SystemLogSocketName /run/systemd/journal/syslog

在这两个实例/etc/rsylog.d/xdr.conf上都添加了。它仅因系统日志消息的目的地而异,见下文。

云实例:

# cat /proc/version
Linux version 3.10.0-1160.62.1.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Wed Mar 23 09:04:02 UTC 2022

# yum list installed | grep rsyslog
rsyslog.x86_64               8.24.0-57.el7_9.2 @rhel-7-server-rhui-rpms

# cat /etc/rsyslog.d/xdr.conf
# Forward all log messages to Taegis XDR
# AWS Collector
*.*    @@aws-v-xxxxxx-xxxxxx-xxxxxxxxxxxxx.elb.us-east-1.amazonaws.com:601

# On-Prem Collector
#*.*    @@scwx-collector.xxx.local:601

本地实例:

# cat /proc/version
Linux version 3.10.0-1160.62.1.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Wed Mar 23 09:04:02 UTC 2022

# yum list installed | grep rsyslog
rsyslog.x86_64                    8.24.0-57.el7_9.2          @rhel-7-server-rpms

# cat /etc/rsyslog.d/xdr.conf
# Forward all log messages to Taegis XDR
# AWS Collector
#*.*    @@aws-v-xxxxxx-xxxxxx-xxxxxxxxxxxxx.elb.us-east-1.amazonaws.com:601

# On-Prem Collector
*.*    @@scwx-collector.xxx.local:601

xdr.conf可以从端口 601 上的每个实例访问中列出的端点。我通过快速telnet会话独立确认。

# telnet scwx-collector.xxx.local 601
Trying 10.100.11.37...
Connected to scwx-collector.xxx.local.
Escape character is '^]'.

# telnet aws-v-xxxxxx-xxxxxx-xxxxxxxxxxxxx.elb.us-east-1.amazonaws.com 601
Trying 10.200.2.89...
Connected to aws-v-xxxxxx-xxxxxx-xxxxxxxxxxxxx.elb.us-east-1.amazonaws.com.
Escape character is '^]'.

AWS 实例工作正常。Syslog 消息被传送到收集器和/var/log/messages. 本地服务器无法将消息传递到这两个位置。

在本地服务器上,如果我重命名并重新启动xdr.conf服务,则会立即开始填充。启用后它们是空的 - 没有更多的条目出现。外部 syslog 收集器不显示任何接收到的事件,也不显示在 syslog 端点之间传输的任何数据包。xdr.conf.bakrsyslog/var/log/messagesxdr.conftcpdump

为什么 rsyslog 既不向/var/log/messages外部收集器也不向外部收集器发送消息?唯一的区别是它将消息发送到的端点,据我所知,这些端点既可访问又正常运行。甚至 syslog 收集器端点也是相同的配置。两个操作系统是一样的,rsyslog是同一个版本。我该如何进一步解决这个问题?

rhel rsyslog
  • 1 1 个回答
  • 244 Views

1 个回答

  • Voted
  1. Best Answer
    Appleoddity
    2022-07-14T10:51:25+08:002022-07-14T10:51:25+08:00

    我最终发现这是由 SELinux 引起的问题。

    我发现 SELinux 拒绝访问该/etc/rsyslog.d/xdr.conf文件。进一步调查时,我看到以下输出:

    [root@x rsyslog.d]# ls -Z
    -rw-r--r--. root root system_u:object_r:syslog_conf_t:s0 listen.conf
    -rw-r--r--. root root unconfined_u:object_r:syslog_conf_t:s0 test.conf
    -rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 xdr.conf
    -rw-r--r--. root root unconfined_u:object_r:syslog_conf_t:s0 xdr.orig
    

    我看到该xdr.conf文件应用了错误的上下文。但是,当我复制xdr.conf到时,xdr.orig我看到应用了正确的上下文。

    通过运行,restorecon -Rv /etc/rsyslog.d我看到它重置了上下文:

    [root@x rsyslog.d]# restorecon -Rv /etc/rsyslog.d
    restorecon reset /etc/rsyslog.d/xdr.conf context unconfined_u:object_r:admin_home_t:s0->unconfined_u:object_r:syslog_conf_t:s0
    

    我怀疑这个问题发生在这些本地服务器上,因为我xdr.conf通过 psftp 将文件上传到文件/root夹,然后将其移入/etc/rsyslog.d. 结果,我认为该文件收到了错误的上下文,这就是 SELinux 拒绝它的原因。在 AWS 实例上,我使用 SSM 将文件推送到实例,显然它在这种情况下接收到正确的上下文。restorecon修复上下文并解决问题。

    在我的研究过程中,我还意识到我使用了一个过时的配置,并更新了我的配置,使其看起来像这样:

    # Forward all log messages to Taegis XDR
    # AWS Collector
    #*.*     action(type="omfwd" target="aws-v-xxxxxx-xxxxxx-xxxxxxxxxxxxx.elb.us-east-1.amazonaws.com" port="601" protocol="tcp"
                    action.resumeRetryCount="-1"
                    queue.type="linkedList" queue.size="10000")
    
    # On-Prem Collector
    *.*     action(type="omfwd" target="scwx-collector.xxx.local" port="601" protocol="tcp"
                    action.resumeRetryCount="-1"
                    queue.type="linkedList" queue.size="10000")
    
    • 1

相关问题

  • 为什么 Linux 会杀死我的进程?

  • linux redhat 7 ( 或 centos 7 ) + firewalld 屏蔽防火墙

  • systemctl 命令在 RHEL 6 中不起作用

  • 如何在 RHEL 7 上离线安装 docker?

  • 在 Gnome3 中禁用窗口的自动最大化

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve