使用elasticsearch和filebeat做日志收集
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用elasticsearch和filebeat做日志收集相关的知识,希望对你有一定的参考价值。
在存储数据之前,elasticsearch可以使用Ingest Node对数据做预处理。
https://www.elastic.co/guide/en/beats/filebeat/current/configuring-ingest-node.html
1 使用ingest功能
1.1 定义一个pipeline
例如grib2-pipeline.json
grok可以使用预定义Patterns(%{Pattern:name}匹配提取字段),也可以直接使用正则表达式(分组命名提取字段)
1.2 将pipeline添加到elasticsearch中
curl -H ‘Content-Type: application/json‘ -XPUT ‘http://localhost:9200/_ingest/pipeline/grib2‘ [email protected]
1.3 如何使用ingest功能
https://www.elastic.co/guide/en/elasticsearch/reference/6.4/ingest.html
PUT my-index/_doc/my-id?pipeline=my_pipeline_id
{
"foo": "bar"
}
2 配置filebeat
2.1 新建 ack.yml文件
filebeat.inputs:
- type: log
paths:
- /opt/deploy/storm/logs/workers-artifacts/grib2*/*/worker.log
include_lines: [‘ack ‘]
output.elasticsearch:
hosts: ["127.0.0.1:9200"]
pipeline: grib2
index: "grib2-%{+yyyy.MM.dd}"
setup.template.name: "grib2"
setup.template.pattern: "grib2-*"
通过setup.template.name|pattern 和 output.elasticsearch.index配置索引的名称,便于将来的使用。
2.2 启动filebeat
nohup ./filebeat -c ack.yml &
-c 指定配置文件;nohup & 后台运行;
3 检索日志
http://localhost:9200/grib2*/_search
以上是关于使用elasticsearch和filebeat做日志收集的主要内容,如果未能解决你的问题,请参考以下文章
elasticsearch+filebeat+kibana jmeter分布式日志
配置Filebeat将数据直接输入elasticsearch
最简化 Elasticsearch & Kibana & Filebeat 安装说明
Elastic+logstash+filebeat做Nginx日志分析