ubuntu

filebeat在ubuntu上如何进行日志轮转

小樊
40
2025-10-10 12:52:43
栏目: 智能运维

Filebeat 在 Ubuntu 上的日志轮转可以通过配置 logrotate 工具来实现。以下是配置 Filebeat 日志轮转的步骤:

  1. 确保已经安装了 logrotate。在大多数 Ubuntu 版本中,logrotate 已经预装。如果没有,请运行以下命令安装:
sudo apt-get update
sudo apt-get install logrotate
  1. 创建一个新的 logrotate 配置文件,用于配置 Filebeat 的日志轮转。使用文本编辑器创建一个新文件,例如:
sudo nano /etc/logrotate.d/filebeat
  1. 将以下配置粘贴到新创建的文件中,然后根据需要进行修改:
/path/to/your/filebeat/log/filebeat.log {
    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
}

这里的配置表示:

  1. 保存并关闭文件。

  2. 测试 logrotate 配置是否正确:

sudo logrotate -f /etc/logrotate.d/filebeat

如果没有错误,表示配置正确。

现在,Filebeat 的日志轮转应该已经按照您的配置进行了。如果需要修改轮转策略,只需编辑 /etc/logrotate.d/filebeat 文件即可。

0
看了该问题的人还看了