在 Ubuntu 上,Filebeat 的开机自启方式取决于你的 Ubuntu 版本以及 Filebeat 的安装方式。下面分情况说明。
如果你是通过以下方式安装的:
sudo apt install filebeat
# 或
sudo dpkg -i filebeat-*.deb
Ubuntu 16.04+ 默认使用 systemd:
sudo systemctl enable filebeat
sudo systemctl start filebeat
sudo systemctl status filebeat
sudo systemctl stop filebeat
sudo systemctl restart filebeat
✅ 这样设置后,服务器重启会自动启动 Filebeat
如果你是手动解压的:
tar -xzf filebeat-*.tar.gz
sudo vim /etc/systemd/system/filebeat.service
示例内容(路径按实际情况修改):
[Unit]
Description=Filebeat
Documentation=https://www.elastic.co/beats/filebeat
Wants=network-online.target
After=network-online.target
[Service]
User=root
ExecStart=/opt/filebeat/filebeat -c /opt/filebeat/filebeat.yml
Restart=always
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable filebeat
sudo systemctl start filebeat
如果是很老的 Ubuntu:
sudo update-rc.d filebeat defaults
systemctl is-enabled filebeat
结果应为:
enabled
sudo filebeat test config
journalctl -u filebeat -f
✅ 最标准做法(DEB 安装):
sudo systemctl enable filebeat
sudo systemctl start filebeat
如果你愿意,可以告诉我:
lsb_release -a)我可以给你更精确的建议。