在 CentOS 上设置 Filebeat 开机自启,取决于你的 CentOS 版本(6 还是 7/8/9)。下面分别说明,最常用的是 CentOS 7+(systemd)。
filebeat version
如果没有安装,可先安装:
rpm -ivh filebeat-*.rpm
# 或使用 yum / dnf
yum install filebeat -y
sudo systemctl enable filebeat
sudo systemctl start filebeat
sudo systemctl status filebeat
正常状态示例:
Active: active (running)
# 停止
systemctl stop filebeat
# 重启
systemctl restart filebeat
# 查看是否开机自启
systemctl is-enabled filebeat
chkconfig --add filebeat
chkconfig filebeat on
service filebeat start
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
查看日志:
journalctl -u filebeat -f
或:
tail -f /var/log/filebeat/filebeat
filebeat test config
filebeat test output
systemctl enable filebeat
systemctl start filebeat
systemctl status filebeat
如果你愿意,可以告诉我:
我可以帮你给出完全适配你环境的配置方案。