加载索引模板须要链接到Elasticsearch,若是输出不是Elasticsearch,则必须手动加载模板。
在Elasticsearch中,索引模板用于定义肯定如何分析字段的设置和映射。linux
Filebeat的推荐索引模板文件由Filebeat包安装,若是你接受filebeat.yml
配置文件中的默认配置,Filebeat会在成功链接到Elasticsearch后自动加载模板,若是模板已存在,则除非你配置Filebeat,不然不会覆盖该模板。docker
默认状况下,若是启用了Elasticsearch输出,Filebeat会自动加载推荐的模板文件fields.yml
,若是要使用默认索引模板,则不须要其余配置,不然,你能够将filebeat.yml
配置文件中的默认值更改成:json
加载不一样的模板segmentfault
setup.template.name: "your_template_name" setup.template.fields: "path/to/fields.yml"
若是模板已存在,则除非你配置Filebeat,不然不会覆盖该模板。安全
覆盖现有模板app
setup.template.overwrite: true
禁用自动模板加载curl
setup.template.enabled: false
若是禁用自动模板加载,则须要手动加载模板。elasticsearch
更改索引名称
url
若是要将事件发送到支持索引生命周期管理的集群,请参阅配置索引生命周期管理以了解如何更改索引名称。
code
默认状况下,当禁用或不支持索引生命周期管理时,Filebeat使用时间系列索引,索引名为filebeat-7.3.0-yyyy.MM.dd
,其中yyyy.MM.dd
是事件索引的日期,要使用其余名称,请在Elasticsearch输出中设置index
选项。你指定的值应包括索引的根名称以及版本和日期信息,你还须要配置setup.template.name
和setup.template.pattern
选项以匹配新名称,例如:
output.elasticsearch.index: "customname-%{[agent.version]}-%{+yyyy.MM.dd}" setup.template.name: "customname" setup.template.pattern: "customname-*"
若是你使用的是预先构建的Kibana仪表板,请同时设置setup.dashboards.index
选项,例如:
setup.dashboards.index: "customname-*"
要手动加载模板,请运行setup
命令,须要链接到Elasticsearch,若是启用了另外一个输出,则须要临时禁用该输出并使用-E
选项启用Elasticsearch,此处的示例假定已启用Logstash输出,若是已启用Elasticsearch输出,则能够省略-E
标志。
若是要链接到安全的Elasticsearch集群,请确保已按第2步:配置Filebeat中所述配置凭据。
若是运行Filebeat的主机没有与Elasticsearch的直接链接,请参阅手动加载模板(备用方法)。
要加载模板,请使用适用于你系统的命令。
deb和rpm:
filebeat setup --index-management -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["localhost:9200"]'
mac:
./filebeat setup --index-management -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["localhost:9200"]'
brew:
filebeat setup --index-management -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["localhost:9200"]'
linux:
./filebeat setup --index-management -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["localhost:9200"]'
docker:
docker run docker.elastic.co/beats/filebeat:7.3.0 setup --index-management -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["localhost:9200"]'
win:
以管理员身份打开PowerShell提示符(右键单击PowerShell图标,而后选择“以管理员身份运行”)。
在PowerShell提示符下,切换到Filebeat的安装目录,而后运行:
PS > .\filebeat.exe setup --index-management -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["localhost:9200"]'
若是你已经使用Filebeat将数据索引到Elasticsearch中,则索引可能包含旧文档,加载索引模板后,能够从filebeat-*
中删除旧文档,以强制Kibana查看最新文档。
使用此命令:
deb和rpm:
curl -XDELETE 'http://localhost:9200/filebeat-*'
mac:
curl -XDELETE 'http://localhost:9200/filebeat-*'
linux:
curl -XDELETE 'http://localhost:9200/filebeat-*'
win:
PS > Invoke-RestMethod -Method Delete "http://localhost:9200/filebeat-*"
此命令删除与模式filebeat-*
匹配的全部索引,在运行此命令以前,请确保要删除与该模式匹配的全部索引。
若是运行Filebeat的主机没有与Elasticsearch的直接链接,则能够将索引模板导出到文件,将其移动到具备链接的计算机,而后手动安装模板。
要导出索引模板,请运行:
deb和rpm:
filebeat export template > filebeat.template.json
mac:
./filebeat export template > filebeat.template.json
linux:
./filebeat export template > filebeat.template.json
win:
PS > .\filebeat.exe export template --es.version 7.3.0 | Out-File -Encoding UTF8 filebeat.template.json
要安装模板,请运行:
deb和rpm:
curl -XPUT -H 'Content-Type: application/json' http://localhost:9200/_template/filebeat-7.3.0 -d@filebeat.template.json
mac:
curl -XPUT -H 'Content-Type: application/json' http://localhost:9200/_template/filebeat-7.3.0 -d@filebeat.template.json
linux:
curl -XPUT -H 'Content-Type: application/json' http://localhost:9200/_template/filebeat-7.3.0 -d@filebeat.template.json
win:
PS > Invoke-RestMethod -Method Put -ContentType "application/json" -InFile filebeat.template.json -Uri http://localhost:9200/_template/filebeat-7.3.0