在CentOS系统中配置Filebeat日志轮转,可以通过修改Filebeat的配置文件以及系统的logrotate配置来实现。以下是详细的步骤:
打开Filebeat配置文件:
sudo vi /etc/filebeat/filebeat.yml
找到并修改logging.level
和logging.to_files
:
logging:
level: info
to_files: true
files:
name: /var/log/filebeat/filebeat
keepfiles: 7
这里设置了日志级别为info
,并且启用了文件日志模式,日志文件保存在/var/log/filebeat/filebeat
,保留最近7天的日志文件。
保存并退出:
:wq
创建或编辑logrotate配置文件:
sudo vi /etc/logrotate.d/filebeat
添加以下内容:
/var/log/filebeat/*.log {
daily
missingok
rotate 7
compress
notifempty
create 0640 root root
}
这里设置了每天轮转一次日志文件,保留最近7天的日志文件,并且压缩旧日志文件。create 0640 root root
设置了新日志文件的权限和所有者。
保存并退出:
:wq
无论你使用哪种方法,最后都需要重启Filebeat服务以使配置生效:
sudo systemctl restart filebeat
你可以通过查看日志文件来验证配置是否生效:
tail -f /var/log/filebeat/filebeat
或者查看logrotate的日志文件:
sudo tail -f /var/log/logrotate.log
通过以上步骤,你应该能够成功配置CentOS系统中Filebeat的日志轮转。