温馨提示×

ubuntu filebeat如何设置开机自启

小樊
45
2026-10-25 16:20:39
栏目: 智能运维

在 Ubuntu 上,Filebeat 的开机自启方式取决于你的 Ubuntu 版本以及 Filebeat 的安装方式。下面分情况说明。


一、使用官方 DEB 包安装(最常见,推荐)

如果你是通过以下方式安装的:

sudo apt install filebeat
# 或
sudo dpkg -i filebeat-*.deb

1. 设置开机自启(systemd)

Ubuntu 16.04+ 默认使用 systemd:

sudo systemctl enable filebeat

2. 启动 Filebeat

sudo systemctl start filebeat

3. 查看状态

sudo systemctl status filebeat

4. 停止 / 重启

sudo systemctl stop filebeat
sudo systemctl restart filebeat

✅ 这样设置后,服务器重启会自动启动 Filebeat


二、使用 TAR 包(二进制)安装

如果你是手动解压的:

tar -xzf filebeat-*.tar.gz

1. 创建 systemd 服务文件

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

2. 重载并启用

sudo systemctl daemon-reload
sudo systemctl enable filebeat
sudo systemctl start filebeat

三、旧版 Ubuntu(Upstart,≤14.04)

如果是很老的 Ubuntu:

sudo update-rc.d filebeat defaults

四、常见问题排查

1. 开机没启动?

systemctl is-enabled filebeat

结果应为:

enabled

2. 配置文件错误导致启动失败

sudo filebeat test config

3. 查看日志

journalctl -u filebeat -f

五、总结(推荐做法)

✅ 最标准做法(DEB 安装):

sudo systemctl enable filebeat
sudo systemctl start filebeat

如果你愿意,可以告诉我:

  • Ubuntu 版本(lsb_release -a)
  • Filebeat 安装方式(apt / dpkg / tar)

我可以给你更精确的建议。

0 踩