Appearance
filebeat
创建服务
通过systemd 创建 Filebeat 服务文件,通常位于 /etc/systemd/system/filebeat.service。服务可以自动启动并在系统启动时运行。当
bash
[Unit]
Description=Filebeat sends log files to Elasticsearch # 服务描述
Wants=network-online.target # 确保网络在线
After=network-online.target # 确保网络在线后再启动服务
[Service]
Type=simple # 服务类型,simple表示服务启动后立即返回
User=root # 运行服务的用户
Group=root # 运行服务的用户组
ExecStart=/root/lib/filebeat8/filebeat -c /root/lib/filebeat8/filebeat.yml # 启动服务的命令
Restart=always # 如果服务崩溃,自动重启
RestartSec=10 # 重启间隔时间
WorkingDirectory=/root/lib/filebeat8 # 工作目录
[Install]
WantedBy=multi-user.target # 服务目标,multi-user.target表示多用户模式配置完成后,使用以下命令启用并启动服务:
bash
systemctl enable filebeat # 开机自启
systemctl daemon-reload # 重新加载服务配置
systemctl start filebeat # 启动服务
systemctl status filebeat # 查看服务状态
systemctl stop filebeat # 停止服务
systemctl restart filebeat # 重启服务
systemctl disable filebeat # 禁用开机自启