升級前必須備份Filebeat的配置文件和數據目錄,這是避免數據丟失的核心步驟。
/etc/filebeat/filebeat.yml
,使用以下命令備份:sudo cp /etc/filebeat/filebeat.yml /etc/filebeat/filebeat.yml.bak
/var/lib/filebeat/
,備份該目錄可防止升級后數據重新采集:sudo cp -r /var/lib/filebeat /var/lib/filebeat.bak
確保系統能獲取到最新的Filebeat版本,運行以下命令更新軟件包列表:
sudo apt update
sudo apt install filebeat
執行后會自動檢測并安裝可用的最新版本,過程中會提示確認,輸入Y
繼續。apt-cache policy filebeat
選擇目標版本(如7.17.0-1ubuntu1
),然后執行:sudo apt install filebeat=7.17.0-1ubuntu1
filebeat version
sudo systemctl status filebeat
若狀態顯示為active (running)
,則說明升級成功。若升級后配置文件有變動(如新增模塊、調整輸出),可將備份的配置文件覆蓋回原位置:
sudo cp /etc/filebeat/filebeat.yml.bak /etc/filebeat/filebeat.yml
然后重啟服務使配置生效:
sudo systemctl restart filebeat
/var/lib/filebeat/
中的舊數據(如未發送完的日志),無需手動恢復。journalctl -u filebeat -f
實時查看日志,確保無報錯信息。通過以上步驟,可在Ubuntu上安全升級Filebeat,同時保證已采集的日志數據不會丟失。