1,Filebeat簡介
Filebeat是一個使用Go語言實現的輕量型日志采集器。在微服務體系中他與微服務部署在一起收集微服務產生的日志並推送到ELK。
在我們的架構設計中Kafka負責微服務和ELK的分離,Filebeat負責收集微服務的日志並推送到Kafka中,如圖:
2,Filebeat安裝使用步驟
2.1 下載並解壓Filebeat
在以上網址中下載和操作系統匹配的版本
其中CentOS屬紅帽系列選擇RPM,Ubuntu屬Debian系列選擇DEB,其他Linux選擇Linux通用。我用的win10選擇Windows 64-bit,下載並解壓到自定義目錄(比如:C:\Programs\filebeat-6.5.1-windows-x86_64)
2 .2 編輯filebeat.yml配置文件
修改其中的input選項
#=========================== Filebeat inputs =============================
filebeat.inputs:
# Each - is an input. Most options can be set at the input level, so
# you can use different inputs for various configurations.
# Below are the input specific configurations.
- type: log
# Change to true to enable this input configuration.
enabled: true #此處默認為false,切記改為true.否則坑到天黑
# Paths that should be crawled and fetched. Glob based paths.
paths:
#- /var/log/*.log #Linux使用此處配置
- C:\Logs\*.log #Windows使用此配置
修改output選項,添加輸出到kafka的配置
#================================ Outputs =====================================
# Configure what output to use when sending the data collected by the beat.
#-------------------------- Kafka output ------------------------------
output.kafka:
# Array of hosts to connect to.
hosts: ["192.168.8.32:9092"] #hosts是string數組類型,支持多個kafka實力地址(此處不是配置zookeeper地址)
topic: elklog #kafka的topic名稱
2.3 運行命令啟動Filebeat
Linux運行以下命令:
sudo ./filebeat -e -c filebeat.yml
Windows運行以下命令:
filebeat.exe -e -c filebeat.yml
3,測試
在我們配置好的input選項中的目錄下,新建一個test.log文件,並寫入測試字符串保存並關閉。
可以看到Kafka已經有數據了
如果ELK運行正常,Elasticsearch和Kibana中也有數據了。