我遇到了一个无法解决的奇怪问题,因为我的问题在搜索此错误时有所不同。人们在尝试将 Filebeat
连接到 Logstash
时似乎遇到过这种情况。
但是,我试图将日志直接写入 Elasticsearch
,但我收到了与 Logstash
相关的错误,即使我什至没有在 Docker 中启动容器撰写
??
主要的 Docker 组合文件:
version: '2.2'
services:
filebeat:
container_name: filebeat
build:
context: .
dockerfile: filebeat.Dockerfile
volumes:
- ./logs:/var/log
networks:
- esnet
elasticsearch:
container_name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:7.5.2
ports:
- 9200:9200
- 9300:9300
environment:
- discovery.type=single-node
- cluster.name=docker-
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
networks:
- esnet
elastichq:
container_name: elastichq
image: elastichq/elasticsearch-hq
ports:
- 8080:5000
environment:
- HQ_DEFAULT_URL=http://elasticsearch:9200
- HQ_ENABLE_SSL=False
- HQ_DEBUG=FALSE
networks:
- esnet
networks:
esnet:
DockerFile
for Filebeat
FROM docker.elastic.co/beats/filebeat:7.5.2
COPY filebeat/filebeat.yml /usr/share/filebeat/filebeat.yml
USER root
RUN chown root:filebeat /usr/share/filebeat/filebeat.yml
RUN chmod 644 /usr/share/filebeat/filebeat.yml
USER filebeat
我正在尝试读取已经采用 Elasticsearch
格式的 json
日志,因此在阅读文档后我决定尝试直接写入 Elasticsearch
这似乎是有效的,具体取决于应用程序。
我的 Sample.json
文件:
{"@timestamp":"2020-02-10T09:35:20.7793960+00:00","level":"Information","messageTemplate":"The value of i is {LoopCountValue}","message":"The value of i is 0","fields":{"LoopCountValue":0,"SourceContext":"WebAppLogger.Startup","Environment":"Development","ApplicationName":"ELK Logging Demo"}}
我的Filebeat.yml
:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.json
json.keys_under_root: true
json.add_error_key: true
json.message_key: log
#----------------------------- Elasticsearch output --------------------------------
output.elasticsearch:
hosts: ["elasticsearch:9200"]
index: "sample-%{+YYYY.MM.dd}"
如本文标题所述,我在控制台中收到此消息:
filebeat | 2020-02-10T09:38:24.438Z ERROR pipeline/output.go:100 Failed to connect to backoff(async(tcp://logstash:5044)): lookup logstash on 127.0.0.11:53: no such host
然后,当我最终尝试可视化 ElasticHq
中的数据时,不可避免地,那里什么也没有。
到目前为止,我已经尝试使用像 docker prune
这样的命令,以防 Docker 发生一些有趣的事情。
有什么我想念的吗?
最佳答案
您错误配置了 filebeat.yml 文件。看看这个错误:
Failed to connect to backoff(async(tcp://logstash:5044))
Filebeat 尝试连接到 logstash,因为这是默认配置。事实上,一方面你显示了一个 filebeat.yml 文件,另一方面,你还没有将它挂载到/usr/share/filebeat/filebeat.yml - 查看你的卷设置
filebeat:
container_name: filebeat
build:
context: .
dockerfile: filebeat.Dockerfile
volumes:
- ./logs:/var/log
networks:
- esnet
你应该安装它。如果您尝试使用 dockerfile 将其复制到 docker 容器中 - 为什么????有必要重新发明轮子并增加复杂性吗? - 你应该使用根用户:
USER root
并在 docker-compose.yml 中将 root 用户添加到您的服务中:
user: root
关于docker - 错误 pipeline/output.go :100 Failed to connect to backoff(async(tcp://logstash:5044)) - ELK Filebeat . NET Core 3.1 Docker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60147800/