我在使用 Logstash 时遇到了一个奇怪的问题。我提供一个日志文件作为logstash 的输入。配置如下:
input {
file {
type => "apache-access"
path => ["C:\Users\spanguluri\Downloads\logstash\bin\test.log"]
}
}
output {
elasticsearch {
protocol => "http"
host => "10.35.143.93"
port => "9200"
index => "latestindex"
}
}
我已经在运行elasticsearch服务器并验证是否正在接收数据 卷曲查询。问题是,当输入是
file
时,没有接收到数据。但是,如果我将输入更改为 stdin { }
,如下所示,它会顺利发送所有输入数据:
input {
stdin{ }
}
output {
elasticsearch {
protocol => "http"
host => "10.35.143.93"
port => "9200"
index => "latestindex"
}
}
我不明白我哪里错了。有人可以看一下这个吗?
您应该在文件部分下设置 start_position :
start_position => "beginning"
它默认为结束,因此不会读取文件中的任何现有行,只会读取新添加的行:
起始位置
Value can be any of: "beginning", "end" Default value is "end"
选择 Logstash 最初开始读取文件的位置:开头 或在最后。默认行为将文件视为实时流和 因此从最后开始。如果您有要导入的旧数据,请设置 这是‘开始’
此选项仅修改文件所在的“首次接触”情况 新的并且以前没有见过。如果之前已经看过某个文件,则此 选项无效。
除了提供的答案之外,我还必须将路径从 c:\my\path 更改为 c:/my/path 才能读取文件。
尝试在 docker 上调试 ELK 设置的人,请将日志文件添加到logstash 的卷中,并在logstash.conf 中指定它
input {
file {
path => "/usr/share/logstash/app.log" # Update this path to the actual path of your app.log file
start_position => "beginning"
sincedb_path => "/dev/null" # Disable sincedb tracking
}
}
filter {
}
output {
elasticsearch {
hosts => "${SOME_ENV_VARIABLE_IN_ADDITION_TO_OTHERS_IF_YOU_USE_ELASTIC}"
}
stdout {
codec => rubydebug
}
}
如果您指定了 stdout 配置,您应该会在 Logstash 的 docker 日志上看到您的日志。