在 CentOS 上设置 Filebeat 开机自启,取决于你的 CentOS 版本(6/7/8/9),但 最常见的是 CentOS 7/8/9(systemd)。下面分情况说明。
filebeat version
sudo systemctl enable filebeat
sudo systemctl start filebeat
sudo systemctl status filebeat
sudo systemctl restart filebeat
sudo systemctl stop filebeat
✅ 说明
/usr/lib/systemd/system/filebeat.service
systemctl enable 后,系统重启会自动启动 Filebeatsudo chkconfig --add filebeat
sudo chkconfig filebeat on
sudo service filebeat start
systemctl is-enabled filebeat
返回:
enabled ✅disabled ❌sudo reboot
重启后检查:
systemctl status filebeat
查看日志:
journalctl -u filebeat -f
或:
tail -f /var/log/filebeat/filebeat
filebeat test config
filebeat test output
如果 filebeat.service 不存在,可手动创建:
# /etc/systemd/system/filebeat.service
[Unit]
Description=Filebeat sends log files to Logstash or directly to Elasticsearch.
Documentation=https://www.elastic.co/products/beats/filebeat
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/usr/share/filebeat/bin/filebeat -c /etc/filebeat/filebeat.yml
Restart=always
[Install]
WantedBy=multi-user.target
加载并启用:
sudo systemctl daemon-reload
sudo systemctl enable filebeat
sudo systemctl start filebeat
systemctl enable filebeat
systemctl start filebeat
systemctl status filebeat
如果你愿意,可以告诉我:
我可以给你更精确的步骤。