在同一台主機上事先安裝好filebeat,elasticsearch和kibana
filebeat配置
安裝完Filebeat后,可以看到在Filebeat的安裝目錄下有一個叫做filebeat.yml的配置文件,還有一個叫做modules.d的文件夾。在filebeat.yml中,我們做如下的修改:
setup.kibana:
host: "localhost:5601"
output.elasticsearch:
hosts: ["localhost:9200"]
注意:filebeat.yml文件中的其他配置不需要修改
拓展:
顯示Filebeat支持的模塊:./filebeat modules list
啟動某一個模塊:./filebeat modules enable 模塊名
關閉某一個模塊:./filebeat modules disenable 模塊名
啟動nginx模塊:./filebeat modules enable nginx
查看在modules.d目錄下的文件變化,可以看到nginx.yml文件的最后沒有“disabled”字樣,表明它已經被啟動成功。我們進一步編輯這個nginx.yml文件:
# Module: nginx
# Docs: https://www.elastic.co/guide/en/beats/filebeat/7.3/filebeat-module-nginx.html
- module: nginx
# Access logs
access:
enabled: true
# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
var.paths: ["/usr/local/src/nginx_log_file/nginx.log"] # 根據nginx日志所在路徑實際修改
# Error logs
error:
enabled: true
# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths: ["/var/log/nginx/error.log"]
為了能夠使得我們的nginx模塊能夠正確地被Kibana顯示,我們必須運行如下的命令:
[root@bogon filebeat-7.5.0-linux-x86_64]# ./filebeat setup
Index setup finished.
Loading dashboards (Kibana must be running and reachable)
Loaded dashboards
Loaded machine learning job configurations
Loaded Ingest pipelines
注意:在安裝或升級Filebeat時,或在啟用新模塊后,必須執行setup命令
運行:./filebeat -e
已經通過./filebeat setup
命令,把針對nginx的模塊儀表盤導入到Kibana中了。就可以使用標准的dashboard來對nginx數據進行展示及分析。
這里的filebeat-7.5.0是一個alias,它指向我們剛被創建的一個index,比如filebeat-7.5.0-2020.05.08-000001。
在這里顯示的數據是10,000,其實這不是一個真實的文檔的數目。
這里要注意的一件事是響應中的hits.total。 它具有10,000和“ relation” =“ gte”的值。 索引中實際上有984,887個文檔,我們已經創建了全部。 在7.0版發布之前,hits.total始終用於表示符合查詢條件的文檔的實際數量。 在Elasticsearch 7.0版中,如果匹配數大於10,000,則不會計算hits.total。 這是為了避免為給定查詢計算精確匹配文檔的不必要開銷。 我們可以通過將track_total_hits = true作為請求參數來強制進行精確匹配的計算。