1 概論

filebeat 是一個輕量級的日誌收集工具 (golang編寫的,佔用資源小)

官方文檔: Getting Started With Filebeat

2 下載安裝

artifacts.elastic.co/do

3 使用filebeat 發送日誌到 redis 中

1 解壓縮

tar -zxvf filebeat-6.1.1-linux-x86_64.tar.gz

2 如下如:

我們需要編輯 filebeat.yml

YAML支持 列表,數字, 字元串, 字典表。

字典 以 key: value 對的形式,在 key後面必須有一個空格。

name: John Doe

age: 34

country: Canada

列表以破折號開始,所有的列表成員必須以`- `在縮進的一行

- Red

- Green- Blue

列表和字典構建結構化的配置

filebeat:

prospectors: - type: log paths: - /var/log/*.log multiline:

pattern: ^[

match: after

列表和字典同樣可以使用更簡單的形式, 比較類似JSON 使用{} 表示字典,使用[]表示列表

person: {name: "John Doe", age: 34, country: "Canada"}

colors: ["Red", "Green", "Blue"]

3 構建倉庫(探礦者)

Filebeat 通過定義 「挖礦者」去定位和處理文件。 在配置filebeat的過程中,你需要指定一個列表的探礦者 在 filebeat.yml中的 filebeat.prospectors節點.

如下是一個簡單的配置:

filebeat.prospectors:

- type: log paths: - /var/log/apache/httpd-*.log

- type: log

paths: - /var/log/messages - /var/log/*.log

這個探礦者收集所有的文件 在/var/log/*.log ,意思是 : filebeat 會收集在/var/log

目錄中所有以.log結尾的文件。

4 輸出到redis / kafka / elasticsearch

Configure the output | Filebeat Reference [6.1] | Elastic

如下配置 :

output.redis:

hosts: ["192.168.96.58"]

port: 6383

datatype: list keys: - key: "test_tp_log" when.contains: source: "tp.log" - key: "test_alive_log" when.contains: source: "alive.log" - key: "test_jvm_log" when.contains: source: "jvm.log" db: 0

我們輸出 日誌文件輸出到 192.168.96.58 , redis的埠是 6383 數據類型是lis

4 啟動filebeat

./filebeat -e -c filebeat.yml

推薦閱讀:

相關文章