使用systemctl启动filebeat

我安装 Filebeat 时用的是压缩包解压后直接配置的方式。启动时需要执行后台运行命令。例如:

1
2
cd /opt/filebeat-8.4.1-linux-x86_64
nohup ./filebeat -e -c /opt/filebeat-8.4.1-linux-x86_64/filebeat.yml > logs/filebeat-2022100102.log 2>&1 &

重启时需要使用 kill -9 <filebeat PID> 的方式。

为了方便,改成自定义Service方式启动 ,即使用 systemctl 来启动 filebeat 。

1
2
3
4
5
6
vim /usr/lib/systemd/system/filebeat.service
chmod +x /usr/lib/systemd/system/filebeat.service

systemctl daemon-reload
systemctl start filebeat
systemctl enable filebeat

filebeat.service 文件内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=filebeat server daemon
Documentation=/opt/filebeat-8.4.1-linux-x86_64/filebeat --help
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Environment="CONFIG_OPTS=-c /opt/filebeat-8.4.1-linux-x86_64/filebeat.yml"
ExecStart=/opt/filebeat-8.4.1-linux-x86_64/filebeat $CONFIG_OPTS
Restart=always

[Install]
WantedBy=multi-user.target

service 文件配置详情,查看 man systemd.unit;

  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2022-2023 ligongzhao
  • 访问人数: | 浏览次数:

请我喝杯咖啡吧~

支付宝
微信