最近ELK(elasticsearch+logstash+kibana)學習小結
前提:處理大資料日誌收集分析,隨著搜尋叢集的快速膨脹,大量日誌處理及情況反饋滯後帶來一系列問題,亟需一個工具能快速分析定位叢集中那種日誌或那個機器出現了異常。運維的日誌分析系統定製化較重,分析不夠實時。故找一個RTF工具可以直接即上手。
1、簡介:
logstash日誌收集分發到elastic叢集,elasticsearch進行資料索引,kibana進行結構化查詢展示,redis做快取佇列。
2、安裝:
logstash,新版下載即可用,需加配置檔案agent.conf和index.conf,當然最好途徑是官網sample即得即用。
網址:http://logstash.net/
elasticsearch,下載新版,有個wrapping下載解壓到bin/servic目錄即可使用,中文版需要下載rtf版本或安裝外掛。
網址:附上高人git://github.com/medcl/elasticsearch-rtf.git 的整合版,or官網
kibana,查詢結果圖形展示分析
Visit Elasticsearch.org for the full Kibana documentation.無須多說,這句就夠了。
3、配置:
logstash,通過agent方式收集到中心服務,並通過index doc方式傳送資料給elasticsearch,故可以配置多個一對一日誌收集或多c到s的日誌收集模式,即客戶端到服務端收集模式
配置簡介:http://langke.name/tag/kibana
本人試用配置:agent.conf
input { file { type => "ses_access" path => ["/log/demo.log"] }}output { redis { host => "localhost" data_type => "list" key => "logstash:redis" }}
index.conf
input { redis { host => '127.0.0.1' data_type => 'list' port => '6379' key => 'logstash:redis' type => 'redis-input' }}output { elasticsearch { embedded => false protocol => "http" host => "localhost" port => "9200" }}
elasticsearch下載安裝後,即可直接使用,預設配置已開啟
注意:config/elasticsearch.yml通常需新增http的配置:kibana才能通過http介面訪問
http.cors.enabled: truehttp.cors.allow-origin: "*"
kibana檢視配置config/kibana.yml,elas的埠是否正確
ok,基礎配置已有
4、啟動測試
bin/service/elasticsearch console
bin/logstash -f agent.conf --verbose -l log-ag.log
bin/logstash agent -f indexer.conf --verbose -l log-es.log
預設logstash已經安裝kibana外掛可以直接享用了
檢視:http://localhost:9292/index.html#/dashboard/file/logstash.json
UTC時間問題:
logstash:
修改logstash/lib/logstash/event.rb 可以解決這個問
.withZone(org.joda.time.DateTimeZone::UTC)
修改為
.withZone(org.joda.time.DateTimeZone.getDefault())
看到資料恭喜你已經邁出了成功的一步!!
參考:http://langke.name/tag/kibana