在CentOS上使用Filebeat进行日志审计的步骤如下:
首先,你需要安装Filebeat。你可以从Elastic官方网站下载最新版本的Filebeat,并按照以下步骤进行安装:
# 下载Filebeat
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.15.0-amd64.deb
# 安装Filebeat
sudo dpkg -i filebeat-7.15.0-amd64.deb
# 启动Filebeat服务
sudo systemctl start filebeat
# 设置Filebeat开机自启
sudo systemctl enable filebeat
Filebeat的配置文件通常位于/etc/filebeat/filebeat.yml
。你需要根据你的日志文件路径和审计需求进行配置。
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
fields:
type: audit
processors:
- add_fields:
targets: ["message"]
fields:
audit_level: "INFO"
output.elasticsearch:
hosts: ["localhost:9200"]
index: "audit-%{+yyyy.MM.dd}"
在这个示例中:
filebeat.inputs
定义了Filebeat要监控的日志文件路径。processors
部分添加了一个字段audit_level
,你可以根据需要自定义这个字段。output.elasticsearch
定义了Elasticsearch的输出地址和索引名称。启动Filebeat服务并检查其状态:
sudo systemctl start filebeat
sudo systemctl status filebeat
你可以通过Kibana或者直接访问Elasticsearch来验证日志是否已经发送成功。
http://<your_elasticsearch_host>:5601
)。audit-*
)。你可以使用curl
命令来检查Elasticsearch中是否有数据:
curl -X GET "localhost:9200/audit-*/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"match_all": {}
}
}'
为了确保日志文件不会无限增长,你可以设置日志轮转。CentOS通常使用logrotate
来管理日志文件。
创建一个logrotate
配置文件:
sudo nano /etc/logrotate.d/filebeat
添加以下内容:
/var/log/*.log {
daily
missingok
rotate 7
compress
notifempty
create 640 root root
}
这个配置文件会每天轮转日志文件,并保留最近7天的日志。
你可以定期检查Elasticsearch中的日志数据,以确保审计日志的完整性和准确性。你也可以设置警报,当检测到异常日志时及时通知相关人员。
通过以上步骤,你可以在CentOS上使用Filebeat进行日志审计,并将日志数据发送到Elasticsearch进行进一步的分析和存储。