在CentOS系统上,Filebeat的日志文件轮转可以通过配置logrotate工具来实现。以下是配置Filebeat日志轮转的步骤:
确保logrotate已安装: 在CentOS 7和8上,logrotate通常已经预装。如果没有,可以使用以下命令安装:
sudo yum install logrotate
创建或编辑logrotate配置文件:
Filebeat的日志轮转配置文件通常位于/etc/logrotate.d/目录下。你可以创建一个新的配置文件,例如filebeat,或者编辑现有的配置文件(如果有的话)。
使用文本编辑器打开或创建配置文件:
sudo vi /etc/logrotate.d/filebeat
添加以下内容到配置文件中:
/var/log/filebeat/filebeat
{
daily
rotate 7
compress
missingok
notifempty
create 640 root adm
sharedscripts
postrotate
if [ -f '/var/run/filebeat/filebeat.pid' ]; then
/usr/share/filebeat/filebeat -e -c /etc/filebeat/filebeat.yml -d '*'
fi
endscript
}
这里的配置表示:
保存并退出配置文件。
测试logrotate配置是否正确: 使用以下命令测试logrotate配置:
sudo logrotate -f /etc/logrotate.d/filebeat
如果没有错误信息,说明配置正确。
现在,Filebeat的日志文件将根据配置进行轮转。如果你希望logrotate定期自动执行,可以将其添加到cron任务中。