在 Debian 系统上设置 Filebeat 开机自启,通常有两种方式(取决于系统是否使用 systemd)。目前 Debian 8 及以上版本默认使用 systemd,下面以 systemd 为主说明。
filebeat version
如果未安装,可参考:
sudo apt update
sudo apt install filebeat
或官方方式安装(APT / DEB)。
sudo systemctl enable filebeat
输出类似:
Created symlink /etc/systemd/system/multi-user.target.wants/filebeat.service → /lib/systemd/system/filebeat.service.
sudo systemctl start filebeat
sudo systemctl status filebeat
正常状态应显示:
Active: active (running)
sudo systemctl restart filebeat
sudo systemctl stop filebeat
sudo systemctl disable filebeat
如果 systemctl enable 失败,先检查服务文件:
ls /lib/systemd/system/filebeat.service
若不存在,可手动创建 /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 -path.home /usr/share/filebeat -path.config /etc/filebeat -path.data /var/lib/filebeat -path.logs /var/log/filebeat
Restart=always
[Install]
WantedBy=multi-user.target
然后执行:
sudo systemctl daemon-reload
sudo systemctl enable filebeat
sudo systemctl start filebeat
sudo update-rc.d filebeat defaults
sudo service filebeat start
重启系统后检查:
sudo reboot
sudo systemctl status filebeat
查看日志:
sudo journalctl -u filebeat -xe
sudo filebeat test config
sudo filebeat test output
如果你愿意,可以告诉我:
cat /etc/debian_version)我可以给你更精确的配置方案。