在 Debian 上配置 Filebeat 一般包含:安装 → 配置输入/输出 → 启动 → 验证。下面给你一份常用、可直接用的配置说明(以 Filebeat 把日志发送到 Elasticsearch 或 Logstash 为例)。
sudo apt update
sudo apt install -y curl gnupg apt-transport-https
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elastic-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/elastic-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list
sudo apt update
sudo apt install -y filebeat
版本可改成
7.x,看你 Elasticsearch 版本
主配置文件:
/etc/filebeat/filebeat.yml
filebeat.inputs:
- type: filestream
id: system-logs
paths:
- /var/log/*.log
- /var/log/syslog
output.elasticsearch:
hosts: ["http://localhost:9200"]
username: "elastic"
password: "your_password"
setup.kibana:
host: "http://localhost:5601"
filebeat.inputs:
- type: filestream
id: app-logs
paths:
- /var/log/myapp/*.log
output.logstash:
hosts: ["logstash:5044"]
filebeat.inputs:
- type: filestream
paths:
- /var/log/nginx/*.log
- type: filestream
paths:
- /opt/app/logs/*.log
filebeat.inputs:
- type: filestream
paths:
- /var/log/nginx/access.log
tags: ["nginx", "access"]
sudo filebeat setup --index-management -E output.logstash.enabled=false -E output.elasticsearch.hosts=["localhost:9200"]
或:
sudo filebeat setup
sudo systemctl enable filebeat
sudo systemctl start filebeat
查看状态:
sudo systemctl status filebeat
journalctl -u filebeat -f
sudo filebeat test config
sudo filebeat test output
✅ filestream 是新版本推荐类型(7.14+)
✅ 权限问题:Filebeat 需能读日志文件
✅ Elasticsearch / Logstash 要先启动
✅ 时间同步(NTP)很重要
如果你愿意,可以告诉我:
我可以给你一份完全贴合你环境的配置。