分类说明:
A:不支持索引声明周期管理
B:支持索引声明周期管理
C:支持日期格式的支持索引声明周期管理
A:Filebeat 自定义索引名
本文中涉及的配置文件非完整,只是针对性的在普通版基础上进行修改
# 对filebeat.yaml配置文件修改
# 1 添加 tags: ["test"],作为筛选标识
filebeat.inputs:
- type: log
enabled: true
tags: ["test"]
paths:
- /var/log/nginx/*
# 2 筛选并定义索引(该方法确实能改变默认索引名,但是不支持索引生命周期管理)
output.elasticsearch:
hosts: ['192.168.10.10:9200']
indices:
- index: "test"
when.contains:
tags: "test"
B:Filebeat 自定义索引名
前奏:创建索引生命周期策略及索引模板
# 1 创建索引生命周期策略 test_policy (本文采用Kiban图形界面创建)
# 2 创建索引模板 test_(本文采用Kiban图形界面创建)
# 其中,设置别名是必须要做的,关键
主题:配置 Filebeat
# 1 filebeat.yaml 修改
# 1.1 添加 tags: ["test"],作为筛选标识
filebeat.inputs:
- type: log
enabled: true
tags: ["test"]
paths:
- /var/log/nginx/*
# 1.2 筛选并定义索引
output.elasticsearch:
hosts: ['192.168.10.10:9200']
indices:
- index: "test-000001"
when.contains:
tags: "test"
# 2 启动 filebeat
# 3 filebeat.yaml 修改
output.elasticsearch:
hosts: ['192.168.10.10:9200']
indices:
- index: "test"
when.contains:
tags: "test"
# 4 重启 filebeat
前四步目的是 首先创建索引test-000001,再改索引名是为了以后推送消息至索引test*,不然,会一直向test-000001推送消息,就无法实现滚动更新的效果
尾声:Kibana 操作
# 1 索引模板修改-去掉刚才设置的别名
# 目的:为了使刚才创建的索引test-000001有别名test
# 问: 为什么有删了索引模板的别名
# 答: 再赋予索引test-000001别名test后,在滚动更新是,该别名和设置的rollover_alias冲突,因此要删掉别名
# 2 刷新索引
# 此时会看到索引test-000001有别名,并且绑定了索引声明周期策略test_policy
# 3 不断的向/var/log/nginx/目录下的log文件写日志
# 此时会看到索引的动态更新
C:Filebeat 自定义索引名支持日期格式
前奏:创建索引生命周期策略及索引模板(同B)
主题:配置 Filebeat
# 1 filebeat.yaml 修改
# 1.1 添加 tags: ["test"],作为筛选标识
filebeat.inputs:
- type: log
enabled: true
tags: ["test"]
paths:
- /var/log/nginx/*
# 1.2 筛选并定义索引
output.elasticsearch:
hosts: ['192.168.10.10:9200']
indices:
- index: "<test-{now/d}-000001>"
when.contains:
tags: "test"
# 2 启动 filebeat
# 3 filebeat.yaml 修改
output.elasticsearch:
hosts: ['192.168.10.10:9200']
indices:
- index: "test"
when.contains:
tags: "test"
# 4 重启 filebeat
尾声:Kibana 操作(同B)
说明
在C中,一些原理还没搞清楚,欢迎各位指导,但不影响使用。比如多有文章建议 Filebeat 的支持日期的自定义索引名格式为test-%{+yyyy.MM.dd}-000001,但多次实验后发现行不通;报错:虽然会更新,但内容总会写在000001的索引。
如有侵权,请联系删除;如有错误,请批评指正。