下面给你一份在 Debian 上配置 Filebeat 的实用指南,从安装到常见配置示例都有。
sudo apt update
sudo apt install -y curl gnupg apt-transport-https
# 添加 Elastic 官方 GPG
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elastic-keyring.gpg
# 添加 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
sudo apt update
sudo apt install -y filebeat
如果你用的是 7.x,把
8.x改成7.x
主配置文件:
/etc/filebeat/filebeat.yml
filebeat.inputs:
- type: filestream
id: system-log
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["http://localhost:9200"]
username: "elastic"
password: "your_password"
启动:
sudo systemctl enable filebeat
sudo systemctl start filebeat
filebeat.inputs:
- type: filestream
id: nginx-access
paths:
- /var/log/nginx/access.log
fields:
service: nginx
output.elasticsearch:
hosts: ["http://localhost:9200"]
filebeat.inputs:
- type: filestream
id: app-log
paths:
- /opt/app/logs/*.log
output.logstash:
hosts: ["logstash:5044"]
filebeat.inputs:
- type: filestream
id: java-app
paths:
- /opt/app/logs/app.log
multiline:
type: pattern
pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
negate: true
match: after
sudo filebeat setup --index-management -E output.elasticsearch.hosts=["localhost:9200"]
# 查看状态
systemctl status filebeat
# 测试配置
filebeat test config
# 测试输出
filebeat test output
# 查看日志
journalctl -u filebeat -f
确保 filebeat 能读日志:
sudo usermod -aG adm filebeat
paths 是否正确journalctl -u filebeat如果你告诉我:
我可以直接给你一份可复制的完整配置。