elasticsearch - 带有 tcp 的 Logstash,错误:java.io.IOException: Connection reset by peer
问题描述
我想在我的 golangApp 中使用 logstash。
/etc/logstash/conf.d/first-pipeline.conf
input {
tcp {
port => 5959
codec => json
}
}
#filter {}
output {
elasticsearch {
hosts => [ "localhost:9200" ]
}
}
和运行 logstash 的命令:
/usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/first-pipeline.conf --path.settings=/etc/logstash
Sending Logstash logs to /var/log/logstash which is now configured via log4j2.properties
[2018-12-09T09:11:14,984][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified
[2018-12-09T09:11:14,995][INFO ][logstash.runner ] Starting Logstash {"logstash.version"=>"6.5.1"}
[2018-12-09T09:11:16,968][INFO ][logstash.pipeline ] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>4, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50}
[2018-12-09T09:11:17,347][INFO ][logstash.outputs.elasticsearch] Elasticsearch pool URLs updated {:changes=>{:removed=>[], :added=>[http://localhost:9200/]}}
[2018-12-09T09:11:17,356][INFO ][logstash.outputs.elasticsearch] Running health check to see if an Elasticsearch connection is working {:healthcheck_url=>http://localhost:9200/, :path=>"/"}
[2018-12-09T09:11:17,589][WARN ][logstash.outputs.elasticsearch] Restored connection to ES instance {:url=>"http://localhost:9200/"}
[2018-12-09T09:11:17,655][INFO ][logstash.outputs.elasticsearch] ES Output version determined {:es_version=>6}
[2018-12-09T09:11:17,660][WARN ][logstash.outputs.elasticsearch] Detected a 6.x and above cluster: the `type` event field won't be used to determine the document _type {:es_version=>6}
[2018-12-09T09:11:17,692][INFO ][logstash.outputs.elasticsearch] New Elasticsearch output {:class=>"LogStash::Outputs::ElasticSearch", :hosts=>["//localhost:9200"]}
[2018-12-09T09:11:17,730][INFO ][logstash.outputs.elasticsearch] Using mapping template from {:path=>nil}
[2018-12-09T09:11:17,786][INFO ][logstash.outputs.elasticsearch] Attempting to install template {:manage_template=>{"template"=>"logstash-*", "version"=>60001, "settings"=>{"index.refresh_interval"=>"5s"}, "mappings"=>{"_default_"=>{"dynamic_templates"=>[{"message_field"=>{"path_match"=>"message", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false}}}, {"string_fields"=>{"match"=>"*", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false, "fields"=>{"keyword"=>{"type"=>"keyword", "ignore_above"=>256}}}}}], "properties"=>{"@timestamp"=>{"type"=>"date"}, "@version"=>{"type"=>"keyword"}, "geoip"=>{"dynamic"=>true, "properties"=>{"ip"=>{"type"=>"ip"}, "location"=>{"type"=>"geo_point"}, "latitude"=>{"type"=>"half_float"}, "longitude"=>{"type"=>"half_float"}}}}}}}}
[2018-12-09T09:11:17,809][INFO ][logstash.inputs.tcp ] Automatically switching from json to json_lines codec {:plugin=>"tcp"}
[2018-12-09T09:11:17,862][INFO ][logstash.inputs.tcp ] Starting tcp input listener {:address=>"0.0.0.0:5959", :ssl_enable=>"false"}
[2018-12-09T09:11:18,097][INFO ][logstash.pipeline ] Pipeline started successfully {:pipeline_id=>"main", :thread=>"#<Thread:0x42d68f8e run>"}
[2018-12-09T09:11:18,157][INFO ][logstash.agent ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
[2018-12-09T09:11:18,329][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600}
golang 中的代码:
import (
"encoding/json"
"fmt"
"github.com/heatxsink/go-logstash"
"time"
)
func main() {
l := logstash.New("0.0.0.0", 5959, 5)
_, err := l.Connect()
if err != nil {
fmt.Println(err)
}
dataMap := map[string]int{"apple": 5, "lettuce": 7}
jsonMap, _ := json.Marshal(dataMap)
err = l.Writeln(string(jsonMap))
if err != nil {
fmt.Println(err)
}
}
当我尝试在应用程序中请求logstash时。显示终端的此错误结束:
[2018-12-09T09:12:41,954][ERROR][logstash.inputs.tcp] Netty 管道中的错误:java.io.IOException: Connection reset by peer
每件事都在我的本地系统中。可以帮帮我,拜托!
解决方案
推荐阅读
- google-analytics-api - 为什么从 Google Analytics Reporting API 返回的数据行包含指标的零值?
- firebase - 使用 Vue js 进行 Firebase 查询
- java - 从 BigQuery 读取并将数据存储到 Google 存储(特殊字符问题)
- java - Selenium 无法识别 IE 中新打开的浏览器上的元素
- dart - 安装软件包时出现握手错误
- c# - 为什么正则表达式计数在 C# 中用作长度?
- fpu - gem5 (Alpha) 如何执行浮点运算?
- .net-core - Razor Pages - 返回模型值
- python - 来自本体语料库 Unicode 错误的 Gensim 句子
- python - 对 MonetDB 的插入不是持久的