在 CentOS 上,Filebeat 本身的“鉴权”通常不是指登录鉴权,而是指:
下面按常见场景说明(CentOS 7/8 通用)。
/etc/filebeat/filebeat.yml
output.elasticsearch:
hosts: ["https://es.example.com:9200"]
username: "filebeat_writer"
password: "your_password"
⚠️ 不建议用
elastic超级用户,建议创建专用角色
创建专用用户(在 ES 中):
bin/elasticsearch-users useradd filebeat_writer \
-p password \
-r filebeat_writer
output.elasticsearch:
hosts: ["https://es.example.com:9200"]
api_key: "id:api_key"
生成 API Key:
curl -X POST "https://es:9200/_security/api_key" \
-u elastic:password \
-H "Content-Type: application/json" \
-d '{
"name": "filebeat-key",
"role_descriptors": {
"filebeat_writer": {
"cluster": ["monitor","read_ilm"],
"index": ["write","create_index","index"]
}
}
}'
output.elasticsearch:
hosts: ["https://es.example.com:9200"]
ssl.certificate: "/etc/filebeat/certs/filebeat.crt"
ssl.key: "/etc/filebeat/certs/filebeat.key"
ssl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
output.logstash:
hosts: ["logstash.example.com:5044"]
username: "filebeat"
password: "password"
Logstash 侧需要开启:
input {
beats {
port => 5044
ssl => true
ssl_certificate => "..."
ssl_key => "..."
}
}
output.logstash:
hosts: ["logstash.example.com:5044"]
ssl.certificate: "/etc/filebeat/certs/filebeat.crt"
ssl.key: "/etc/filebeat/certs/filebeat.key"
ssl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
CentOS 上 Filebeat 默认以 root 运行:
ps -ef | grep filebeat
可读取:
/var/log/messages/var/log/secure例如读取 /var/log/audit/audit.log:
usermod -aG adm filebeat
usermod -aG systemd-journal filebeat
或修改日志权限(不推荐直接改):
chmod 644 /var/log/audit/audit.log
output.kafka:
hosts: ["kafka:9092"]
username: "filebeat"
password: "password"
sasl.mechanism: "PLAIN"
✅ 配置文件权限:
chmod 600 /etc/filebeat/filebeat.yml
chown root:root /etc/filebeat/filebeat.yml
✅ 禁用匿名访问 ES
✅ 使用 firewall 限制 5044 / 9200 端口
| 场景 | 推荐方式 |
|---|---|
| ES 鉴权 | API Key |
| Logstash | TLS + 用户名 |
| 安全合规 | TLS + 客户端证书 |
| 系统日志 | root 或 adm 组 |
如果你能告诉我:
我可以给你一份可直接用的配置文件。