Filebeat安裝及使用


https://blog.csdn.net/dwyane__wade/article/details/80169051

LogStash 插件

使用

https://blog.csdn.net/wyqlxy/article/details/52622867

Filebeat簡介

  • Filebeat由兩個主要組成部分組成:prospector(探勘者)和 harvesters(礦車)。這些組件一起工作來讀取文件並將事件數據發送到指定的output。
    • prospector: 負責找到所有需要進行讀取的數據源
    • harvesters:負責讀取單個文件的內容,並將內容發送到output中,負責文件的打開和關閉。

Filebeat工作原理

  • Filebeat可以保持每個文件的狀態,並且頻繁地把文件狀態從注冊表里更新到磁盤。這里所說的文件狀態是用來記錄上一次Harvster讀取文件時讀取到的位置,以保證能把全部的日志數據都讀取出來,然后發送給output。如果在某一時刻,作為output的ElasticSearch或者Logstash變成了不可用,Filebeat將會把最后的文件讀取位置保存下來,直到output重新可用的時候,快速地恢復文件數據的讀取。在Filebaet運行過程中,每個Prospector的狀態信息都會保存在內存里。如果Filebeat出行了重啟,完成重啟之后,會從注冊表文件里恢復重啟之前的狀態信息,讓FIlebeat繼續從之前已知的位置開始進行數據讀取。

Filebeat用途

  • 為什么要用filebeat來收集日志?為什么不直接用logstash收集日志?

因為logstash是jvm跑的,資源消耗比較大,啟動一個logstash就需要消耗500M左右的內存(這就是為什么logstash啟動特別慢的原因),而filebeat只需要10來M內存資源。常用的ELK日志采集方案中,大部分的做法就是將所有節點的日志內容通過filebeat發送到logstash,logstash根據配置文件進行過濾。然后將過濾之后的文件輸送到elasticsearch中,通過kibana去展示。

  • 適用於集群環境下,服務多,且部署在不同機器

Filebeat安裝

啟動

  • ./filebeat -e -c filebeat.yml

    • -c:配置文件位置
    • -path.logs:日志位置
    • -path.data:數據位置
    • -path.home:家位置
    • -e:關閉日志輸出
    • -d 選擇器:啟用對指定選擇器的調試。 對於選擇器,可以指定逗號分隔的組件列表,也可以使用-d“*”為所有組件啟用調試.例如,-d“publish”顯示所有“publish”相關的消息。
  • 后台啟動filebeat

     

    • nohup ./filebeat -e -c filebeat.yml >/dev/null 2>&1 & 將所有標准輸出及標准錯誤輸出到/dev/null空設備,即沒有任何輸出
    • nohup ./filebeat -e -c filebeat.yml > filebeat.log &

     

    停止filebeat:ps -ef |grep filebeat, kill -9 pid

啟動返回:

2018-03-26T14:43:12.218+0800 INFO instance/beat.go:468 Home path: [/usr/local/elk/filebeats/filebeat-6.2.1-linux-x86_64] Config path: [/usr/local/elk/filebeats/filebeat-6.2.1-linux-x86_64] Data path: [/usr/local/elk/filebeats/filebeat-6.2.1-linux-x86_64/data] Logs path: [/usr/local/elk/filebeats/filebeat-6.2.1-linux-x86_64/logs] 2018-03-26T14:43:12.218+0800 INFO instance/beat.go:475 Beat UUID: 0aac391c-e8ef-4437-b5d0-62c147b118ee 2018-03-26T14:43:12.218+0800 INFO instance/beat.go:213 Setup Beat: filebeat; Version: 6.2.3 2018-03-26T14:43:12.218+0800 INFO elasticsearch/client.go:145 Elasticsearch url: http://172.30.1.45:9200 2018-03-26T14:43:12.218+0800 INFO pipeline/module.go:76 Beat name: iZ2ze2lelgjwuyib5l73eaZ 2018-03-26T14:43:12.219+0800 INFO instance/beat.go:301 filebeat start running. 2018-03-26T14:43:12.219+0800 INFO registrar/registrar.go:108 Loading registrar data from /usr/local/elk/filebeats/filebeat-6.2.1-linux-x86_64/data/registry 2018-03-26T14:43:12.219+0800 INFO registrar/registrar.go:119 States Loaded from registrar: 0 2018-03-26T14:43:12.219+0800 INFO crawler/crawler.go:48 Loading Prospectors: 1 2018-03-26T14:43:12.219+0800 INFO crawler/crawler.go:82 Loading and starting Prospectors completed. Enabled prospectors: 0 2018-03-26T14:43:12.219+0800 INFO [monitoring] log/log.go:97 Starting metrics logging every 30s 2018-03-26T14:43:12.219+0800 INFO cfgfile/reload.go:127 Config reloader started 2018-03-26T14:43:12.219+0800 INFO cfgfile/reload.go:219 Loading of config files completed. 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

結合logstash測試

  • 准備日志文件,放置filebeat監聽日志目錄下:
mkdir -p /usr/local/elk/filebeats/log 上傳日志文件xxx.log
  • 1
  • 2
  • 3
  • 新建logstash_filebeat.conf,內容如下:
input { beats { port => 5044 } } output { stdout { codec => rubydebug } }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 啟動logstash:logstash -f logstash_filebeat.conf

  • 修改filebeat.yml

filebeat:
  prospectors:
  -
      paths:
        - /usr/local/elk/log/*.log fields: service: project_name output: #elasticsearch: # hosts: ["localhost:9200"] logstash: hosts: ["172.30.1.45:5044"]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • bin目錄下啟動filebeat:./filebeat -e -c filebeat.yml -d “publish”

  • 現象:logstash控制台輸出日志。

filebeat輸出到elasticsearch,通過kibana展示

  • 准備logstash配置文件,內容如下:
input {
  beats {
    port => 5044 } } filter{ if [fields][service] == "project_name" { multiline { pattern => "^20" negate => true what => "previous" } grok { match => { "message" => "\s*%{TIMESTAMP_ISO8601:log_print_time} \s*%{LOGLEVEL:log_level} \s*\[%{DATA:thread_number}\] \s*%{LOGLEVEL:log_level1} \s*%{DATA:method}\-\> \s*(?<info>([\s\S]*))"} } date { match => ["log_print_time", "yyyy-MM-dd HH:mm:ss,SSS"] target => "@timestamp" } mutate { remove_field => ["log_print_time"] } } } output { if[fields][service] == "project_name" { elasticsearch { hosts => ["172.30.1.45:9200"] index => "project_name-%{+YYYY.MM.dd}" } } stdout { codec=> rubydebug } }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

Filebeat配置多個探索者(prospectors)

filebeat:
  prospectors:
  -
      paths:
        - /usr/local/elk/redislog/*.log # 相當於logstash中的type fields: service: redis - paths: - /usr/local/elk/log/*.log fields: service: ecps output: #elasticsearch: # hosts: ["localhost:9200"] logstash: hosts: ["172.30.1.45:5044"]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

參考博客:https://blog.csdn.net/fenglailea/article/details/52486471


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM