下面以 Debian 11 / 12 为例,说明如何安装和配置 Filebeat(Elastic 官方的日志采集器)。
sudo apt update
sudo apt install -y curl gnupg apt-transport-https
导入 Elastic GPG Key:
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elastic-keyring.gpg
添加 APT 源(以 8.x 为例):
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
安装 Filebeat:
sudo apt update
sudo apt install filebeat
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.x.x-amd64.deb
sudo dpkg -i filebeat-8.x.x-amd64.deb
配置文件路径:
/etc/filebeat/filebeat.yml
filebeat.inputs:
- type: filestream
id: syslog
paths:
- /var/log/syslog
- /var/log/auth.log
output.elasticsearch:
hosts: ["http://localhost:9200"]
username: "elastic"
password: "your_password"
output.logstash:
hosts: ["localhost:5044"]
如果你使用 Elasticsearch + Kibana:
sudo filebeat setup
这会加载:
sudo systemctl enable filebeat
sudo systemctl start filebeat
查看状态:
sudo systemctl status filebeat
journalctl -u filebeat -f
curl -X GET "localhost:9200/_cat/indices?v"
启用模块:
sudo filebeat modules enable nginx
sudo filebeat modules enable system
配置模块:
sudo filebeat modules list
模块配置在:
/etc/filebeat/modules.d/
Filebeat 需要读取日志文件权限:
sudo usermod -aG adm filebeat
如果 ES 开启 TLS:
output.elasticsearch:
hosts: ["https://localhost:9200"]
ssl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
如果你有:
可以告诉我,我可以给你一份针对性配置示例。