gpt4 book ai didi

java - 如何在docker compose中配置logstash?

转载 作者:行者123 更新时间:2023-11-30 05:42:48 26 4
gpt4 key购买 nike

我正在设置 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。

最佳答案

您在此处安装了一个文件作为目录名称:

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

挂载单个文件时包含文件名:

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

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

关于java - 如何在docker compose中配置logstash?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55371569/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com