1. 程式人生 > 實用技巧 >ELK實踐(一):基礎入門 -filebeat安裝

ELK實踐(一):基礎入門 -filebeat安裝

為了讓測試簡單,我們手動模擬日誌的生成:

echo "test - test2" >> /tmp/test1.log
echo "test - test2" >> /tmp/test2.log

生成了2個日誌檔案test1.log、test2.log,各有一行日誌。

新建一個filebeat配置檔案:

cd /usr/local/elk

vim beats/filebeat/filebeat.test.yml

配置內容:

# filebeat.test.yml
filebeat.inputs:
- type: log
  paths:
    - /tmp/test1.log
  tags: ["test1"]
  document_type: test1

- type: log
  paths:
    - /tmp/test2.log
  tags: ["test2"]
  document_type: test2

output.elasticsearch:
  hosts: ["127.0.0.1:9200"]
  index: "test-filebeat"

配置說明:

filebeat.inputs:

type 日誌型別,預設log
input_type 輸入型別,預設log
paths 採集的日誌,可以使用萬用字元。支援多個
tags 自定義標籤,是個陣列。自定義
document_type 自定義欄位,用於Logsatsh區分來源,在Logsatsh裡用變數type表示
一個-表示一個filebeat.prospector,這裡設定了2個。日誌傳送到elasticsearch,索引index 是test-filebeat。