在 Debian 上设置 Filebeat 开机自启动,通常取决于你使用的 init 系统(现在大多是 systemd)。下面以 systemd(Debian 8+,常见) 为例说明。
which filebeat
filebeat version
sudo systemctl enable filebeat
sudo systemctl start filebeat
sudo systemctl status filebeat
看到 active (running) 且 enabled 即成功。
systemd 服务文件通常在:
/lib/systemd/system/filebeat.service
如果不存在,可手动创建(一般不推荐,除非你自定义安装):
[Unit]
Description=Filebeat sends log files to Logstash or 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 apt install filebeat
安装的话,默认已经注册 systemd 服务,只需要:
sudo systemctl enable --now filebeat
sudo update-rc.d filebeat defaults
sudo service filebeat start
查看日志:
journalctl -u filebeat -f
先测试配置:
sudo filebeat test config
确保 /var/lib/filebeat 属主正确:
sudo chown -R root:root /var/lib/filebeat
如果你能告诉我:
cat /etc/debian_version)我可以给你更精确的步骤。