配置 Rsyslog 以停止记录某些消息

Ste*_*hen 17 rsyslog

我想停止 rsyslog 记录这些消息。

[168707.740364] TCP: Peer 192.168.100.1:46199/41503 unexpectedly shrunk window 2027330493:2027331431 (repaired)

我在 /etc/rsyslog.conf 中尝试了这个,但仍然记录了消息。

if $msg contains 'unexpectedly' then /dev/null

任何人都可以指出我正确的方向吗?

Kar*_*rlo 10

如果您使用最新版本的 rsyslog(例如 7),则需要执行

& stop
Run Code Online (Sandbox Code Playgroud)

在您留言之后。不这样做会给你

warning: ~ action is deprecated, consider using the 'stop' statement instead [try http://www.rsyslog.com/e/2307 ]
Run Code Online (Sandbox Code Playgroud)


kas*_*ani 6

rsyslog 需要一个语句来在匹配后停止记录。在您已有的 if 语句之后立即添加此行。

& ~
Run Code Online (Sandbox Code Playgroud)

您可能还需要在 conf 文件中向上移动这两个语句,以便在其他一些可能将它们记录到消息的语句之前解析它们。我将我的 rsyslog 配置更改为如下所示

/etc/rsyslog.conf ($IncludeConfig /etc/rsyslog.d/*.conf)
/etc/rsyslog.d/40-specificdaemon.conf
/etc/rsyslog.d/99-general.conf
Run Code Online (Sandbox Code Playgroud)

这确保了我想要的顺序,并使配置管理更容易推送更新。

  • `& ~` 在较新版本的 rsyslog 中已弃用:http://www.rsyslog.com/doc/v8-stable/compatibility/v7compatibility.html。`~` 也称为丢弃操作,如果您搜索该页面,您将看到有关它的注释。您应该继续使用`& stop`。 (4认同)