在 Debian 下配置 Filebeat(以官方仓库安装为例,适用于 Filebeat 7.x / 8.x),一般流程如下:
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 源
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 filebeat
如果用 7.x:
packages/7.x/apt
/etc/filebeat/
├── filebeat.yml # 主配置文件
└── modules.d/ # 模块配置(nginx、system、mysql 等)
编辑配置文件:
sudo nano /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: filestream
id: system-log
paths:
- /var/log/syslog
- /var/log/auth.log
output.elasticsearch:
hosts: ["http://localhost:9200"]
username: "elastic"
password: "your_password"
setup.kibana:
host: "http://localhost:5601"
filebeat.inputs:
- type: filestream
id: app-log
paths:
- /var/log/myapp/*.log
output.logstash:
hosts: ["localhost:5044"]
sudo filebeat modules enable system
sudo filebeat modules enable nginx
sudo filebeat modules list
sudo nano /etc/filebeat/modules.d/nginx.yml
- module: nginx
access:
enabled: true
var.paths: ["/var/log/nginx/access.log"]
error:
enabled: true
var.paths: ["/var/log/nginx/error.log"]
sudo filebeat setup
sudo systemctl enable filebeat
sudo systemctl start filebeat
sudo systemctl status filebeat
journalctl -u filebeat -f
Filebeat 需读取日志:
sudo usermod -aG adm filebeat
sudo filebeat test config
sudo filebeat test output
/var/log/filebeat/filebeat
filebeat.inputs:
- type: filestream
paths:
- /var/log/syslog
output.console:
pretty: true
运行测试:
sudo filebeat -e -c /etc/filebeat/filebeat.yml
如果你有 具体场景(如 Docker 日志、Kafka 输出、Elasticsearch 安全认证),可以告诉我,我给你定制配置。