在 Debian 上把 Filebeat 对接 Elasticsearch(ES) 一般分为「安装 Filebeat → 配置 ES 地址 → 启动并验证」三步。下面给你一个可直接用的实战流程(以 Debian 11/12 为例,ES 假设为 7.x/8.x)。
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
# 添加仓库
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
如果是 ES 7.x,把
8.x改成7.x
sudo vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
- /var/log/nginx/access.log
output.elasticsearch:
hosts: ["http://192.168.1.100:9200"]
username: "elastic"
password: "your_password"
setup.kibana:
host: "http://192.168.1.100:5601"
如果是 ES 8.x + HTTPS
output.elasticsearch:
hosts: ["https://192.168.1.100:9200"]
username: "elastic"
password: "your_password"
ssl:
ca_trusted_fingerprint: "xxxxxx"
sudo filebeat setup --index-management -E output.elasticsearch.username=elastic -E output.elasticsearch.password=your_password
可选(对接 Kibana):
sudo filebeat setup -E setup.kibana.host=http://192.168.1.100:5601
sudo systemctl enable filebeat
sudo systemctl start filebeat
sudo systemctl status filebeat
journalctl -u filebeat -f
curl -u elastic:your_password http://192.168.1.100:9200/_cat/indices?v
应该能看到:
filebeat-8.x.x-YYYY.MM.DD
9200network.hostfilebeat.inputs.enabled: trueoutput.logstash:
hosts: ["192.168.1.101:5044"]
multiline.pattern: '^\['
multiline.negate: true
multiline.match: after
如果你愿意,可以告诉我:
我可以直接给你定制版配置。