在CentOS上使用Filebeat分析日志,可按以下步驟操作:
sudo yum install filebeat -y
安裝。/etc/filebeat/filebeat.yml
文件,指定要監控的日志文件路徑,如filebeat.inputs: - type: log enabled: true paths: - /var/log/*.log
,還可設置輸出目標為Elasticsearch,如output.elasticsearch: hosts: - "localhost:9200"
,并根據需要添加處理器,如processors: - dissect: tokenizer: "%{timestamp} %{level} %{message}" field: "message"
來解析日志。sudo systemctl start filebeat
啟動服務,并通過sudo systemctl enable filebeat
設置開機自啟。sudo systemctl status filebeat
檢查服務狀態,確保其正常運行。