用nohup方式啟動filebeat,運行一段時間后,filebeat會自動停止退出,因為filebeat默認會定期檢測文件是否有新的內容。
解決辦法:將filebeat通過系統后臺的方式長期運行。
1,在進入 /etc/systemd/system目錄,創建一個filebeat.service文件
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 /root/filebeat-7.17.8-linux-x86_64/filebeat.yml"
Environment="PATH_OPTS=-path.home /root/filebeat-7.17.8-linux-x86_64/filebeat -path.config /root/filebeat-7.17.8-linux-x86_64 -path.data //root/filebeat-7.17.8-linux-x86_64/data -path.logs /root/filebeat-7.17.8-linux-x86_64/logs"
ExecStart=/root/filebeat-7.17.8-linux-x86_64 $LOG_OPTS $CONFIG_OPTS $PATH_OPTS
Restart=always
[Install]
WantedBy=multi-user.target
將上面filebeat目錄改成你的filebeat安裝目錄
2,給予可執行的權限
chmod +x /etc/systemd/system/filebeat.service
3,后臺啟動服務
systemctl daemon-reload
systemctl enable filebeat
systemctl start filebeat