Beats是用于单用途数据托运人的平台。它们以轻量级代理的形式安装,并未来自成百上千台机器的数据发送到Logstash或Elasticsearch。linux
(画外音:通俗地理解,就是采集数据,并上报到Logstash或Elasticsearch)浏览器
Beats对于收集数据很是有用。它们位于你的服务器上,将数据集中在Elasticsearch中,Beats也能够发送到Logstash来进行转换和解析。安全
为了捕捉(捕获)数据,Elastic提供了各类Beats:服务器
Beats能够直接(或者经过Logstash)将数据发送到Elasticsearch,在那里你能够进一步处理和加强数据,而后在Kibana中将其可视化。数据结构
配置文件:filebeat.ymlcurl
为了配置Filebeat:elasticsearch
1. 定义日志文件路径ui
对于最基本的Filebeat配置,你可使用单个路径。例如:url
filebeat.inputs: - type: log enabled: true paths: - /var/log/*.log
在这个例子中,获取在/var/log/*.log路径下的全部文件做为输入,这就意味着Filebeat将获取/var/log目录下全部以.log结尾的文件。spa
为了从预约义的子目录级别下抓取全部文件,可使用如下模式:/var/log/*/*.log。这将抓取/var/log的子文件夹下全部的以.log结尾的文件。它不会从/var/log文件夹自己抓取。目前,不可能递归地抓取这个目录下的全部子目录下的全部.log文件。
(画外音:
假设配置的输入路径是/var/log/*/*.log,假设目录结构是这样的:
那么只会抓取到2.log和3.log,而不会抓到1.log和4.log。由于/var/log/aaa/ccc/1.log和/var/log/4.log不会被抓到。
)
2. 若是你发送输出目录到Elasticsearch(而且不用Logstash),那么设置IP地址和端口以便可以找到Elasticsearch:
output.elasticsearch: hosts: ["192.168.1.42:9200"]
3. 若是你打算用Kibana仪表盘,能够这样配置Kibana端点:
setup.kibana: host: "localhost:5601"
4. 若是你的Elasticsearch和Kibana配置了安全策略,那么在你启动Filebeat以前须要在配置文件中指定访问凭据。例如:
output.elasticsearch: hosts: ["myEShost:9200"] username: "filebeat_internal" password: "{pwd}" setup.kibana: host: "mykibanahost:5601" username: "my_kibana_user" password: "{pwd}"
若是你想使用Logstash对Filebeat收集的数据执行额外的处理,那么你须要将Filebeat配置为使用Logstash。
output.logstash: hosts: ["127.0.0.1:5044"]
在Elasticsearch中,索引模板用于定义设置和映射,以肯定如何分析字段。(画外音:至关于定义索引文档的数据结构,由于要把采集的数据转成标准格式输出)
Filebeat包已经安装了推荐的索引模板。若是你接受filebeat.yml中的默认配置,那么Filebeat在成功链接到Elasticsearch之后会自动加载模板。若是模板已经存在,不会覆盖,除非你配置了必须这样作。
经过在Filebeat配置文件中配置模板加载选项,你能够禁用自动模板加载,或者自动加载你本身的目标。
配置模板加载
默认状况下,若是Elasticsearch输出是启用的,那么Filebeat会自动加载推荐的模板文件 ——— fields.yml。
setup.template.name: "your_template_name" setup.template.fields: "path/to/fields.yml"
覆盖一个已存在的模板
setup.template.overwrite: true
禁用自动加载模板
setup.template.enabled: false
修改索引名称
# 默认状况下,Filebeat写事件到名为filebeat-6.3.2-yyyy.MM.dd的索引,其中yyyy.MM.dd是事件被索引的日期。为了用一个不一样的名字,你能够在Elasticsearch输出中设置index选项。例如:
output.elasticsearch.index: "customname-%{[beat.version]}-%{+yyyy.MM.dd}" setup.template.name: "customname" setup.template.pattern: "customname-*" setup.dashboards.index: "customname-*"
手动加载模板
./filebeat setup --template -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["localhost:9200"]'
Filebeat附带了Kibana仪表盘、可视化示例。在你用dashboards以前,你须要建立索引模式,filebeat-*,而且加载dashboards到Kibana中。为此,你能够运行setup命令或者在filebeat.yml配置文件中配置dashboard加载。
./filebeat setup --dashboards
./filebeat -e -c filebeat.yml -d "publish"
http://127.0.0.1:5601
#=========================== Filebeat inputs ============== filebeat.inputs: - type: log enabled: true paths: - /var/log/*.log #============================== Dashboards =============== setup.dashboards.enabled: false #============================== Kibana ================== setup.kibana: host: "192.168.101.5:5601" #-------------------------- Elasticsearch output --------- output.elasticsearch: hosts: ["localhost:9200"]
启动Elasticsearch
/usr/local/programs/elasticsearch/elasticsearch-6.3.2/bin/elasticsearch
启动Kibana
/usr/local/programs/kibana/kibana-6.3.2-linux-x86_64/bin/kibana
设置dashboard
./filebeat setup --dashboards
启动Filebeat
./filebeat -e -c filebeat.yml -d "publish"
浏览器访问 http://192.168.101.5:5601
查看索引
请求:
curl -X GET "localhost:9200/_cat/indices?v"
响应:
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size yellow open bank 59jD3B4FR8iifWWjrdMzUg 5 1 1000 0 475.1kb 475.1kb green open .kibana DzGTSDo9SHSHcNH6rxYHHA 1 0 153 23 216.8kb 216.8kb yellow open filebeat-6.3.2-2018.08.08 otgYPvsgR3Ot-2GDcw_Upg 3 1 255 0 63.7kb 63.7kb yellow open customer DoM-O7QmRk-6f3Iuls7X6Q 5 1 1 0 4.5kb 4.5kb