我一直在寻找从 Windows 发送日志的选项,我已经设置了 Logstash,并且目前我使用 Logstash-forwarder 和 ssl 加密将日志从 Linux (CentOS) 服务器发送到我的 ELK 堆栈。
出于合规性原因,加密在这种环境中非常重要。
我本来希望在 Windows 中也使用 Logstash-forwarder,但是在使用 Go 编译后,我遇到了传送事件日志的问题,并且我发现有些人说由于文件锁定问题而无法实现,logstash-forwarder人们似乎正在努力,但我真的等不及了。
不管怎样,最终我发现 nxlog 似乎能够使用 ssl 以加密格式发送日志,我发现了一个few posts about similar topics虽然我已经了解了很多关于如何传送日志以及如何设置 nxlog 的知识,但我仍然不知道如何设置 Logstash 来接受日志以便我可以处理它们。
我在 #nxlog 和 #logstash irc 频道中询问过,并在 #nxlog 中得到了一些确认,认为这是可能的,但没有关于如何配置它的进一步信息。
无论如何,我已经获取了为与我的logstash转发器一起使用而创建的crt文件(如果需要,当我很高兴这将起作用时,我将创建一个新文件)并使用pem扩展名将其重命名,我相信它应该按原样工作以 ASCII 格式可读。我已经为 %CERTDIR% 创建了环境变量并将我的文件放在那里,我从我读过的其他文章中为 nxlog 编写了以下配置文件,我认为这是正确的,但我不是 100% 确定:
## This is a sample configuration file. See the nxlog reference manual about the
## configuration options. It should be installed locally and is also available
## online at http://nxlog.org/nxlog-docs/en/nxlog-reference-manual.html
## Please set the ROOT to the folder your nxlog was installed into,
## otherwise it will not start.
#define ROOT C:\Program Files\nxlog
define ROOT C:\Program Files (x86)\nxlog
Moduledir %ROOT%\modules
CacheDir %ROOT%\data
Pidfile %ROOT%\data\nxlog.pid
SpoolDir %ROOT%\data
LogFile %ROOT%\data\nxlog.log
# Enable json extension
<Extension json>
Module xm_json
</Extension>
# Nxlog internal logs
<Input internal>
Module im_internal
Exec $EventReceivedTime = integer($EventReceivedTime) / 1000000; to_json();
</Input>
# Windows Event Log
<Input eventlog>
# Uncomment im_msvistalog for Windows Vista/2008 and later
Module im_msvistalog
# Uncomment im_mseventlog for Windows XP/2000/2003
# Module im_mseventlog
Exec $EventReceivedTime = integer($EventReceivedTime) / 1000000; to_json();
</Input>
<Output sslout>
Module om_ssl
Host lumberjack.domain.com
Port 5000
CertFile %CERTDIR%/logstash-forwarder.crt
AllowUntrusted TRUE
OutputType Binary
</Output>
<Route 1>
Path eventlog, internal => sslout
</Route>
我想知道的是logstash中使用什么输入格式我尝试使用以下配置将日志发送到伐木工输入类型(使用与我的logstash转发器使用的相同的配置):
input {
lumberjack {
port => 5000
type => "logs"
ssl_certificate => "/etc/pki/tls/certs/logstash-forwarder.crt"
ssl_key => "/etc/pki/tls/private/logstash-forwarder.key"
}
}
但是当服务启动时,我在 nxlog 日志文件中收到以下内容:
2014-11-06 21:16:20 INFO connecting to lumberjack.domain.com:5000
2014-11-06 21:16:20 INFO nxlog-ce-2.8.1248 started
2014-11-06 21:16:21 INFO successfully connected to lumberjack.domain.com:5000
2014-11-06 21:16:22 INFO remote closed SSL socket
2014-11-06 21:16:22 INFO reconnecting in 1 seconds
2014-11-06 21:16:23 INFO connecting to lumberjack.domain.com:5000
2014-11-06 21:16:24 INFO reconnecting in 2 seconds
2014-11-06 21:16:24 ERROR couldn't connect to ssl socket on lumberjack.antmarketing.com:5000; No connection could be made because the target machine actively refused it.
当我将日志记录设置为“调试”时,我看到大量日志飞过,但我认为关键部分是:
2014-11-06 21:20:18 ERROR Exception was caused by "rv" at om_ssl.c:532/io_err_handler(); [om_ssl.c:532/io_err_handler()] -; [om_ssl.c:501/om_ssl_connect()] couldn't connect to ssl socket on lumberjack.domain.com:5000; No connection could be made because the target machine actively refused it.
我认为这表明我在logstash上使用了错误的输入方法,但我想这也可能是我的ssl证书或其配置方式的问题。当我从 Windows 计算机建立连接时,我似乎没有在 Logstash 服务器上生成任何日志。