在 Debian 上部署 Filebeat(Elastic 官方轻量级日志采集器)时,有几个关键点和常见坑需要注意。下面按「系统层面 → 安装配置 → 权限与安全 → 运维排查」整理。
cat /etc/os-release
uname -m
日志时间错乱会导致 ES 索引异常:
timedatectl status
# 建议开启 NTP
apt install -y systemd-timesyncd
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | 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" \
> /etc/apt/sources.list.d/elastic-8.x.list
apt update
apt install filebeat
⚠️ 注意:Elastic 8.x 默认开启 安全认证(TLS + 账号)
Debian 下默认用户:
ps -ef | grep filebeat
# 通常是:filebeat
确保 filebeat 用户能读日志:
ls -l /var/log/xxx/
常见解决方案:
usermod -aG adm filebeat
filebeat modules enable system
并确保:
journalctl -u xxx
可读
路径:
/etc/filebeat/filebeat.yml
最小可用示例(Elasticsearch 8):
filebeat.inputs:
- type: filestream
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["https://localhost:9200"]
username: "elastic"
password: "xxxx"
ssl:
certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
chmod 600 /etc/filebeat/filebeat.yml
chown root:filebeat /etc/filebeat/filebeat.yml
⚠️ 内含密码,绝不能 644
filebeat modules enable nginx
filebeat modules enable system
/etc/filebeat/modules.d/nginx.yml
不要直接改 modules 目录里的文件
cp /etc/elasticsearch/certs/http_ca.crt /etc/filebeat/certs/
不要直接用 elastic:
# Kibana / ES 中创建
filebeat_writer
| 问题 | 原因 |
|---|---|
| 无数据 | 文件权限不足 |
| 时间错乱 | 系统时间不同步 |
| 启动失败 | yml 缩进错误 |
| 连不上 ES | TLS / 密码错误 |
| 重复发送 | registry 被清理 |
# 测试配置
filebeat test config
# 测试输出
filebeat test output
# 前台调试
filebeat -e -c /etc/filebeat/filebeat.yml
# 查看状态
systemctl status filebeat
journalctl -u filebeat -f
filestream(新版本默认)paths,避免全盘扫描queue.disk如果你愿意,我可以:
你现在是 测试环境还是生产环境?用的是 ES 7 还是 8?