温馨提示×

CentOS Filebeat怎么设置开机自启

小樊
34
2026-07-20 08:13:01
栏目: 智能运维

CentOS 上设置 Filebeat 开机自启,取决于你的 CentOS 版本(6 还是 7/8/9)。下面分别说明,最常用的是 CentOS 7+(systemd)


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

1. 确认 Filebeat 已安装

filebeat version

如果没有安装,可先安装:

rpm -ivh filebeat-*.rpm
# 或使用 yum / dnf
yum install filebeat -y

2. 设置开机自启

sudo systemctl enable filebeat

3. 启动 Filebeat

sudo systemctl start filebeat

4. 查看状态

sudo systemctl status filebeat

正常状态示例:

Active: active (running)

5. 常用 systemctl 命令

# 停止
systemctl stop filebeat

# 重启
systemctl restart filebeat

# 查看是否开机自启
systemctl is-enabled filebeat

二、CentOS 6(使用 chkconfig,已淘汰)

1. 开机自启

chkconfig --add filebeat
chkconfig filebeat on

2. 启动

service filebeat start

三、确认 Filebeat 服务文件(systemd)

CentOS 7+ 安装后一般会自动生成:

ls /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

四、常见问题排查

1. Filebeat 启动失败

查看日志:

journalctl -u filebeat -f

或:

tail -f /var/log/filebeat/filebeat

2. 配置文件错误

filebeat test config
filebeat test output

五、总结(CentOS 7+ 最简步骤)

systemctl enable filebeat
systemctl start filebeat
systemctl status filebeat

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

  • ✅ CentOS 具体版本
  • ✅ Filebeat 安装方式(rpm / tar.gz)
  • ✅ 是否使用 Elasticsearch / Logstash

我可以帮你给出完全适配你环境的配置方案

0