Ubuntu 上 Filebeat 数据存储配置指南
一 关键目录与默认路径
path:
data: /custom/data/location
logs: /custom/logs/location
sudo systemctl restart filebeat
sudo systemctl status filebeat
journalctl -u filebeat -f
以上路径与操作为 Ubuntu/Debian 常见默认位置与做法,适用于 Filebeat 的本地状态与数据存放管理。
二 将数据写入外部存储的常用方式
output.elasticsearch:
hosts: ["localhost:9200"]
index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"
output.redis:
hosts: ["localhost:6379"]
key: "filebeat_logs"
output.logstash:
hosts: ["localhost:5044"]
说明:Filebeat 原生输出并不包含 MySQL;如需落库,通常使用 Logstash JDBC 将 Logstash 接收到的事件写入 MySQL。
三 索引与生命周期管理
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/example.com.access.log
fields:
domain: example.com
fields_under_root: true
- type: log
enabled: true
paths:
- /var/log/nginx/api.example.com.access.log
fields:
domain: api.example.com
fields_under_root: true
output.elasticsearch:
hosts: ["localhost:9200"]
indices:
- index: "example-com-%{+yyyy.MM.dd}"
when.equals:
domain: "example.com"
- index: "api-example-com-%{+yyyy.MM.dd}"
when.equals:
domain: "api.example.com"
setup.ilm.enabled: true
setup.ilm.rollover_alias: "filebeat"
setup.ilm.pattern: "{now/d}-000001"
setup.ilm.policy_name: "filebeat-policy"
并在 Elasticsearch 中创建相应 ILM 策略(如按大小或时间滚动,30 天后删除等),以实现热温冷分层与自动清理。四 验证与运维要点
sudo systemctl start filebeat
sudo systemctl enable filebeat
sudo systemctl status filebeat
journalctl -u filebeat -f
curl -X GET "localhost:9200/_cat/indices?v"