温馨提示×

CentOS如何设置Filebeat开机启动

小樊
54
2026-08-03 21:28:39
栏目: 智能运维

CentOS 上设置 Filebeat 开机自启,取决于你使用的是 CentOS 7/8(systemd) 还是 CentOS 6(init.d)。目前主流是 systemd,下面重点说明。


一、CentOS 7 / 8(systemd,推荐)

1. 确认 Filebeat 已安装

filebeat version

如果未安装,可参考:

rpm -ivh filebeat-*.rpm
# 或
yum install filebeat -y

2. 配置 Filebeat(可选但建议)

vim /etc/filebeat/filebeat.yml

确保至少配置 output.elasticsearchoutput.logstash


3. 设置开机自启

sudo systemctl enable filebeat

4. 启动 Filebeat

sudo systemctl start filebeat

5. 查看状态

sudo systemctl status filebeat

正常状态示例:

Active: active (running)

6. 重启 / 停止

sudo systemctl restart filebeat
sudo systemctl stop filebeat

二、CentOS 6(init.d,老系统)

1. 启动脚本(通常已自带)

/etc/init.d/filebeat start

2. 设置开机启动

chkconfig --add filebeat
chkconfig filebeat on

3. 查看状态

service filebeat status

三、常见问题排查

1️⃣ Filebeat 启动失败

查看日志:

journalctl -u filebeat -f

或:

tail -f /var/log/filebeat/filebeat

2️⃣ 配置文件错误

测试配置:

filebeat test config

测试输出:

filebeat test output

3️⃣ systemctl enable 提示找不到 unit

说明 systemd 服务文件缺失,可手动创建:

vim /usr/lib/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

然后执行:

systemctl daemon-reload
systemctl enable filebeat
systemctl start filebeat

四、验证是否开机自启成功

systemctl is-enabled filebeat

返回:

enabled

如果你愿意,我可以帮你:

  • ✅ 检查你的 filebeat.yml
  • ✅ 排查启动失败原因
  • ✅ 配置 Filebeat → Elasticsearch / Logstash

直接把 CentOS 版本 + Filebeat 版本 发我即可。

0