相關組件
- Elastic search 服務用于分詞并索引日志數(shù)據(jù)
- Logstash / filebeat 服務用于從主機上收集日志文件內容并發(fā)送到 Elastic search 服務索引存儲
- Kibana 服務通過 Elastic search 服務提供的 rest api 查詢和可視化展示日志
服務搭建
通過 docker 部署,創(chuàng)建一個部署腳本 elk.sh 內容如下,直接運行腳本即可完成部署,部署完成后通過瀏覽器訪問兩 Kibana 管理入口:http://localhost:9200 和 Elastic Search 服務入口 http://localhost:5601 驗證是否正確部署完成,服務搭建完成后,Elastic search 中沒有任何日志數(shù)據(jù),需要通過在其他主機上配置 filebeat 將某個應用的數(shù)據(jù)發(fā)送到服務器中。
docker stop elk
docker rm -f elk
docker run -d \
--restart always \
--name elk \
-p 9200:9200 \
-p 5601:5601 \
nshou/elasticsearch-kibana
Windows 10 filebeat 服務安裝配置
下載開源版本 https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-oss-7.6.1-windows-x86_64.zip,解壓縮到 C 盤根目錄下, 如下圖修改配置文件,在 c:\logs 目錄下創(chuàng)建一個錯誤日志文件 error.log 并添加日志內容,通過管理員權限打開 powershell,拖放文件 install-service-filebeat.ps1 運行服務。
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:
- C:\Program Files (x86)\CMOS-UE\logs\*.log
#- c:\programdata\elasticsearch\logs\*
#============================= Filebeat modules ===============================
filebeat.config.modules:
# Glob pattern for configuration loading
path: ${path.config}/modules.d/*.yml
# Set to true to enable config reloading
reload.enabled: false
# Period on which files under path should be checked for changes
#reload.period: 10s
#==================== Elasticsearch template setting ==========================
setup.template.settings:
index.number_of_shards: 1
#index.codec: best_compression
#_source.enabled: false
#-------------------------- Elasticsearch output ------------------------------
output.elasticsearch:
# Array of hosts to connect to.
hosts: ["10.0.23.198:9200"]
# Protocol - either `http` (default) or `https`.
# protocol: "https"
Ubuntu 18.04 filebeat 服務安裝配置
從官方地址 https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-oss-7.6.1-amd64.deb 下載對應的版本安裝完成后,修改配置文件 /etc/filebeat/filebeat.yml,完成后重啟服務.
# 安裝服務,停止和啟動服務,查看服務狀態(tài)
dpkg -i filebeat-oss-7.6.1.deb
service filebeat stop
service filebeat start
service filebeat staus
Kibana 使用
完成了第一階段的配置后,登錄 http://localhost:9200 即可查看日志,如何使用 Kibana 請參見官方幫助文檔。