rsyslog过滤和转发
rsyslog filtering and forwarding
我正在尝试使用 rsyslog 虚拟机实现过滤和转发。
当我使用
*.* @@192.168.1.100:514
它将所有日志转发到该日志服务器。
我需要做的是过滤掉包含 'testing' 和 'flow' 的日志,并防止从本地主机发送到日志服务器的日志。
我尝试了很多方法来实现这种组合,但都失败了。我只是在使用过滤器后没有收到任何到目的地的日志。
rsyslog.conf剩余的完整内容是
# rsyslog configuration file
# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html
#### MODULES ####
# The imjournal module bellow is now used as a message source instead of imuxsock.
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imjournal # provides access to the systemd journal
#$ModLoad imklog # reads kernel messages (the same are read from journald)
#$ModLoad immark # provides --MARK-- message capability
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
#### GLOBAL DIRECTIVES ####
# Where to place auxiliary files
$WorkDirectory /var/lib/rsyslog
# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf
# Turn off message reception via local log socket;
# local messages are retrieved through imjournal now.
$OmitLocalLogging on
# File to store the position in the journal
$IMJournalStateFile imjournal.state
#### RULES ####
if $msg contains 'testing' then @@192.168.1.100:514
#*.* @@192.168.1.100:514
我的配置不工作。
首先,请注意 $IncludeConfig /etc/rsyslog.d/*.conf
行。基本上是说所有 .conf
文件都将包含在您粘贴的那个 rsyslog.conf
文件中。因此,与其将您的规则放在该文件的底部,我建议添加另一个文件,例如 /etc/rsyslog.d/30-testing.conf
并将您的规则放在那里。这更有条理,如果您的系统日志配置在未来增长,将会很有帮助。
除此之外,如果它在没有过滤器的情况下工作,因此 ports/firewall 不是问题,那么它确实应该工作——你的过滤器行看起来不错。您可能已经这样做了,但不妨试试:
:msg, contains, "testing" @@192.168.1.100:514
还有,请问你是不是每次修改配置文件都要重启rsyslog服务?您可能需要这样做。您还可以 post 您使用的是什么版本的 rsyslog?
我正在尝试使用 rsyslog 虚拟机实现过滤和转发。
当我使用
*.* @@192.168.1.100:514
它将所有日志转发到该日志服务器。
我需要做的是过滤掉包含 'testing' 和 'flow' 的日志,并防止从本地主机发送到日志服务器的日志。
我尝试了很多方法来实现这种组合,但都失败了。我只是在使用过滤器后没有收到任何到目的地的日志。
rsyslog.conf剩余的完整内容是
# rsyslog configuration file
# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html
#### MODULES ####
# The imjournal module bellow is now used as a message source instead of imuxsock.
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imjournal # provides access to the systemd journal
#$ModLoad imklog # reads kernel messages (the same are read from journald)
#$ModLoad immark # provides --MARK-- message capability
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
#### GLOBAL DIRECTIVES ####
# Where to place auxiliary files
$WorkDirectory /var/lib/rsyslog
# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf
# Turn off message reception via local log socket;
# local messages are retrieved through imjournal now.
$OmitLocalLogging on
# File to store the position in the journal
$IMJournalStateFile imjournal.state
#### RULES ####
if $msg contains 'testing' then @@192.168.1.100:514
#*.* @@192.168.1.100:514
我的配置不工作。
首先,请注意 $IncludeConfig /etc/rsyslog.d/*.conf
行。基本上是说所有 .conf
文件都将包含在您粘贴的那个 rsyslog.conf
文件中。因此,与其将您的规则放在该文件的底部,我建议添加另一个文件,例如 /etc/rsyslog.d/30-testing.conf
并将您的规则放在那里。这更有条理,如果您的系统日志配置在未来增长,将会很有帮助。
除此之外,如果它在没有过滤器的情况下工作,因此 ports/firewall 不是问题,那么它确实应该工作——你的过滤器行看起来不错。您可能已经这样做了,但不妨试试:
:msg, contains, "testing" @@192.168.1.100:514
还有,请问你是不是每次修改配置文件都要重启rsyslog服务?您可能需要这样做。您还可以 post 您使用的是什么版本的 rsyslog?