在CentOS上自定義Filebeat的輸出格式,您需要編輯Filebeat的配置文件filebeat.yml。以下是自定義輸出格式的步驟:
打開終端。
使用文本編輯器(如vi、nano等)打開filebeat.yml配置文件。通常位于/etc/filebeat/filebeat.yml。例如,使用vi編輯器,輸入以下命令:
sudo vi /etc/filebeat/filebeat.yml
在filebeat.yml文件中,找到output部分。如果沒有這個部分,請添加它。然后,在output部分下,您可以定義自己的輸出模塊和格式。例如,如果您想將日志發送到Elasticsearch并自定義輸出格式,可以使用以下配置:
output.elasticsearch:
hosts: ["localhost:9200"]
index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"
pipeline: "filebeat-%{[agent.version]}"
template.name: "filebeat-template"
template.enabled: true
template.id: "filebeat-template"
template.version: 3
template.source: |
{
"index_patterns": ["filebeat-*"],
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"_source": {
"enabled": true
},
"properties": {
"@timestamp": {
"type": "date"
},
"message": {
"type": "text"
},
"filebeat": {
"properties": {
"beat": {
"properties": {
"name": {
"type": "keyword"
},
"version": {
"type": "keyword"
}
}
},
"input_type": {
"type": "keyword"
},
"source": {
"type": "keyword"
},
"offset": {
"type": "long"
},
"file": {
"properties": {
"path": {
"type": "keyword"
}
}
},
"log": {
"type": "object"
},
"stream": {
"type": "keyword"
}
}
}
}
}
}
在這個例子中,我們定義了一個Elasticsearch輸出模塊,并自定義了索引名稱、模板ID和映射。
保存并關閉filebeat.yml文件。
重新啟動Filebeat服務以應用更改:
sudo systemctl restart filebeat
現在,Filebeat將使用您自定義的輸出格式發送日志到Elasticsearch。請注意,這個例子是針對Elasticsearch輸出模塊的。如果您使用其他輸出模塊(如Logstash或消息隊列),則需要根據相應的文檔進行配置。