Filebeat的基本使用_我就是我的博客-CSDN博客_filebeat
一篇文章搞懂filebeat(ELK) - 一寸HUI - 博客园
Filebeat是用于转发和集中日志数据的轻量级传送工具。Filebeat监视您指定的日志文件或位置,收集日志事件,并将它们转发到Elasticsearch或 Logstash进行索引。
Filebeat的工作方式如下:启动Filebeat时,它将启动一个或多个输入,这些输入将在为日志数据指定的位置中查找。对于Filebeat所找到的每个日志,Filebeat都会启动收集器。每个收集器都读取单个日志以获取新内容,并将新日志数据发送到libbeat,libbeat将聚集事件,并将聚集的数据发送到为Filebeat配置的输出。
工作的流程图如下:
Filebeat收集日志并输出到控制台
编辑vim test-filebeat.yml 文件
vim test-filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /data/logs/youyue/api*.log
fields:
api_name: pay/center
fields_under_root: true
- type: log
enabled: true
paths:
- /data/logs/youyue/admin*.log
fields:
admin_name: admin
fields_under_root: true
output.console:
pretty: true
读取.log结尾的日志数据并输出到控制台
## -d 以debug方式启动
./filebeat -e -c test-filebeat.yml -d "publish"
返回结果
Filebeat收集Nginx运行日志并输出到es
vim filebeat-es.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /data/logs/youyue/api*.log
fields:
api_name: pay/center
fields_under_root: true
tags: ["nginx"]
- type: log
enabled: true
paths:
- /data/logs/youyue/admin*.log
fields:
admin_name: admin
fields_under_root: true
tags: ["nginx"]
setup.template.settings:
index.number_of_shards: 1
output.elasticsearch:
hosts: ["http://localhost:9200"]
前提需要开启elasticsearch
启动filebeat
查看是否存储到elasticsearch
基于Nginx module使用Filebeat收集Nginx运行日志并输出到es
## 查看module集合
./filebeat modules list
## 启用module
./filebeat modules enable module名称
## 禁用module
./filebeat modules disable module名称
启动nginx module
./filebeat modules enable nginx
配置Nginx Module
Nginx Module配置文件路径 ${FILEBEAT_HOME}/modules.d/nginx.yml
备注:未启用的module配置文件 后缀是.disabled
- module: nginx
# Access logs
access:
enabled: true
var.paths: ["/data/logs/youyue/*.log"]
# Error logs
error:
enabled: true
var.paths: ["/home/wwwlogs/nginx_error.log"]
# Ingress-nginx controller logs. This is disabled by default. It could be used in Kubernetes environments to parse ingress-nginx logs
ingress_controller:
enabled: false
# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:
配置filebeat
## 模块日志
filebeat.inputs:
filebeat.config.modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: true
reload.period: 10s # 对路径下的文件进行更改检查的周期
setup.template.settings:
index.number_of_shards: 1
output.elasticsearch:
hosts: ["http://localhost:9200"]
Filebeat配置检测报 “setup.template.name and setup.template.pattern have to be set if index name is modified” 错误
解决方案:这个错误本身提示很明显,只要我们配置了索引名格式,就必须要同时配置setup.template.name 和setup.template.pattern,但是,我配置了这两项怎么还是不行呢,还是同样的错误,重点来了:这两项的配置必须要顶格配置,不可以和index对齐写到一个缩进级别!这个是很容易写错的,大家注意!正确的写法: