您的位置:首页 > 其它

使用elasticsearch和filebeat做日志收集

2018-08-29 19:29 926 查看

在存储数据之前,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' -d@grib2-pipeline.json

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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  filebeat pipeline