简介
Filebeat 是一款轻量级的日志数据采集和转发器。
Filebeat 能够监控日志文件或者指定位置中的文件,收集日志事件,并将其转发到 Elasticsearch 或是 Logstash。
Docker安装Filebeat
拉取镜像
docker pull docker.elastic.co/beats/filebeat:7.17.0
启动Filebeat
指定setup.kibana.host为 Kibana 服务
指定output.elasticsearch.hosts为 Elasticsearch 服务
docker run \
docker.elastic.co/beats/filebeat:7.17.0 \
setup -E setup.kibana.host=kibana:5601 \
-E output.elasticsearch.hosts=["elasticsearch:9200"]
Filebeat配置
下载示例配置文件
curl -L -O https://raw.githubusercontent.com/elastic/beats/7.17/deploy/docker/filebeat.docker.yml
挂载配置文件
docker run -d \
--name=filebeat \
--user=root \
--volume="$(pwd)/filebeat.docker.yml:/usr/share/filebeat/filebeat.yml:ro" \
--volume="/var/lib/docker/containers:/var/lib/docker/containers:ro" \
--volume="/var/run/docker.sock:/var/run/docker.sock:ro" \
docker.elastic.co/beats/filebeat:7.17.0 filebeat -e -strict.perms=false \
-E output.elasticsearch.hosts=["elasticsearch:9200"]
自定义配置
filebeat.docker.yml配置文件是用于部署 Beats 模块的,其配置是基于 Docker label。给 Docker 容器添加标签后,它们就会被 Beats 的自动发现功能获取。
在下面示例中,Apache HTTP 服务器容器添加的标签用于配置 Filebeat 和 Metricbeat 模块。
docker run \
--label co.elastic.logs/module=apache2 \
--label co.elastic.logs/fileset.stdout=access \
--label co.elastic.logs/fileset.stderr=error \
--label co.elastic.metrics/module=apache \
--label co.elastic.metrics/metricsets=status \
--label co.elastic.metrics/hosts='${data.host}:${data.port}' \
--detach=true \
--name my-apache-app \
-p 8080:80 \
httpd:2.4