如何在Docker Compose中配置Logstash?

时间:2019-03-27 07:07:37

标签: java docker elasticsearch docker-compose logstash

我正在设置Docker容器,但无法将logstash配置为在AWS中运行的elasticsearch。

文件夹结构如下

.
├── logstash
│   └── logstash.conf
├── docker-compose.yml
├── Dockerfile
├── file.jar

./ logstash / logstash.conf文件外观

(当我们使用jar启动服务器时,输入路径下方的日志文件夹将自动平行于jar文件创建)

input {

  file {
          path => "/java_pro/log/*/*/*.log"
          type => "json"
        }
}

output {
   elasticsearch {
         hosts => [ "https://search-***********.es.amazonaws.com:443" ]
         index => "logback-%{+YYYY-MM-dd}"
   }
}

Dockerfile

FROM java:8
RUN mkdir -p /java_pro
WORKDIR /java_pro
COPY . /java_pro
EXPOSE 443
CMD java -jar file.jar

docker-compose.yml

version: "3"
services:
hub:
  build: .
  volumes:
    - .:/java_pro
    - static_volume:/java_pro
  networks:
    - rabbitmq-networks
rabbitmq:
  image: "rabbitmq:3-management"
  ports:
    - "5672:5672"
    - "15672:15672"
  volumes:
    - "rabbitmq_data:/data"
  networks:
    - rabbitmq-networks
  environment:
    - RABBITMQ_DEFAULT_USER=****
    - RABBITMQ_DEFAULT_PASS=****
logstash:
  image: docker.elastic.co/logstash/logstash:6.4.0
  ports:
    - "9200:9200"
  command: logstash -f /etc/logstash/conf.d/logstash.conf
  volumes:
    - ./logstash/logstash.conf:/etc/logstash/conf.d
  environment:
    LS_JAVA_OPTS: "-Xmx256m -Xms256m"
  networks:
    - rabbitmq-networks

networks:
  rabbitmq-networks:
    driver: bridge

volumes:
  rabbitmq_data:
  static_volume:

Elasticsearch已在AWS中启动并运行。 使用docker-compose up运行时出现错误

No config files found in path {:path=>"/etc/logstash/conf.d/logstash.conf"}
Running health check to see if an Elasticsearch connection is working {:healthcheck_url=>http://elasticsearch:9200/, :path=>"/"}
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"}  

如何解决上述错误,并希望使用logstash将所有日志从应用程序推送到elasticsearch。

1 个答案:

答案 0 :(得分:0)

您在此处装入文件作为目录名称:

volumes:
    - ./logstash/logstash.conf:/etc/logstash/conf.d

在装入单个文件时包括文件名:

volumes:
    - ./logstash/logstash.conf:/etc/logstash/conf.d/logstash.conf:ro

由于容器可能不会修改此文件,因此我也将其标记为只读。