通过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



