ELK6.0日誌從收集處處理完整版教程(二)

ELK簡介

Elasticsearch
開源分佈式搜索引擎,它的特色有:分佈式,零配置,自動發現,索引自動分片,索引副本機制,restful風格接口,多數據源,自動搜索負載等。也能夠認爲ElasticSearch是一個NoSQL存儲中心,能夠存儲各類數據,而且查詢速度超級快。node

Logstash
徹底開源的工具,能夠從各類輸入流(文件,隊列,數據庫)收集信息,並對信息進行處理,將處理後的信息存儲到ElasticSearchlinux

kibana
開源和免費的工具,它能夠從ElasticSearch讀取日誌等存儲的信息, 提供的日誌分析友好的 Web 界面,能夠幫助您彙總、分析和搜索重要數據日誌。webpack

1.Kibana安裝與配置

[elk@server02 elk]# tar -zxvf kibana-6.2.4-linux-x86_64.tar.gznginx

[root@server02 kibana-6.2.4-linux-x86_64]# ls
bin  config  data  LICENSE.txt  node  node_modules  nohup.log  NOTICE.txt  optimize  package.json  plugins  README.txt  src  ui_framework  webpackShimsweb

配置文件:數據庫

[root@server02 config]#  grep "^\s*[^# \t].*$" config/kibana.yml 
server.port: 5601
server.host: 0.0.0.0             #將本機的外網ip地址配置上,這樣外網才能訪問到
elasticsearch.url: "http://localhost:9200"    ##配置EA的地址,本機使用localhost,可配置ipapache

啓動:json

nohup sh ./bin/kibana > nohup.log &
http://192.168.3.113:5601     #驗證web頁面啓動restful

關閉kibana:ps -ef | grep node   #查看進程,kill -9 app

2.LogStash安裝與配置

[root@server02 elk]# tar -zxvf logstash-6.2.4.tar.gz
[root@server02 logstash-6.2.4]# cat config/logstash.conf

input {
    beats {
        port => "5043"
    }
}
filter {
    grok {
        match => { "message" => "\[%{IP:ip}\] \[%{TIMESTAMP_ISO8601:timestamp}\] \[%{NOTSPACE:class}\]"}
    }
}
output {
    elasticsearch {
        hosts => [ "http://localhost:9200" ]
    }
}

啓動:

[root@server02 logstash-6.2.4]# nohup  bin/logstash -f config/logstash.conf > nohup.log &

3.Filebeat安裝與配置

[root@server02 elk]# tar -zxvf filebeat-6.2.4-linux-x86_64.tar.gz
filebeat必須屬於root用戶名下;filebeat.yml中 enable項都由false改成true;

開啓收集system系統日誌:  ./filebeat modules enable system

過濾配置文件中的註釋空格等無用字符只顯示生效配置:
[root@server02 filebeat-6.2.4-linux-x86_64]# grep "^\s*[^# \t].*$" filebeat.yml
filebeat.prospectors:
- type: log
  enabled: true
  paths:
    - /var/log/*.log
filebeat.config.modules:
  path: ${path.config}/modules.d/*.yml
  reload.enabled: true
setup.template.settings:
  index.number_of_shards: 3
setup.kibana:
  host: "localhost:5601"

#output.elasticsearch:
  #hosts: ["localhost:9200"]
output.logstash:
   hosts: ["localhost:5043"]

啓動:
nohup ./filebeat -e -c filebeat.yml -d "Publish" > filebeat.log &

 

 

最後kibana配置:

選擇對應須要收集展現的日誌類型:如:System,nginx,apache,Redis等

按教程配置filebeat後按System logs dashboard

第一次訪問的時候,會要求設置Index Pattern,由於咱們在logstash-es.conf中設置爲logstash-%{+YYYY-MM},因此設置爲logstash-*就能夠了。

Discover是主要的查詢交互界面,以下所示:
  

相關文章
相關標籤/搜索