1、背景:
filebeat服务使用tar包的形式进行的安装,所以需要自己添加一个filebeat.service脚本,然后被systemctl管理起来,并实现开机自启动。
2、配置:
进入脚本编写目录:
cd /usr/lib/systemd/system
执行命令:
sudo vim filebeat.service
添加脚本后保存退出:
[Unit]
Description=filebeat
Documentation=/usr/local/filebeat-8.4.1/filebeat -help
After=network-online.target
[Service]
User=senior
Group=senior
ExecStart=/usr/local/filebeat-8.4.1/filebeat -e -c /usr/local/filebeat-8.4.1/filebeat.yml
Restart=always
[Install]
WantedBy=multi-user.target
重新加载一下:
sudo systemctl daemon-reload
3、添加开机自启:
sudo systemctl enable filebeat.service
如图表示添加成功
由于我的filebeat目前是启动状态,所以需要先杀掉它然后再启动,不这么做看不到效果,systemctl也还没接管。如图:
杀掉之后执行:
sudo systemctl start filebeat.service
查看是否成功运行:
sudo systemctl status filebeat.service
如图,成功:
4、常用命令:
# 启动服务
systemctl start filebeat.service
# 重启服务
systemctl restart filebeat.service
# 停止服务
systemctl stop filebeat.service
# 禁止开机启动
systemctl disable filebeat.service
# 启用开机启动
systemctl enable filebeat.service