下面以 Debian 11/12 为例,说明如何安装和配置 Filebeat(Elastic 官方日志采集器)。
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
配置文件路径:
/etc/filebeat/filebeat.yml
示例:采集 /var/log/*.log
filebeat.inputs:
- type: filestream
enabled: true
paths:
- /var/log/*.log
⚠️ 旧版本使用
log类型,新版本推荐filestream
output.elasticsearch:
hosts: ["localhost:9200"]
username: "elastic"
password: "your_password"
如未启用安全,可去掉 username/password
output.logstash:
hosts: ["localhost:5044"]
output.file:
path: "/tmp/filebeat"
filename: filebeat.out
sudo systemctl enable filebeat
sudo systemctl start filebeat
查看状态:
sudo systemctl status filebeat
sudo filebeat test config
sudo filebeat test output
sudo journalctl -u filebeat -f
filebeat.inputs:
- type: filestream
enabled: true
paths:
- /var/log/nginx/access.log
- /var/log/nginx/error.log
如输出到 Elasticsearch,可直接在 Kibana 中查看索引:
filebeat-*
sudo usermod -aG adm filebeat
sudo systemctl restart filebeat
确认系统时间正确:
timedatectl
sudo apt remove --purge filebeat
sudo rm -rf /etc/filebeat /var/lib/filebeat
如果你愿意,我可以帮你:
直接告诉我你的使用场景即可。