上一篇介紹了docker安裝elk,結合filebeat收集日志。docker安裝elk,結合filebeat收集日志
我們不是用rpm安裝的filebeat,所以在啟動的時候比較麻煩。
原來的啟動命令是:nohup ./filebeat -e -c filebeat.yml > filebeat.log &,結束的時候需要kill -9 pid。
現在我們配置使用systemctl來啟動filebeat。
1.進入目錄
cd /usr/lib/systemd/system
2.新建一個文件,用來存儲啟動filebeat的命令
touch filebeat.service
3.編輯該文件,輸入以下內容
vi filebeat.service
[Unit] Description=filebeat server daemon Documentation=/usr/local/elk/filebeat-7.6.0-linux-x86_64/filebeat -help Wants=network-online.target After=network-online.target [Service] User=root Group=root Environment="BEAT_CONFIG_OPTS=-c /usr/local/elk/filebeat-7.6.0-linux-x86_64/filebeat.yml" ExecStart=/usr/local/elk/filebeat-7.6.0-linux-x86_64/filebeat $BEAT_CONFIG_OPTS Restart=always [Install] WantedBy=multi-user.target
filebeat.service文件說明:
/usr/local/elk/filebeat-7.6.0-linux-x86_64是我的filebeat安裝目錄。
User=root,Group=root不配置也可以啟動
4.刷新一下配置文件
systemctl daemon-reload
5.啟動,關閉,查看狀態
# 啟動 systemctl start filebeat # 查看狀態 systemctl status filebeat
也可以使用ps命令來查看狀態
ps -ef | grep filebeat # 關閉
systemctl stop filebeat
配置結束