EFK之filebeat線上使用方法個人線上應用及參考地址--我帶你入門到成F神

Filebeat是一個輕量級的託運人,用於轉發和集中日誌數據。Filebeat作爲代理安裝在服務器上,監視您指定的日誌文件或位置,收集日誌事件,並將它們轉發到Elasticsearch或 Logstash進行索引。

以下是Filebeat的工作原理:啓動Filebeat時,它會啓動一個或多個輸入,這些輸入將查找您爲日誌數據指定的位置。對於Filebeat找到的每個日誌,Filebeat啓動一個收集器。每個收集器爲新內容讀取單個日誌,並將新日誌數據發送到libbeat,libbeat聚合事件並將聚合數據發送到您爲Filebeat配置的輸出。
EFK之filebeat線上使用方法個人線上應用及參考地址--我帶你入門到成F神

Filebeat是一個Beat,它基於libbeat框架。

Step 1: Install Filebeat

要下載並安裝Filebeat,請使用適用於您的系統的命令:
DEB:

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.5.4-amd64.deb
sudo dpkg -i filebeat-6.5.4-amd64.deb~~

轉:

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.5.4-x86_64.rpm
sudo rpm -vi filebeat-6.5.4-x86_64.rpm

蘋果電腦:

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.5.4-darwin-x86_64.tar.gz
tar xzvf filebeat-6.5.4-darwin-x86_64.tar.gz

Linux的:

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.5.4-linux-x86_64.tar.gz
tar xzvf filebeat-6.5.4-linux-x86_64.tar.gz

第二步、配置Filebeat
要配置Filebeat,請編輯配置文件。調用默認配置文件 filebeat.yml。文件的位置因平臺而異。
還有一個名爲的完整示例配置文件filebeat.reference.yml ,顯示了所有未棄用的選項
(注意主配置文件filebeat.yml可以不唯一,啓動時可以制定自己寫的yml)
以下是filebeat該filebeat.yml文件部分的示例。Filebeat使用大多數配置選項的預定義默認值。

filebeat.inputs:
-  type:log 
  enabled:true 
  paths:
    - 
    / var / log / * 。log # -  c:\ programdata \ elasticsearch \ logs \ *

配置Filebeat:

定義日誌文件的路徑(或路徑)。

對於最基本的Filebeat配置,您可以使用單個路徑定義單個輸入。例如:

