Ubuntu 上 Filebeat 的数据传输方式
主要传输方式与典型场景
快速配置示例
直接到 Elasticsearch
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["localhost:9200"]
index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"
说明:将日志直接写入本机 ES,按版本与日期滚动索引。
经由 Logstash Filebeat 配置:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.logstash:
hosts: ["localhost:5044"]
Logstash 配置(示例):
input { beats { port => 5044 } }
filter {
grok { match => { "message" => "%{COMBINEDAPACHELOG}" } }
date { match => [ "timestamp", "dd/MMM/yyyy:HH:mm:ss Z" ] }
}
output { elasticsearch { hosts => ["localhost:9200"] index => "filebeat-%{+YYYY.MM.dd}" } }
说明:Filebeat 向 5044 发送,Logstash 解析后再写入 ES。
写入 Redis
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.redis:
hosts: ["127.0.0.1:6379"]
key: "filebeat-logs"
验证:
redis-cli
> KEYS *
> LRANGE filebeat-logs 0 -1
说明:将事件写入 Redis 列表,键名为 filebeat-logs。
写入 Kafka
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.kafka:
hosts: ["kafka-broker1:9092","kafka-broker2:9092"]
topic: "filebeat-logs"
codec.json:
pretty: false
escape_html: false
说明:Filebeat 作为生产者写入 Kafka topic: filebeat-logs,后续由消费者处理。
选型建议与注意事项