我遇到一个奇怪的问题,无法解决,因为搜索此错误时,我的问题有所不同。尝试将Filebeat
连接到Logstash
时,人们似乎已经经历过这种情况。
但是,尽管我什至没有在Elasticsearch
中旋转容器,我仍试图将日志直接写入Logstash
,但是却遇到与Docker Compose
相关的错误
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
代表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
我正在尝试读取已经为json
格式的Elasticsearch
日志,因此在阅读了文档之后,我决定尝试直接写入Elasticsearch
,这似乎对应用程序有效,具体取决于应用程序。
我的Sample.json
文件:
{“ @ timestamp”:“ 2020-02-10T09:35:20.7793960 + 00:00”,“ level”:“ Information”,“ messageTemplate”:“ i的值为{LoopCountValue}”,“ message” :“ i的值为0”,“字段”:{“ LoopCountValue”:0,“ SourceContext”:“ WebAppLogger.Startup”,“环境”:“ 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错误pipe / output.go:100无法连接至退避(async(tcp:// logstash:5044)):在127.0.0.11:53上查找logstash:没有此类主机
然后,当我最终尝试可视化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容器中-为什么?????有必要重新发明轮子并增加复杂性? -您应该使用root用户:
USER root