filebeat.inputs:
-  type:log 
  enabled:true 
  paths:
    -  /var/log/*.log

此示例中的輸入收集路徑中的所有文件/var/log/*.log,這意味着Filebeat將收集目錄/var/log/結尾的所有文件.log。

要從預定義級別的子目錄中獲取所有文件,可以使用以下模式: /var/log//.log。這.log將從子文件夾中獲取所有文件/var/log。它不從/var/log文件夾本身獲取日誌文件。目前,無法以遞歸方式獲取目錄的所有子目錄中的所有文件。
配置輸出。Filebeat支持各種 輸出,但通常您可以將事件直接發送到Elasticsearch,也可以發送到Logstash以進行其他處理。

要將輸出直接發送到Elasticsearch(不使用Logstash),請設置Elasticsearch安裝的位置:

  • 如果您 在Elastic Cloud上運行我們 託管的Elasticsearch Service,請指定您的Cloud ID。例如:

cloud.id:“staging:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyRjZWM2ZjI2MWE3NGJmMjRjZTMzYmI4ODExYjg0Mjk0ZiRjNmMyY2E2ZDA0MjI0OWFmMGNjN2Q3YTllOTYyNTc0Mw ==”

  • 如果您在自己的硬件上運行Elasticsearch,請設置Filebeat可以找到Elasticsearch安裝的主機和端口。例如:
output.elasticsearch:
  hosts:[“myEShost:9200”]

如果您計劃使用隨Filebeat提供的示例Kibana儀表板,請配置Kibana端點。如果Kibana與Elasticsearch在同一主機上運行,​​則可以跳過此步驟。

setup.kibana:
  host:“mykibanahost:5601”

例如,運行Kibana的計算機的主機名和端口mykibanahost:5601。如果在端口號後面指定路徑,請包括方案和端口:http://mykibanahost:5601/path

如果要使用Logstash對Filebeat收集的數據執行其他處理,則需要配置Filebeat以使用Logstash。
第三步
要執行此操作,請編輯Filebeat配置文件以通過註釋掉它來禁用Elasticsearch輸出,並通過取消註釋logstash部分來啓用Logstash輸出:

#----------------------------- Logstash輸出------------------ --------------

output.logstash:
  hosts: ["127.0.0.1:5044"]

該hosts選項指定Logstash服務器和port(5044),其中Logstash配置爲偵聽傳入的Beats連接。

對於此配置,您必須手動將索引模板加載到Elasticsearch中, 因爲自動加載模板的選項僅適用於Elasticsearch輸出。

第四步 在elasticsearch中加載索引模板

在Elasticsearch中,索引模板用於定義確定如何分析字段的設置和映射。

Filebeat的推薦索引模板文件由Filebeat包安裝。如果接受filebeat.yml配置文件中的默認配置,則 Filebeat會在成功連接到Elasticsearch後自動加載模板。如果模板已存在,則除非您配置Filebeat,否則不會覆蓋該模板。

配置模板加載編輯
默認情況下,fields.yml如果啓用了Elasticsearch輸出,Filebeat會自動加載推薦的模板文件 。如果要使用默認索引模板,則不需要其他配置。否則,您可以將filebeat.yml配置文件中的默認值更改爲:

  • 加載不同的模板
setup.template.name:“your_template_name”
setup.template.fields:“path / to / fields.yml”

如果模板已存在,則除非您配置Filebeat,否則不會覆蓋該模板。

  • 覆蓋現有模板

setup.template.overwrite:true

* 禁用自動模板加載

setup.template.enabled:false


*  更改索引名稱

默認情況下,Filebeat將事件寫入命名的索引 filebeat-6.5.4-yyyy.MM.dd,其中yyyy.MM.dd是事件索引的日期。要使用其他名稱,請index在Elasticsearch輸出中設置該 選項。您指定的值應包括索引的根名稱以及版本和日期信息。您還需要配置setup.template.name和 setup.template.pattern選項以匹配新名稱。例如:

output.elasticsearch.index:“customname - %{[beat.version]} - %{+ yyyy.MM.dd}”
setup.template.name:“customname”
setup.template.pattern:“customname- *”

如果您使用的是預先構建的Kibana儀表板,請同時設置該 setup.dashboards.index選項。例如:

`setup.dashboards.index:“customname- *”``



**手動加載模板編輯**
要手動加載模板,請運行該setup命令。需要連接到Elasticsearch。如果啓用了另一個輸出,則需要暫時​​禁用該輸出並使用該-E選項啓用Elasticsearch 。此處的示例假定已啓用Logstash輸出。-E如果已啓用Elasticsearch輸出,則可以省略標誌。

如果要連接到安全的Elasticsearch集羣,請確保已按照步驟2:配置Filebeat中所述配置憑據。

如果運行Filebeat的主機沒有與Elasticsearch的直接連接,請參閱手動加載模板(備用方法)。

要加載模板,請使用適用於您系統的命令。

deb和rpm:

> filebeat setup --template -E output.logstash.enabled = false -E'output.elasticsearch.hosts = [“localhost:9200”]'

蘋果電腦:

> ./filebeat setup --template -E output.logstash.enabled = false -E'output.elasticsearch.hosts = [“localhost:9200”]'

Linux的:

./filebeat setup --template -E output.logstash.enabled = false -E'output.elasticsearch.hosts = [“localhost:9200”]'
docker:

> docker run docker.elastic.co/beats/filebeat:6.5.4 setup --template -E output.logstash.enabled = false -E'output.elasticsearch.hosts = [“localhost:9200”]'

win:

以管理員身份打開PowerShell提示符(右鍵單擊PowerShell圖標,然後選擇“以管理員身份運行”)。

在PowerShell提示符下,切換到Filebeat的安裝目錄,然後運行:

> PS>。\ filebeat.exe setup --template -E output.logstash.enabled = false -E'output.elasticsearch.hosts = [“localhost:9200”]'

強制Kibana查看最新的文檔編輯
如果您已經使用Filebeat將數據索引到Elasticsearch,則索引可能包含舊文檔。加載索引模板後,您可以刪除舊文檔filebeat-*以強制Kibana查看最新文檔。

使用此命令:

deb和rpm:

> curl -XDELETE'http:// localhost:9200 / filebeat- *'

蘋果電腦:

> curl -XDELETE'http:// localhost:9200 / filebeat- *'

Linux的:

> curl -XDELETE'http:// localhost:9200 / filebeat- *'

win:

> PS> Invoke-RestMethod -Method刪除“http:// localhost:9200 / filebeat- *”

此命令刪除與模式匹配的所有索引filebeat-*。在運行此命令之前,請確保要刪除與該模式匹配的所有索引。

手動加載模板(備用方法)編輯
If the host running Filebeat does not have direct connectivity to Elasticsearch, you can export the index template to a file, move it to a machine that does have connectivity, and then install the template manually.

To export the index template, run:

deb and rpm:

> filebeat export template > filebeat.template.json

mac:

> ./filebeat export template > filebeat.template.json

linux:

> ./filebeat export template > filebeat.template.json

win:

> PS > .\filebeat.exe export template --es.version 6.5.4 | Out-File -Encoding UTF8 filebeat.template.json
> To install the template, run:

deb and rpm:

> curl -XPUT -H 'Content-Type: application/json' http://localhost:9200/_template/filebeat-6.5.4 [email protected]

mac:

> curl -XPUT -H 'Content-Type: application/json' http://localhost:9200/_template/filebeat-6.5.4 [email protected]

linux:

> curl -XPUT -H 'Content-Type: application/json' http://localhost:9200/_template/filebeat-6.5.4 [email protected]

win:

> PS > Invoke-RestMethod -Method Put -ContentType "application/json" -InFile filebeat.template.json -Uri http://localhost:9200/_template/filebeat-6.5.4

好了今天入門就到這裏了,改天整理文檔的時候繼續。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章