我正在使用 rsyslog 并尝试执行以下配置:
1. Server 1 - log all local messages and log messages from server2
2. Server 2 - log all local messages and log messages from server1
因此,两台服务器都应该包含其本地和远程系统日志。
那么我在rsyslog.conf配置文件的转发部分放入的是:
服务器1:
# ### begin forwarding rule ###
# The statement between the begin ... end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
$WorkDirectory /var/lib/rsyslog # where to place spool files
$ActionQueueFileName server1 # unique name prefix for spool files
$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
$ActionQueueType LinkedList # run asynchronously
$ActionResumeRetryCount -1 # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
*.* @@10.0.0.2
# ### end of the forwarding rule ###
服务器2:
# ### begin forwarding rule ###
# The statement between the begin ... end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
$WorkDirectory /var/lib/rsyslog # where to place spool files
$ActionQueueFileName server2 # unique name prefix for spool files
$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
$ActionQueueType LinkedList # run asynchronously
$ActionResumeRetryCount -1 # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
*.* @@10.0.0.1
# ### end of the forwarding rule ###
问题是,这基本上会导致类似无限循环的情况。 IE 每个系统都有自己的条目,然后来自每个系统的所有新条目。因此,这会不断地不断复制相同的信息,从而快速填满日志文件。
有什么办法可以做我想做的事吗?
我正在使用 rsyslog v5 (RHEL 6/Centos 6) 标准。
答案1
你也许可以这样做使用条件句,尽管 rsyslog 语法配置取决于您正在运行的版本 - 并且该版本的 CentOS 正在变旧。
在 udp 服务器配置(UDPServerRun
或类似配置)之后,在将消息转发到远程的指令之前,您可以尝试添加以下内容:
if $fromhost-ip startswith '10.0.0.' then /var/log/remotelogs.log
& ~
这应该将远程日志发送到单独的文件,并防止进一步处理/转发。
尽管如果您打算转发系统日志消息,我建议您考虑设置专用的系统日志代理/存储服务器 - 如果必须保留重复副本,甚至可以是两个。如果您认为简单的系统日志服务器不值得您花时间:您可以看看 Logstash(以及一般的 ELK 堆栈)或 Splunk,...也许作为一个副项目。