下面以 Debian 11/12 为例,系统讲解如何安装和配置 Filebeat(Elastic 官方轻量级日志采集器)。
sudo apt update
sudo apt install filebeat -y
安装完成后:
/etc/filebeat/filebeat.yml/etc/filebeat/modules.d/filebeatwget -qO - 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.list
sudo apt update
sudo apt install filebeat -y
编辑配置文件:
sudo nano /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"
⚠️ 如果是 Elasticsearch 8.x,默认开启安全认证,需要用户名密码或 API Key
sudo filebeat modules enable system
sudo filebeat modules list
/etc/filebeat/modules.d/system.yml
第一次使用需要执行:
sudo filebeat setup
该命令会:
sudo systemctl enable filebeat
sudo systemctl start filebeat
sudo systemctl status filebeat
sudo filectl status
journalctl -u filebeat -f
测试配置是否正确:
sudo filebeat test config
sudo filebeat test output
output.logstash:
hosts: ["localhost:5044"]
output.kafka:
hosts: ["kafka:9092"]
topic: "filebeat-logs"
检查:
sudo filebeat test output
sudo filebeat setup --dashboards
如果你有 具体场景(如 Nginx、Docker、K8s、ELK 版本),我可以给你一份 针对性配置示例。