在 CentOS 上让 Filebeat 开机自启,主要取决于你使用的 CentOS 版本(6 / 7+) 以及 Filebeat 的安装方式(RPM 包 / 二进制)。
如果你是 通过 RPM 包安装 Filebeat(推荐):
# 设置开机自启
systemctl enable filebeat
# 启动 Filebeat
systemctl start filebeat
# 查看状态
systemctl status filebeat
✅ 官方 RPM 包默认已带
filebeat.service
# 设置开机自启
chkconfig filebeat on
# 启动
service filebeat start
# 查看状态
service filebeat status
如果你是 直接解压 tar.gz 使用,需要手动创建服务文件。
vi /etc/systemd/system/filebeat.service
示例内容(按实际路径修改):
[Unit]
Description=Filebeat
Documentation=https://www.elastic.co/beats/filebeat
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/filebeat/filebeat -c /usr/local/filebeat/filebeat.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable filebeat
systemctl start filebeat
systemctl is-enabled filebeat
输出:
enabled ✅disabled ❌rpm -ql filebeat | grep service
journalctl -u filebeat -f
filebeat -c /etc/filebeat/filebeat.yml
如果你愿意,可以告诉我:
我可以给你 完全对应你环境的命令。