要在CentOS上自定义Filebeat的输出格式,您需要编辑Filebeat的配置文件filebeat.yml
sudo vi /etc/filebeat/filebeat.yml
在filebeat.yml
文件中找到output.elasticsearch
部分。如果您使用的是Logstash作为输出,那么应该找到output.logstash
部分。如果没有找到,请在文件末尾添加相应的部分。
自定义输出格式。以下是一个将日志发送到Elasticsearch的自定义输出格式示例:
output.elasticsearch:
hosts: ["localhost:9200"]
index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"
pipeline: "filebeat-pipeline"
在这个例子中,我们将日志发送到本地的Elasticsearch实例,并使用一个名为filebeat-pipeline
的预定义管道。您可以根据需要修改这些设置。
logstash.conf
:sudo vi /etc/logstash/conf.d/logstash.conf
logstash.conf
文件中,找到filebeat
输入插件部分。如果没有找到,请在文件末尾添加相应的部分。然后,在output
部分自定义输出格式。以下是一个将日志发送到Elasticsearch的自定义输出格式示例:input {
beats {
port => 5044
}
}
filter {
# 在这里添加您的过滤器配置
}
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"
document_type => "_doc"
pipeline => "filebeat-pipeline"
}
}
在这个例子中,我们将日志发送到本地的Elasticsearch实例,并使用一个名为filebeat-pipeline
的预定义管道。您可以根据需要修改这些设置。
保存并关闭配置文件。
重启Filebeat和Logstash服务以应用更改:
sudo systemctl restart filebeat
sudo systemctl restart logstash
现在,Filebeat应该会按照您自定义的输出格式将日志发送到Elasticsearch。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: centos怎么离线安装docker