t.me/atinfo_chat Telegram группа по автоматизации тестирования

Connection refused при попытке подключится к elasticsearch в docker

docker
elasticsearch
java
Теги: #<Tag:0x00007f9c59264088> #<Tag:0x00007f9c5926be78> #<Tag:0x00007f9c5926bb30>

(Arina) #1

Всем привет

Проблема заключается в ошибке

][WARN ][logstash.outputs.elasticsearch] Attempted to resurrect connection to dead ES instance, but got an error. {:url=>"http://localhost:9200/", :error_type=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::HostUnreachableError, :error=>"Elasticsearch Unreachable: [http://localhost:9200/][Manticore::SocketException] Connection refused (Connection refused)"}

Я гуглила, но одни пишут, что надо указывать localhost, другие elasticsearch для докера

elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.0.1
    restart: unless-stopped
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      - discovery.type=single-node
      - XPACK_SECURITY_ENABLED=false
      - XPACK_REPORTING_ENABLED=false
      - XPACK_MONITORING_ENABLED=false
#      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    depends_on:
      - logstash


  kibana:
    image: docker.elastic.co/kibana/kibana:7.0.1
    ports:
      - "5601:5601"
    depends_on:
      - elasticsearch
    restart: unless-stopped

  logstash:
    image: docker.elastic.co/logstash/logstash:7.0.1
    networks:
      - elk
    environment:
      - XPACK_SECURITY_ENABLED=false
      - XPACK_REPORTING_ENABLED=false
      - XPACK_MONITORING_ENABLED=false
      - ELASTIC_HOST=localhost:9200
    ports:
      - "5046:5046"
    volumes:
      - ./config/pipelines.yml:/usr/share/logstash/config/pipelines.yml:ro
      - ./config/pipelines:/usr/share/logstash/config/pipelines:ro

habr_pipeline.conf выглядит вот так

input {
  tcp {
    port => "5046"
  }
}
filter {
  mutate {
    add_field => [ "habra_field", "Hello Habr" ]
  }
}
output {
  elasticsearch {
    hosts => "${ELASTIC_HOST}"
    user => ""
    password => ""
    index => "ts_indicator_description"
  }
}

и сами логи logstash

logstash_1       | 2019/06/05 14:03:56 Setting 'xpack.monitoring.enabled' from environment.
logstash_1       | Sending Logstash logs to /usr/share/logstash/logs which is now configured via log4j2.properties
logstash_1       | [2019-06-05T14:05:01,860][INFO ][logstash.setting.writabledirectory] Creating directory {:setting=>"path.queue", :path=>"/usr/share/logstash/data/queue"}
logstash_1       | [2019-06-05T14:05:01,899][INFO ][logstash.setting.writabledirectory] Creating directory {:setting=>"path.dead_letter_queue", :path=>"/usr/share/logstash/data/dead_letter_queue"}
logstash_1       | [2019-06-05T14:05:02,850][INFO ][logstash.runner          ] Starting Logstash {"logstash.version"=>"7.0.1"}
logstash_1       | [2019-06-05T14:05:02,914][INFO ][logstash.agent           ] No persistent UUID file found. Generating new UUID {:uuid=>"a9a7e716-1ccf-48c2-8109-317995181fa5", :path=>"/usr/share/logstash/data/uuid"}
logstash_1       | [2019-06-05T14:05:13,068][INFO ][logstash.outputs.elasticsearch] Elasticsearch pool URLs updated {:changes=>{:removed=>[], :added=>[http://localhost:9200/]}}
logstash_1       | [2019-06-05T14:05:13,413][WARN ][logstash.outputs.elasticsearch] Attempted to resurrect connection to dead ES instance, but got an error. {:url=>"http://localhost:9200/", :error_type=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::HostUnreachableError, :error=>"Elasticsearch Unreachable: [http://localhost:9200/][Manticore::SocketException] Connection refused (Connection refused)"}
logstash_1       | [2019-06-05T14:05:13,457][INFO ][logstash.outputs.elasticsearch] New Elasticsearch output {:class=>"LogStash::Outputs::ElasticSearch", :hosts=>["//localhost:9200"]}
logstash_1       | [2019-06-05T14:05:13,508][INFO ][logstash.javapipeline    ] Starting pipeline {:pipeline_id=>"HABR", "pipeline.workers"=>1, "pipeline.batch.size"=>1, "pipeline.batch.delay"=>50, "pipeline.max_inflight"=>1, :thread=>"#<Thread:0x47788e26 run>"}
logstash_1       | [2019-06-05T14:05:14,041][INFO ][logstash.javapipeline    ] Pipeline started {"pipeline.id"=>"HABR"}
logstash_1       | [2019-06-05T14:05:14,123][INFO ][logstash.inputs.tcp      ] Starting tcp input listener {:address=>"0.0.0.0:5046", :ssl_enable=>"false"}
logstash_1       | [2019-06-05T14:05:14,448][INFO ][logstash.agent           ] Pipelines running {:count=>1, :running_pipelines=>[:HABR], :non_running_pipelines=>[]}
logstash_1       | [2019-06-05T14:05:15,143][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600}
logstash_1       | [2019-06-05T14:05:18,485][WARN ][logstash.outputs.elasticsearch] Attempted to resurrect connection to dead ES instance, but got an error. {:url=>"http://localhost:9200/", :error_type=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::HostUnreachableError, :error=>"Elasticsearch Unreachable: [http://localhost:9200/][Manticore::SocketException] Connection refused (Connection refused)"}

Что тут не верно?

p.s. руками до http://localhost:9200/ могу
p.s.s. смена localhost на elasticsearch тоже не спасла

logstash_1       | [2019-06-05T14:09:32,896][WARN ][logstash.outputs.elasticsearch] Attempted to resurrect connection to dead ES instance, but got an error. {:url=>"http://elasticsearch:9200/", :error_type=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::HostUnreachableError, :error=>"Elasticsearch Unreachable: [http://elasticsearch:9200/][Manticore::ResolutionFailure] elasticsearch"}

(Евгений) #2

ваш сервис logstash в отдельной сети “elk”:

logstash:
    image: docker.elastic.co/logstash/logstash:7.0.1
    networks:
      - elk

в то время как остальные сервисы - нет.
Поэтому можно указать, что и другие сервисы будут в той же сети “elk”, добавив под каждый сервис:

    networks:
      - elk

(Arina) #3

спасибо! помогло!