Elasticsearch、Logstash和Kibana Windows環境搭建(一)

來源:互聯網
上載者:User

標籤:sql   bin   斷行符號   dcl   ica   master   redis   友好   lin   

一、概述
ELK官網 https://www.elastic.coELK由Elasticsearch、Logstash和Kibana三部分組件組成;Elasticsearch是個開源分布式搜尋引擎,它的特點有:分布式,零配置,自動探索,索引自動分區,索引複本機制,restful風格介面,多資料來源,自動搜尋負載等。Logstash是一個完全開源的工具,它可以對你的日誌進行收集、分析,並將其儲存供以後使用kibana 是一個開源和免費的工具,它可以為 Logstash 和 Elasticsearch 提供的日誌分析友好的 Web 介面,可以協助您匯總、分析和搜尋重要資料日誌。

常見平台架構

ELK = Elasticsearch + Logstash + KibanaEFK = Elasticsearch + Flume + Kibana簡單架構:ELK+Redis或(Logstash/Flume)->(Kafka/Redis)->ES->Web可更簡單些:Client(Filebeat) --> LogServer(Logstash-->Elasticsearch-->Kibana )(可以不用Logstash,Filebeat直接輸出到ES)複雜架構:資料擷取層[離線/即時資料,MySQL/ES/Logstash/Flume]->資料轉送層[Kafka/Redis]->資料緩衝層[Storm->Kafka]->計算儲存層[離線計算(Kylin/Spark SQL/Impala/MR)、即時計算(Storm/Spark Streaming/Flink/Druid)、儲存(ES/MySQL/Hbase/HDFS/Kudu)]->應用程式層[Web/REST API]

二、下載安裝ELK
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.3.tar.gz --no-check-certificatewget https://artifacts.elastic.co/downloads/logstash/logstash-5.4.3.tar.gz --no-check-certificatewget https://artifacts.elastic.co/downloads/kibana/kibana-5.4.3-windows-x86.zip --no-check-certificate注意需要jdk8環境


在windows 上運行 elasticsearch 分布式日誌分析,檢索

https://www.elastic.co/downloads  

在介面中下載  elasticsearch   Logstash  Kibana

1 .  elasticsearch   下載 ,zip 解壓縮,進入bin 運行檔案elasticsearch.bat  

訪問 http://localhost:9200 

啟動成功   


2 .由於elasticsearch 只是字串 等檔案資訊 ,需要安裝  elasticsearch-head 外掛程式

            在目前的版本中,由於使用的是6.4.0進行環境搭建,需要使用node 等工具進行安裝外掛程式

            步驟一。 安裝node   在此不再贅述

            步驟二。安裝 npm install -g grunt-cli   安裝   grunt  

                         使用 grunt –version  查看安裝 grunt的版本資訊

 

3.修改elasticsearch/conf 檔案夾 修改  elasticsearch.xml 檔案  ,

 

進入安裝目錄下的config目錄,修改elasticsearch.yml檔案.在檔案的末尾加入以

http.cors.enabled: true

http.cors.allow-origin: "*"

node.master: true

node.data: true

其他動作

然後去掉network.host: 192.168.0.1的注釋並改為network.host: 0.0.0.0,去掉cluster.name;node.name;http.port的注釋(也就是去掉#)

  雙擊elasticsearch.bat重啟es


4.下載elasticsearch-head包


https://github.com/mobz/elasticsearch-head  中下載head外掛程式,選擇下載zip

5.解壓到指定檔案夾下,G:\elasticsearch-6.6.2\elasticsearch-head-master  進入該檔案夾,修改G:\elasticsearch-6.6.2\elasticsearch-head-master\Gruntfile.js 在對應的位置加上hostname:‘*‘

6. 修改完成後,使用cmd命令進入 elasticsearch-head-master 檔案夾中  ,     執行命令 npm install   然後在執行 npm run start   運行 head

運行成功 成功介面


訪問介面

以上為elasticsearch 安裝和查看教程

測試elasticsearch-head 

  1.使用cmd請求 

curl -XGET http://127.0.0.1:9200/_cluster/health?pretty
請求結果 

 2.使用elasticsearch-head進行請求
 請求結果

☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆

啟動  logstash 服務 需要修改 conf中添加 logstash.conf   在建立的檔案中粘貼

input {
     file {
         type => "nginx_access"
         path => "D:\nginx\logs\access.log"
     }
}
output {
     elasticsearch {
         hosts => ["192.168.10.105:9200"]
         index => "access-%{+YYYY.MM.dd}"
     }
     stdout {
         codec => json_lines
     }
}

進入到bin檔案夾中 執行   
   命令1   logstash.bat agent –f   ../config/logstash.conf

    命令2   logstash.bat -f  ../config/logstash.conf

啟動 logstash  如果報錯  將  logstash.bat  中的  "%CLASSPATH%"  使用  ”” 引號引起來,在執行即可

啟動報錯,不能當成持續服務

     reason=>"Expected one of #, input, filter, output at line 1, column             1       (byte1)after "}

是檔案格式問題。

Windows檔案預設是utf8 。將檔案格式改為:ansi格式就可以了。程式可以正常運行bin\logstash -f ./config/test.conf


啟動Kibana 服務

進入到   kibana-6.4.0-windows-x86_64/bin 檔案夾  雙擊 Kibana.bat

剛啟動時 ,需要等大概一分鐘  ,cmd命令 視窗沒有反應




Elasticsearsh 設定中文分詞器

使用安裝命令  elasticsearch-plugin.bat install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.0/elasticsearch-analysis-ik-6.4.0.zip

使用windows 安裝會報錯,不如直接下載  然後將檔案  資訊解壓到 elasticsearch/plugs/ik檔案夾下

驗證 在kibana中可以進行 請求,也可在 elasticsearsh中進行請求

GET    _search    { "query": { "match": { "message": "中華" } } }




將elasticsearsh 設定為windows 系統服務

     在bin中執行   elasticsearch-service.bat install

將logstash   Kibana 設定為windows 服務

使用nssm進行安裝

   nssm    (官網地址)   https://nssm.cc/ci/nssm-2.24-101-g897c7ad.zip

使用

進入到 ELK_WORK\nssm-2.24-101-g897c7ad\win64>nssm install logstash/Kibana

斷行符號後會彈出執行框

NSSM  用法 (  Linux service 使用一樣)

To manage a service:

        nssm start <servicename>

        nssm stop <servicename>

        nssm restart <servicename>

        nssm status <servicename>

        nssm statuscode <servicename>

        nssm rotate <servicename>

        nssm processes <servicename>

 

 

總結,

在windows中啟動  ELK 日誌收集分析查詢 功能 ,

將會在服務中安裝三個服務

Elasticsearch 服務  訪問地址  192.168.10.105:9200

服務名  Elasticsearch 6.4.0 (elasticsearch-service-x64)


logstash 服務  訪問地址 192.168.10.105:9600

Kibana   服務   訪問地址:http://localhost:5601

Elasticsearch、Logstash和Kibana Windows環境搭建(一)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.