aws ec2 安裝Elastic search 7.2.0 kibana 並配置 hanlp 分詞插件


作者:season

Elastic search & kibana & 分詞器 安裝

版本控制

ES版本:7.2.0
分詞器版本:
kibana 版本:7.2.0

下載地址

ES 下載地址:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-2-0
kibana 下載地址:https://www.elastic.co/cn/downloads/past-releases/kibana-7-2-0
hanlp 分詞器下載地址: https://github.com/KennFalcon/elasticsearch-analysis-hanlp

Elastic search安裝

  • 0.添加es 用戶,並新建目錄

不能以root 方式運行elasticSearch

groupadd elasticsearch 
useradd elasticsearch -g elasticsearch

chown -R elasticsearch:elasticsearch /home/elasticsearch

  • 1.修改 配置文件 elasticsearch.yml
cluster.name: fastclaim
node.name: node-test
network.host: 172.31.3.50
http.port: 9200
cluster.initial_master_nodes: ["node-test"]
  • 2.針對無法創建本地文件問題,用戶最大可創建文件數太小

切換到root用戶,編輯limits.conf配置文件

vi /etc/security/limits.conf
#末尾添加
* soft nofile 65536
* hard nofile 65536
* soft nproc 65536
* hard nproc 65536
  • 3.針對無法創建本地線程問題,用戶最大可創建線程數太小
vi /etc/security/limits.d/90-nproc.conf
將
 * soft nproc 1024
修改爲
 * soft nproc 4096
 
  • 4.針對最大虛擬內存太小
    解決方法:切換到root用戶下,修改配置文件sysctl.conf
vi /etc/sysctl.conf
添加配置
vm.max_map_count=655360
執行命令
sysctl -p
  • 5.重新啓動,啓動成功

如果要在後臺運行,使用./bin/elasticsearch -d啓動

curl 172.31.3.50:9200

{
  "name" : "node-test",
  "cluster_name" : "fastclaim",
  "cluster_uuid" : "VtYF-EQIQNKHR1XWk7sE4g",
  "version" : {
    "number" : "7.2.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "508c38a",
    "build_date" : "2019-06-20T15:54:18.811730Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

kibana 安裝

  • 1.安裝及啓動

tar -xzvf 解壓縮後,進行安裝,
vim config/kibana.yml

# 修改如下四行
server.port: 5601
server.host: "172.31.3.50"
elasticsearch.hosts: ["http://172.31.3.50:9200"]
kibana.index: ".kibana"
# 後臺啓動

nohup ./bin/kibana >/dev/null &
  • 2.開發工具地址

http://IP:5601/app/kibana#/dev_tools/console?_g=()

分詞器配置

參考鏈接:https://github.com/KennFalcon/elasticsearch-analysis-hanlp

  • 1.下載安裝ES對應Plugin Release版本

安裝方式:

方式一

a. 下載對應的release安裝包,最新release包可從baidu盤下載(鏈接:https://pan.baidu.com/s/1mFPNJXgiTPzZeqEjH_zifw 密碼:i0o7)

b. 執行如下命令安裝,其中PATH爲插件包絕對路徑:
./bin/elasticsearch-plugin install file://${PATH}

方式二

a. 使用elasticsearch插件腳本安裝command如下:
./bin/elasticsearch-plugin install https://github.com/KennFalcon/elasticsearch-analysis-hanlp/releases/download/v7.2.0/elasticsearch-analysis-hanlp-7.2.0.zip

  • 2.安裝數據包
    release包中存放的爲HanLP源碼中默認的分詞數據,若要下載完整版數據包,請查看HanLP Release。
    數據包目錄:ES_HOME/plugins/analysis-hanlp
    注:因原版數據包自定義詞典部分文件名爲中文,這裏的hanlp.properties中已修改爲英文,請對應修改文件名
    hanlp.properties 在
    /home/elasticsearch/elasticsearch-7.2.0/config/analysis-hanlp 目錄中

因爲aws ec2 裏面網絡環境比較好,推薦直接在線安裝。

  • 3.重啓Elasticsearch

注:上述說明中的ES_HOME爲自己的ES安裝路徑,需要絕對路徑

  • 4.配置自定義詞典並熱更新

在本版本中,增加了詞典熱更新,修改步驟如下:

a. 在ES_HOME/plugins/analysis-hanlp/data/dictionary/custom目錄中新增自定義詞典
b. 修改hanlp.properties,修改CustomDictionaryPath,增加自定義詞典配置
c. 等待1分鐘後,詞典自動加載

具體腳本,以醫學常用詞典medical.txt 爲例

mv /tmp/medical.txt /home/elasticsearch/

cp /home/elasticsearch/medical.txt /home/elasticsearch/elasticsearch-7.2.0/plugins/analysis-hanlp/data/dictionary/custom/

#移動完成後修改權限

chown -R elasticsearch:elasticsearch /home/elasticsearch/


ll /home/elasticsearch/elasticsearch-7.2.0/plugins/analysis-hanlp/data/dictionary/custom/

#修改添加自定義目錄

vim /home/elasticsearch/elasticsearch-7.2.0/config/analysis-hanlp/hanlp.properties

# Custom dictinary path
CustomDictionaryPath=data/dictionary/custom/CustomDictionary.txt; ModernChineseSupplementaryWord.txt; ChinesePlaceName.txt ns; PersonalName.txt; OrganizationName.txt; ShanghaiPlaceName.txt ns;data/dictionary/person/nrf.txt nrf; medical.txt;

注:每個節點都需要做上述更改

  • 5.提供的分詞方式說明

hanlp: hanlp默認分詞
hanlp_standard: 標準分詞
hanlp_index: 索引分詞
hanlp_nlp: NLP分詞
hanlp_n_short: N-最短路分詞
hanlp_dijkstra: 最短路分詞
hanlp_crf: CRF分詞(已有最新方式)
hanlp_speed: 極速詞典分詞

  • 6.分詞樣例
GET /_analyze?pretty
{
  "analyzer" : "hanlp_crf",
  "text" : ["南京市長江大橋"]
}
{
  "tokens" : [
    {
      "token" : "南京市",
      "start_offset" : 0,
      "end_offset" : 3,
      "type" : "ns",
      "position" : 0
    },
    {
      "token" : "長江大橋",
      "start_offset" : 0,
      "end_offset" : 4,
      "type" : "nz",
      "position" : 1
    }
  ]
}
發佈了35 篇原創文章 · 獲贊 7 · 訪問量 9488
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章