1. 程式人生 > >ELK、Filebeat環境搭建

ELK、Filebeat環境搭建

簡介

ELK為Elasticsearch、Logstash、Kibana簡稱,Filebeat為日誌傳輸工具

  1. Elasticsearch
    The Heart of the Elastic Stack,Elasticsearch是一個基於分散式RESTful風格的搜尋和分析引擎,能夠解決越來越多的用例,作為Elastic Stack的核心,它集中儲存資料,以便預期發現意外情況
  2. Logstash
    Logstash是一個開源的伺服器端資料處理管道,它可以同時從多個源中提取資料,對其進行轉換,然後將其傳送到您最喜歡的"儲存"
  3. Kibana
    Your Window into
    the Elastic Stack,Kibana用來視覺化Elasticsearch資料
  4. Filebeat
    輕量級的日誌、檔案傳輸工具,filebeat會使用一個反壓力敏感(backpressure-sensitive)的協議來解釋高負荷的資料量,當資料處理繁忙時,Filebeat放慢它的讀取速度.一旦壓力解除,將恢復到原來的速度,繼續傳輸資料
    簡單的來說,Filebeat用來檢測資料,把資料傳送給Logstash,Logstash是具備實時傳輸資料的管道,將資料從管道的輸入端傳輸到輸出端,而且可以根據需要過濾、處理資料,Elasticsearch 是一個分散式搜尋引擎,負責資料的儲存、檢索、分析,Kibana提供了視覺化的介面,用於資料的視覺化操作.

安裝

  1. 配置Elasticsearch
    修改檔案/elasticsearch-6.3.2/config/elasticsearch.yml:

    cluster.name: lios-boot-rest
    node.name: lios-boot
    path.data: /Users/wenchao.wang/dev/elk/logs
    path.logs: /Users/wenchao.wang/dev/elk/logs
    network.host: 127.0.0.1
    http.port: 9200
    

    啟動服務:

    ./elasticsearch-6.3.2/bin/elasticsearch
    
  2. 配置Logstash
    在/logstash-6.3.2/config目錄下新建配置檔案filebeat-to-es.conf:

    input {
    beats{
       type => "lios-boot-rest"
       host => "127.0.0.1"
       port => 5044
     }
    }
    output {
    elasticsearch{
    hosts => ["127.0.0.1:9200"]
    index => "lios-boot-rest-%{+YYYY.MM.dd}"
    }
    }
    

    啟動服務:

    ./logstash-6.3.2/bin/logstash -f ./filebeat-to-es.conf 
    
  3. 配置kibana

    server.port: 5601
    server.host: "127.0.0.1"
    elasticsearch.url: "http://127.0.0.1:9200"
    kibana.index: ".kibana"
    

    啟動服務:

    ./kibana-6.3.2-darwin-x86_64/bin kibana
    
  4. 配置filebeat

    filebeat.inputs:
    - type: log
      # Change to true to enable this input configuration.
      enabled: true
      # Paths that should be crawled and fetched. Glob based paths.
      paths:
      - /data/lios/logs/apps/lios-boot-rest/*.log
      tags: ["lios-boor-rest-log"]
      document_type: lios-boot-rest
      spool_size: 1024
      idle_timeout: "3s"
    filebeat.config.modules:
      path: ${path.config}/modules.d/*.yml
      reload.enabled: false
      # Period on which files under path should be checked for changes
      #reload.period: 10s
    setup.template.settings:
      index.number_of_shards: 3
    #----------------------------- Logstash output --------------------------------
    output.logstash:
      # The Logstash hosts
      hosts: ["127.0.0.1:5044"]
    

    啟動filebeat服務

     mac上啟動方式
     sudo chown root filebeat.yml
     sudo ./filebeat -e -c filebeat.yml -d "publish"
    

    發現filebeat已經向logstash傳送資料了:
    https://note.youdao.com/yws/api/personal/file/WEB9d0e71c88ccb436a312e6747ac1c2e46?method=download&shareKey=47897f4682f9c75b134a928ad976766f

視覺化

網址中輸入http://localhost:5601/
https://note.youdao.com/yws/api/personal/file/WEB67fc37afa7f12be50de95ae2d447afcb?method=download&shareKey=c0db3c5afcfaf14869ee68a7eb2f7b17
建立索引:
https://note.youdao.com/yws/api/personal/file/WEB4e269f40a4710edd267c3bddb0874a14?method=download&shareKey=7c241b06a656228479904e8e7cabea63
建立索引成功後,發現已經可以看到資料了:
https://note.youdao.com/yws/api/personal/file/WEBf032714873aecd77a05398651e621b24?method=download&shareKey=b508852230494de3f0943d32ed10b4e8