通过nohub方式启动filebeat,运行一段时间后filebeat自动退出,原因是filebeat默认会定期检测文件是否有新的内容,如果超过一定时间检测的文件没有任务新日志写入,那么filebeat会自动退出,解决办法就是将filebeat通过系统后台的方式长期运行。

1、在linux操作系统 /etc/systemd/system目录下创建一个filebeat.service文件,写入如下内容:

[Unit]
Description=Filebeat is a lightweight shipper for metrics.
Documentation=https://www.elastic.co/products/beats/filebeat
Wants=network-online.target
After=network-online.target

[Service]
Environment="LOG_OPTS=-e"
Environment="CONFIG_OPTS=-c /work/soft/filebeat-7.12.1-linux-x86_64/filebeat.yml"
Environment="PATH_OPTS=-path.home /work/soft/filebeat-7.12.1-linux-x86_64/filebeat -path.config /work/soft/filebeat-7.12.1-linux-x86_64 -path.data /work/soft/filebeat-7.12.1-linux-x86_64/data -path.logs /work/soft/filebeat-7.12.1-linux-x86_64/logs"
ExecStart=/work/soft/filebeat-7.12.1-linux-x86_64/filebeat $LOG_OPTS $CONFIG_OPTS $PATH_OPTS
Restart=always

[Install]
WantedBy=multi-user.target

2、给该文件给予可执行的权限:

chmod +x /etc/systemd/system/filebeat.service

3、系统后台服务方式启动:

# 依次执行下列命令
systemctl daemon-reload
systemctl enable filebeat
systemctl start filebeat

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