【ELK】【docker】【elasticsearch】2.使用elasticSearch+kibana+logstash+ik分詞器+pinyin分詞器+繁簡體轉化分詞器 6.5.4 啓動 ELK+

官網地址:https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#docker-cli-run-prod-modehtml

 

1.拉取鏡像

docker pull elasticsearch:6.5.4
docker pull kibana:6.5.4

 

2.啓動容器

docker run  -d --name es1  -p 9200:9200 -p 9300:9300 --restart=always -e "discovery.type=single-node" elasticsearch:6.5.4
docker run -d  -p 5601:5601 --name kibana --restart=always --link es1:elasticsearch  kibana:6.5.4

 若是啓動ES僅是測試使用,啓用單節點便可。node

若是啓動ES是要給生產任務使用,須要啓動ES集羣。ES  6.5.4啓動集羣文章git

3.訪問地址

http://192.168.92.130:5601/status

 

4.安裝ik分詞器

進入es容器github

sudo docker exec -it es1 /bin/bash

 

進入plugins目錄docker

cd plugins/

 

此時查看插件目錄下,有兩個插件的目錄json

 

下載對應es版本的ik的壓縮包【安裝插件的版本須要與es版本一致】數組

wget http://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.5.4/elasticsearch-analysis-ik-6.5.4.zip

 

建立ik目錄,用於存放解壓ik壓縮包的文件ruby

mkdir elasticsearch-analysis-ik

 

 

解壓ik壓縮包到指定目錄bash

unzip elasticsearch-analysis-ik-6.5.4.zip -d elasticsearch-analysis-ik

 

 刪除源壓縮包app

rm -f elasticsearch-analysis-ik-6.5.4.zip

 

exit  退出容器 重啓es容器 查看啓動日誌加載插件信息

exit
docker restart es1
docker logs -f es1

 

 驗證ik分詞器是否安裝成功【analyzer參數值:ik_max_word 若是未安裝成功,請求就會報錯!】

兩種粗細粒度分別爲:

  ik_max_word

  ik_smart

POST     http://192.168.92.130:9200/_analyze

請求體:

{
    "analyzer":"ik_max_word",
    "text":"德瑪西亞之力在北韓打倒了變形金剛"
}

結果:

{
    "tokens": [
        {
            "token": "",
            "start_offset": 0,
            "end_offset": 1,
            "type": "CN_CHAR",
            "position": 0
        },
        {
            "token": "",
            "start_offset": 1,
            "end_offset": 2,
            "type": "CN_CHAR",
            "position": 1
        },
        {
            "token": "西亞",
            "start_offset": 2,
            "end_offset": 4,
            "type": "CN_WORD",
            "position": 2
        },
        {
            "token": "之力",
            "start_offset": 4,
            "end_offset": 6,
            "type": "CN_WORD",
            "position": 3
        },
        {
            "token": "",
            "start_offset": 6,
            "end_offset": 7,
            "type": "CN_CHAR",
            "position": 4
        },
        {
            "token": "北韓",
            "start_offset": 7,
            "end_offset": 9,
            "type": "CN_WORD",
            "position": 5
        },
        {
            "token": "打倒",
            "start_offset": 9,
            "end_offset": 11,
            "type": "CN_WORD",
            "position": 6
        },
        {
            "token": "倒了",
            "start_offset": 10,
            "end_offset": 12,
            "type": "CN_WORD",
            "position": 7
        },
        {
            "token": "變形金剛",
            "start_offset": 12,
            "end_offset": 16,
            "type": "CN_WORD",
            "position": 8
        },
        {
            "token": "變形",
            "start_offset": 12,
            "end_offset": 14,
            "type": "CN_WORD",
            "position": 9
        },
        {
            "token": "金剛",
            "start_offset": 14,
            "end_offset": 16,
            "type": "CN_WORD",
            "position": 10
        }
    ]
}
View Code

 ik分詞器成功安裝

 

附加一個:

查看某個index下某個type中的某條document的某個屬性的屬性值 分詞效果:

格式以下:

你的index/你的type/document的id/_termvectors?fields=${字段名}
http://192.168.92.130:9200/swapping/builder/6/_termvectors?fields=buildName

【注意fields參數對應的是數組】

 

 

 

 

 

5.安裝pinyin分詞器

 進入容器

sudo docker exec -it es1 /bin/bash

進入插件目錄

cd plugins/

建立目錄elasticsearch-analysis-pinyin

mkdir elasticsearch-analysis-pinyin

進入目錄elasticsearch-analysis-pinyin,下載pinyin分詞器壓縮包【注意版本和es版本一致】

