【发布时间】:2017-01-03 14:08:32
【问题描述】:
我一直在关注rsyslog/logstash article,试图通过 rsyslog 将我的应用程序的日志文件发送到远程服务器。在该页面上,这是我采取的步骤。请注意,客户端(VM 发送日志)和服务器(VM 接收日志)上的防火墙和 SELinux 均已关闭。我已经通过 netcat 实用程序证明我可以在客户端和服务器之间发送数据包。
在我的客户端,我已经像这样配置了我的 /etc/rsyslog.conf 文件:
# Load the imfile module
module(load="imfile" PollingInterval="10")
# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf
# Debugging
$DebugFile /var/log/rsyslog-debug.log
$DebugLevel 2
# General configuration
$RepeatedMsgReduction off
$WorkDirectory /var/spool/rsyslog
$ActionQueueFileName mainqueue
$ActionQueueMaxDiskSpace 500M
$ActionQueueSaveOnShutdown on
$ActionQueueType LinkedList
$ActionResumeRetryCount -1
# Template for non json logs, just sends the message wholesale with extra
# # furniture.
template(name="textLogTemplate"
type="list") {
constant(value="{ ")
constant(value="\"type\":\"")
property(name="programname")
constant(value="\", ")
constant(value="\"host\":\"")
property(name="%HOSTNAME%")
constant(value="\", ")
constant(value="\"timestamp\":\"")
property(name="timestamp" dateFormat="rfc3339")
constant(value="\", ")
constant(value="\"@version\":\"1\", ")
constant(value="\"role\":\"app-server\", ")
constant(value="\"sourcefile\":\"")
property(name="$!metadata!filename")
constant(value="\", ")
constant(value="\"message\":\"")
property(name="rawmsg" format="json")
constant(value="\"}\n")
}
在客户端,我有 /etc/rsyslog.d/01-trm-error-logs.conf
input(type="imfile"
File="/usr/share/tomcat/dist/logs/trm-error.log"
Tag="trm-error-logs:"
readMode="2"
escapeLF="on"
)
if $programname == 'trm-error-logs:' then {
action(
type="omfwd"
Target="my.remoteserver.com"
Port="514"
Protocol="tcp"
template="textLogTemplate"
)
stop
}
在服务器端,我的 /etc/rsyslog.conf 中有
# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
我已经重启了双方的rsyslog服务。
但是,我没有看到日志被运出。我确实在 /var/log/messages 中看到了 /usr/share/tomcat/dist/logs/trm-error.log 的内容,但我不希望它们出现在那里。我确实看到 /usr/share/tomcat/dist/logs/trm-error.log 的内容根据我生成的 /var/log/rsyslog-debug.log 文件的内容被读取。
我确实在客户端机器上运行了以下命令,但什么也没看到。
tcpdump -i eth0 -n host my.remoteserver.com -P out -vvv
【问题讨论】: