温馨提示×

filebeat在ubuntu上的定时任务设置

小樊
44
2025-09-01 06:14:25
栏目: 智能运维

在Ubuntu上设置Filebeat定时任务,常用的是使用cronsystemd,以下是具体方法:

使用cron设置

  1. 打开终端,输入crontab -e(若需root权限则用sudo crontab -e)。
  2. 在打开的文件中添加定时任务行,例如每天凌晨2点执行Filebeat:
0 2 * * * /usr/share/filebeat/filebeat -e -c /etc/filebeat/filebeat.yml 
  1. 保存并关闭文件。

使用systemd设置

  1. 创建filebeat.timer文件:sudo nano /etc/systemd/system/filebeat.timer
  2. 添加以下内容,这里设置每5分钟运行一次:
[Unit] Description=Run Filebeat every 5 minutes [Timer] OnBootSec=5min OnUnitActiveSec=5min Unit=filebeat.service Persistent=true [Install] WantedBy=timers.target 
  1. 重新加载systemd守护进程:sudo systemctl daemon-reload
  2. 启动定时器:sudo systemctl start filebeat.timer
  3. 若要开机自启,执行:sudo systemctl enable filebeat.timer

0