在 Debian 系统上,Filebeat 的开机自启方式取决于你是怎么安装的,常见有以下几种情况。
如果你是执行了类似下面的安装方式:
sudo dpkg -i filebeat-*.deb
# 或
sudo apt install filebeat
那么 Filebeat 已经自动注册为 systemd 服务,只需启用即可。
sudo systemctl enable filebeat
sudo systemctl start filebeat
sudo systemctl status filebeat
✅ 这种方式 重启后会自动启动
如果是下载 filebeat-*.linux-amd64.tar.gz 解压使用,则 默认没有开机自启。
创建服务文件:
sudo vim /etc/systemd/system/filebeat.service
内容示例:
[Unit]
Description=Filebeat
Documentation=https://www.elastic.co/beats/filebeat
After=network.target
[Service]
Type=simple
User=root
ExecStart=/opt/filebeat/filebeat -c /opt/filebeat/filebeat.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
注意路径改成你实际的 filebeat 路径
重载并启用:
sudo systemctl daemon-reload
sudo systemctl enable filebeat
sudo systemctl start filebeat
如果是 非常老的 Debian(无 systemd):
sudo update-rc.d filebeat defaults
并确保有 /etc/init.d/filebeat 启动脚本。
systemctl is-enabled filebeat
输出:
enabled ✅disabled ❌sudo filebeat test config
如果你愿意,可以告诉我:
cat /etc/os-release)我可以给你更精确的操作步骤。