duanhe0817825
duanhe0817825
采纳率100%
2018-12-09 07:10

Logstash与tcp,错误:java.io.IOException:连接被对等方重置

已采纳

我想在我的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}

Code in 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)
}
}

当我试图请求登录应用程序时,终端会显示这个错误:

[2018-12-09T09:12:41,954][ERROR][logstash.inputs.tcp ] Error in Netty pipeline: java.io.IOException: Connection reset by peer

所有的东西都在我的本地系统中。请帮帮我!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答