在 CentOS 上设置 Filebeat 开机自启,取决于你使用的是 CentOS 7/8(systemd) 还是 CentOS 6(init.d)。目前主流是 systemd,下面重点说明。
filebeat version
如果未安装,可参考:
rpm -ivh filebeat-*.rpm
# 或
yum install filebeat -y
vim /etc/filebeat/filebeat.yml
确保至少配置 output.elasticsearch 或 output.logstash。
sudo systemctl enable filebeat
sudo systemctl start filebeat
sudo systemctl status filebeat
正常状态示例:
Active: active (running)
sudo systemctl restart filebeat
sudo systemctl stop filebeat
/etc/init.d/filebeat start
chkconfig --add filebeat
chkconfig filebeat on
service filebeat status
查看日志:
journalctl -u filebeat -f
或:
tail -f /var/log/filebeat/filebeat
测试配置:
filebeat test config
测试输出:
filebeat test output
说明 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直接把 CentOS 版本 + Filebeat 版本 发我即可。