在 CentOS 上让 Filebeat 在后台运行,常见有几种方式,按推荐程度从高到低说明:
如果 Filebeat 是通过官方 RPM 安装的,一般已经自带 systemd 服务。
systemctl start filebeat
systemctl enable filebeat
systemctl status filebeat
journalctl -u filebeat -f
✅ 优点:稳定、可管理、重启自动运行
✅ 生产环境首选
如果你只是临时测试:
nohup /usr/share/filebeat/bin/filebeat -c /etc/filebeat/filebeat.yml > /var/log/filebeat.out 2>&1 &
ps -ef | grep filebeat
kill -9 <pid>
⚠️ 不推荐生产环境长期使用
yum install -y screen
screen -S filebeat
/usr/share/filebeat/bin/filebeat -c /etc/filebeat/filebeat.yml
Ctrl + A + D 退出但保持运行screen -r filebeat 重新进入如果没自动生成服务文件:
vim /etc/systemd/system/filebeat.service
内容示例:
[Unit]
Description=Filebeat
After=network.target
[Service]
ExecStart=/usr/share/filebeat/bin/filebeat -c /etc/filebeat/filebeat.yml
Restart=always
User=root
[Install]
WantedBy=multi-user.target
然后执行:
systemctl daemon-reload
systemctl start filebeat
systemctl enable filebeat
| 场景 | 推荐方式 |
|---|---|
| 生产环境 | ✅ systemd |
| 临时测试 | nohup / screen |
| 自定义安装 | 手动 systemd |
如果你愿意,可以告诉我:
我可以给你更精确的操作命令。