1. 程式人生 > >centos下elasticsearch相關外掛(ik,kibana,filebeat,logstash)安裝

centos下elasticsearch相關外掛(ik,kibana,filebeat,logstash)安裝

centos下elasticsearch相關外掛(ik,kibana,filebeat,logstash)安裝

一:安裝ik分詞器

分詞是全文索引中非常重要的部分,Elasticsearch是不支援中文分詞的,ik分詞器支援中文
1.下載elasticsearch-analysis-ik
下載地址: https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.5.1/elasticsearch-analysis-ik-6.5.1.zip


注:v6.5.1必須保證與elasticsearch版本一致
2.安裝ik分詞器
直接解壓elasticsearch-analysis-ik-6.5.1.zip,並將解壓後的檔案目錄elasticsearch-analysis-ik-6.5.1放到elasticsearch的安裝目錄下的plugins下,然後重啟elasticsearch即可
3.測試ik分詞器

curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_analyze?pretty' -d '{
"analyzer" : "ik_max_word",
"text": "中華人民共和國國歌" }'

二:安裝kibana

1.下載安裝kibana
(1)cd到要下載到資料夾位置

cd /usr/local

(2)使用wget或者從官網https://www.elastic.co/cn/downloads/kibana下載rpm版本的安裝包

wget https://artifacts.elastic.co/downloads/kibana/kibana-6.5.1-x86_64.rpm

(3)使用rpm安裝

rpm -ivh kibana-6.5.1-x86_64.rpm

使用rpm安裝後為yum安裝的預設路徑,具體參考:https://www.cnblogs.com/kerrycode/p/6924153.html


2.修改kibana配置檔案
vim /etc/kibana/kibana.yml

server.port: 5601 #連線kibana的埠
server.host: 0.0.0.0 #可以外網連線
elasticsearch.url: http:localhost:9200#具體為你elasticsearch服務的連線
#如果你的elasticsearch有登入驗證則需要配置:
elasticsearch.username: "user"
elasticsearch.password: "pwd"

注:配置屬性時“:”後面務必加上空格再寫。
3.啟動kibana

#開啟
service kibana start
#查詢狀態
service kibana status

三:filebeat安裝

1.下載filebeat包

wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.5.1-x86_64.rpm

2.安裝filebeat

rpm -vi filebeat-6.5.1-x86_64.rpm

3.編輯配置檔案
vim /etc/filebeat/filebeat.yml

setup.kibana:
  host: "localhost:5601"
output.elasticsearch:
  hosts: ["localhost:9200"]
  #username: "elastic"
  #password: "changeme"

4.啟用和配置elasticsearch模組
vim /etc/filebeat/modules.d/elasticsearch.yml

filebeat modules enable elasticsearch

5.開啟filebeat

filebeat setup
service filebeat start

四:安裝logstash

1.下載logstash.rpm安裝包

wget https://artifacts.elastic.co/downloads/logstash/logstash-6.5.1.rpm

或者到官網下載:https://www.elastic.co/downloads/logstash
2.安裝logstash

rpm -vi logstash-6.5.1.rpm

3.建立conf檔案
cd 到/etc/logstash/conf.d
在conf.d資料夾下以.conf為字尾的任何名字的檔案
內容如下:

input {
   file{
       path=> "/usr/local/nginx/logs/cml.log"    ##nginx生成日誌的目錄
       type=> "cml"          ##索引的型別
       start_position=> "beginning"     ##一開始就輸入原來的日誌資訊
  }
  stdin{}
}
filter{
 grok {
       match => {
        "message" =>"(?<remote_IP>\d+.\d+.\d+.\d+)\s-\s-\s\[(?<DATA>\d+/\w+/\d+:\d+:\d+:\d+)[[:space:]](?<time_zone>\+\d+)\]\s\"(?<action>\w+)%{URIPATHPARAM:request} (?<Version>\w+/\d+.\d+)\"\s(?<status>\w+)\s(?<web_size>\w+)\s\"(?<language>\S+)\"\s"
##自定義grok
       }
}
 
}
output{
       elasticsearch{
       action=> "index"
       hosts=> "localhost:9200"      ##輸出到elasticsearch上面
       index=> "log-%{+yyyy.MM.dd}"     ##生成一個log-時間的索引
       }
  stdout {codec=>rubydebug}    ##在終端上輸出方便檢測
}

4.啟動logstash

initctl start logstash
或
systemctl start logstash.service