Debian 与 Filebeat 集成指南
一 环境准备与版本选择
二 安装 Filebeat
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor | sudo tee /usr/share/keyrings/elastic.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/elastic.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list >/dev/null
sudo apt update && sudo apt install -y filebeat
sudo systemctl enable --now filebeat
sudo systemctl status filebeat
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-<VERSION>-amd64.deb
sudo dpkg -i filebeat-<VERSION>-amd64.deb
sudo apt-get -f install # 如有依赖问题
sudo systemctl enable --now filebeat
sudo filebeat test config
sudo filebeat test output
以上步骤覆盖 APT 与 .deb 两种常见安装方式,并包含服务启动与配置校验。
三 配置 Filebeat
sudo cp /etc/filebeat/filebeat.yml /etc/filebeat/filebeat.yml.bak
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["http://localhost:9200"]
index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.logstash:
hosts: ["logstash.example.com:5044"]
sudo filebeat modules enable system nginx
sudo filebeat setup -e
setup.ilm.enabled: false
setup.template.name: "filebeat-custom"
setup.template.pattern: "filebeat-custom-*"
index: "filebeat-custom-%{+yyyy.MM.dd}"
以上示例涵盖直连 ES、输出到 Logstash、模块启用与模板/ILM 的关键配置。
四 启动与验证
sudo systemctl restart filebeat
sudo systemctl status filebeat
sudo journalctl -u filebeat -f
curl -X GET "localhost:9200/_cat/indices?v" | grep filebeat
五 常见问题与优化
filebeat test config 校验。multiline、include_lines、json.keys_under_root 等参数,适合堆栈日志与结构化日志场景。harvester_buffer_size、max_bytes、批量与并发参数调优吞吐;在高并发场景建议输出到 Logstash 或 Kafka 做缓冲与处理。