首先通过Ubuntu官方仓库安装Filebeat,确保版本为最新稳定版(包含安全修复):
sudo apt-get update && sudo apt-get install filebeat
安装完成后,编辑核心配置文件/etc/filebeat/filebeat.yml
,定义日志输入源(如安全相关的系统日志、应用日志)和输出目标(如Elasticsearch、Logstash):
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/auth.log # Ubuntu系统认证日志(关键安全日志)
- /var/log/syslog # 系统通用日志(含安全事件)
- /var/log/secure # 部分Ubuntu版本的SSH登录日志
output.elasticsearch:
hosts: ["localhost:9200"] # 若为远程Elasticsearch,替换为对应地址
保存配置后,启动Filebeat并设置开机自启:
sudo systemctl start filebeat
sudo systemctl enable filebeat
为防止日志在传输过程中被窃取或篡改,需配置Filebeat与Elasticsearch之间的SSL/TLS加密:
sudo mkdir -p /etc/filebeat/certs
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/filebeat/certs/filebeat.key \
-out /etc/filebeat/certs/filebeat.crt
filebeat.yml
的output.elasticsearch
部分添加SSL参数:output.elasticsearch:
hosts: ["localhost:9200"]
protocol: https
ssl.certificate_authorities: ["/etc/filebeat/certs/filebeat.crt"] # CA证书路径
ssl.certificate: "/etc/filebeat/certs/filebeat.crt" # 客户端证书
ssl.key: "/etc/filebeat/certs/filebeat.key" # 客户端私钥
ssl.verify_mode: full # 严格验证证书
sudo systemctl restart filebeat
通过Elasticsearch的X-Pack安全功能,限制Filebeat的访问权限,避免未授权数据写入:
/etc/elasticsearch/elasticsearch.yml
:xpack.security.enabled: true
重启Elasticsearch:sudo systemctl restart elasticsearch
filebeat_user
:curl -X POST "localhost:9200/_security/user/filebeat_user?pretty" -H 'Content-Type: application/json' -d'
{
"password" : "StrongPassword123!",
"roles" : [ "read" ],
"full_name" : "Filebeat Audit User"
}'
filebeat.yml
的output.elasticsearch
部分添加认证信息:output.elasticsearch:
hosts: ["localhost:9200"]
username: "filebeat_user"
password: "StrongPassword123!"
ssl.certificate_authorities: ["/etc/filebeat/certs/filebeat.crt"]
限制Filebeat的运行权限,降低潜在攻击面:
filebeat
)并赋予权限:sudo useradd -r -s /bin/false filebeat
sudo chown -R filebeat:filebeat /etc/filebeat /var/lib/filebeat /var/log/filebeat
sudo chmod 600 /etc/filebeat/filebeat.yml
filebeat.yml
确认):seccomp.enabled: true
seccomp.default_action: allow
seccomp.syscalls.allow:
- rseq
通过监控Filebeat自身状态,及时发现异常:
filebeat.yml
中启用详细日志记录:logging.level: info
logging.to_files: true
logging.files:
path: /var/log/filebeat
name: filebeat
keepfiles: 7
permissions: 0640
sudo systemctl status filebeat
sudo journalctl -u filebeat -f # 实时查看日志
sudo apt-get update && sudo apt-get upgrade filebeat
filebeat.yml
中的输入路径、输出目标、认证信息,确保无敏感信息泄露(如密码明文)。logrotate
防止日志文件过大,避免篡改风险(Filebeat自带日志轮换,可通过logging.files.keepfiles
调整保留天数)。通过以上步骤,可在Ubuntu上利用Filebeat实现安全审计,确保日志数据的保密性、完整性和可用性,同时降低系统安全风险。