在 Debian 上用 Filebeat 一般流程是:安装 → 配置 → 启动 → 验证。下面给你一个从零到可用的完整示例,假设你是要把日志发送到 Elasticsearch 或 Logstash。
# 1. 安装依赖
sudo apt update
sudo apt install curl gpg -y
# 2. 导入 Elastic GPG 密钥
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | \
sudo gpg --dearmor -o /usr/share/keyrings/elastic-keyring.gpg
# 3. 添加 Elastic APT 源
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
# 4. 安装 Filebeat
sudo apt update
sudo apt install filebeat -y
如果你用的是 7.x,把
8.x改成7.x
配置文件位置:
/etc/filebeat/filebeat.yml
filebeat.inputs:
- type: filestream
enabled: true
paths:
- /var/log/*.log
- /var/log/syslog
output.elasticsearch:
hosts: ["localhost:9200"]
logging.level: info
output.elasticsearch:
hosts: ["http://localhost:9200"]
如果 ES 有账号密码:
output.elasticsearch:
hosts: ["https://es.example.com:9200"]
username: "elastic"
password: "your_password"
output.logstash:
hosts: ["localhost:5044"]
Logstash 示例配置:
input {
beats {
port => 5044
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
}
}
sudo systemctl enable filebeat
sudo systemctl start filebeat
查看状态:
sudo systemctl status filebeat
sudo journalctl -u filebeat -f
或:
/var/log/filebeat/filebeat
curl -X GET "localhost:9200/_cat/indices?v"
Filebeat 自带很多模块(nginx、system、mysql 等)
sudo filebeat modules enable system
sudo filebeat modules list
sudo filebeat setup
setup会创建索引模板、仪表盘(Kibana)
sudo usermod -aG adm filebeat
sudo usermod -aG systemd-journal filebeat
sudo filebeat test config
sudo filebeat test output
sudo apt install filebeat
sudo vi /etc/filebeat/filebeat.yml
sudo systemctl restart filebeat
如果你愿意,可以告诉我:
我可以给你一份 完全贴合你环境的 Filebeat 配置。