cd elasticsearch-analysis-pinyin/
wget https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v6.5.4/elasticsearch-analysis-pinyin-6.5.4.zip

 

解壓壓縮包,解壓完成刪除壓縮包

unzip elasticsearch-analysis-pinyin-6.5.4.zip
rm -f elasticsearch-analysis-pinyin-6.5.4.zip

 

退出容器,重啓es,查看日誌

exit
docker restart es1
docker logs -f es1

驗證pinyin分詞器是否安裝成功

 

結果:

{
    "tokens": [
        {
            "token": "de",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 0
        },
        {
            "token": "dmxyzlzbhddlbxjg",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 0
        },
        {
            "token": "ma",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 1
        },
        {
            "token": "xi",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 2
        },
        {
            "token": "ya",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 3
        },
        {
            "token": "zhi",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 4
        },
        {
            "token": "li",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 5
        },
        {
            "token": "zai",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 6
        },
        {
            "token": "bei",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 7
        },
        {
            "token": "han",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 8
        },
        {
            "token": "da",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 9
        },
        {
            "token": "dao",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 10
        },
        {
            "token": "le",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 11
        },
        {
            "token": "bian",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 12
        },
        {
            "token": "xing",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 13
        },
        {
            "token": "jin",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 14
        },
        {
            "token": "gang",
            "start_offset": 0,
            "end_offset": 0,
            "type": "word",
            "position": 15
        }
    ]
}
View Code

證實pinyin插件安裝成功

 

6.繁簡體轉化分詞器

進入es容器

sudo docker exec -it es1 /bin/bash

進入plugins目錄

cd plugins/

建立繁簡體轉化目錄

mkdir elasticsearch-analysis-stconvert

進入目錄

cd elasticsearch-analysis-stconvert/

下載插件壓縮包

wget https://github.com/medcl/elasticsearch-analysis-stconvert/releases/download/v6.5.4/elasticsearch-analysis-stconvert-6.5.4.zip

解壓壓縮包

unzip elasticsearch-analysis-stconvert-6.5.4.zip

解壓完成後,移除原壓縮包

rm -f elasticsearch-analysis-stconvert-6.5.4.zip

退出容器

exit

重啓es

docker restart es1

查看日誌

檢驗繁簡體轉化是否安裝成功

URL:POST

http://192.168.92.130:9200/_analyze

請求體:

{
  "analyzer":"stconvert",
  "text" : "國際電視臺"
}

請求結果:

 

繁簡體轉化安裝成功

 

 

 7.安裝啓動logstash

docker拉取logstash

docker pull logstash:6.5.4

啓動logstash

docker run -d -p 5044:5044 -p 9600:9600 --restart=always --name logstash logstash:6.5.4

查看日誌

docker logs -f logstash

查看日誌能夠看出,雖然啓動成功,可是並未鏈接上es,

 

這就須要修改logstash中的對接配置

進入logstash容器內

docker exec -it logstash /bin/bash

進入config目錄

cd /usr/share/logstash/config/

修改logstash.yml文件中的es.url

vi logstash.yml

修改url爲本身的es所在IP:port

退出容器,重啓logstash

exit
docker restart logstash

查看日誌能夠看到啓動成功而且es鏈接池中剛剛配置的鏈接地址已經鏈接成功

 

 回到kibana,查看ELK狀態以及運轉狀況

 

OK,ELK搭建完成!!! 

 

 =================================================附錄=============================================================================

 

1、ELK概念描述

看到這裏,有不少地方都是迷迷糊糊的吧。

這裏簡單一說:

ELK是一整套的分佈式日誌分析平臺的解決方案。

 

在ELK【都是開源軟件】中,

E表明 es,用於存儲日誌信息【就是一個開源可持久化的分佈式全文搜索引擎】

L表明logstash,用於收集日誌信息【開源數據收集引擎】

K表明kibana,用於展現日誌信息【開源的分析和可視化平臺】

 

2、關於logstash插件的知識

這裏就要了解一些logstash的知識 logstash插件詳解

而對於logstash的收集功能,實際上是由它的一個一個插件完成的。而主體的三個插件配置就是input--->filter--->output,以下圖所示。

 其中input和output是必須的,而filter是非必須的。

input插件配置,是指定數據的輸入源,配置標明要收集的數據是從什麼地方來的。一個 pipeline是能夠指定多個input插件的。

    input能夠是stdin、file、kafka

filter插件配置,是對原始數據進行類型轉化、刪除字段、格式化數據的。不是必須的配置。

    filter能夠是date、grok、dissect、mutate、json、geoip、ruby

output插件配置,是將數據輸出到指定位置。

    output能夠是stdout、file、elasticsearch

 

 

====================================================================================================

相關文章
相關標籤/搜索