elastlcsearch分佈式存儲引擎------環境搭建

環境搭建

如今有兩臺服務器分別爲10.19.40.63和10.19.40.64,分別在這兩臺服務器上安裝兩個節點。java

一、下載elasticsearch-6.4.1.tar.gz安裝包node

二、解壓安裝包:tar -zxvf elasticsearch-6.4.1.tar.gz。python

三、在10.19.40.63服務器上建立elasticsearch01和elasticsearch02目錄,在10.19.40.64服務器上建立elasticsearch03和elasticsearch04目錄,將解壓的文件拷貝到四個目錄下。es6

四、在四個節點的config目錄下的elasticsearch.yml配置文件進行配置各節點的信息。配置信息以下npm

#集羣的名稱
cluster.name: es6
#節點名稱,其他兩個節點分別爲node-2 和node-3
node.name: node-1
#指定該節點是否有資格被選舉成爲master節點,默認是true,es是默認集羣中的第一臺機器爲master,若是這臺機掛了就會從新選舉master
node.master: true
#容許該節點存儲數據(默認開啓)
node.data: true
#索引數據的存儲路徑
path.data: /usr/local/elk/elasticsearch/data
#日誌文件的存儲路徑
path.logs: /usr/local/elk/elasticsearch/logs
#設置爲true來鎖住內存。由於內存交換到磁盤對服務器性能來講是致命的,當jvm開始swapping時es的效率會下降,因此要保證它不swap
bootstrap.memory_lock: true
#綁定的ip地址
network.host: 0.0.0.0
#設置對外服務的http端口,默認爲9200
http.port: 9200
# 設置節點間交互的tcp端口,默認是9300 
transport.tcp.port: 9300
#Elasticsearch將綁定到可用的環回地址,並將掃描端口9300到9305以嘗試鏈接到運行在同一臺服務器上的其餘節點。#這提供了自動集羣體驗,而無需進行任何配置。數組設置或逗號分隔的設置。每一個值的形式應該是host:port或host#(若是沒有設置,port默認設置會transport.profiles.default.port 回落到transport.tcp.port)。#請注意,IPv6主機必須放在括號內。默認爲127.0.0.1, [::1]
discovery.zen.ping.unicast.hosts: ["192.168.8.101:9300","192.168.8.103:9300", "192.168.8.104:9300"]
#若是沒有這種設置,遭受網絡故障的集羣就有可能將集羣分紅兩個獨立的集羣 - 分裂的大腦 - 這將致使數據丟失
discovery.zen.minimum_master_nodes: 3

五、建立用戶組和用戶用來管理elasticsearch:json

  groupadd elsearchbootstrap

  useradd elsearch -g elsearch -p elasticsearch數組

  chown -R elsearch:elsearch elasticsearch01服務器

  chown -R elsearch:elsearch elasticsearch02網絡

六、在經過指令:su es,轉換用戶到es。進入elasticsearch/bin目錄。執行./elasticsearch -d啓動服務。

七、若是報下圖錯誤:

須要修改以下配置文件:

  /etc/security/limits.conf文件須要添加以下參數

  * soft nofile 65536

  * hard nofile 131072

  * soft nproc 2048

  * hard nproc 4096

   /etc/sysctl.conf文件須要添加以下參數

  vm.max_map_count = 655360

   /etc/security/limits.d/20-nproc.conf文件添加以下參數

  soft nproc 4096

在修改完配置文件後,進行熱加載:

  sysctl -p

elasticsearch-head搭建

一、須要安裝相應的依賴包node.js和python

二、解壓elasticsearch-head-master.zip壓縮包

三、cd elasticsearch-head-master目錄,執行以下指令:npm install

四、若是在執行npm install時,報以下錯誤:

則須要執行以下指令:

npm install phantomjs-prebuilt@2.1.14 --ignore-scripts

五、以下配置文件

  • 修改Head主目錄下的Gruntfile.js

 

  • 修改elasticsearch下的配置文件elasticsearch.yml
#在文件末尾添加便可,此處須要注意yml的格式問題(有的博友已經遇到了不生效,詳見評論---20180927)
http.cors.enabled: true
http.cors.allow-origin: "*"

六、啓動head:npm run start

使用IK分詞器

一、能夠經過命令:unzip 文件夾   進行解壓elasticsearch-analysis-ik-6.4.1.zip。

二、在plugins目錄下建立ik目錄,將解壓的文件複製到ik目錄下。

三、從新啓動elasticsearch。

四、若是日誌中出現以下內容,則安裝成功:

基本的索引操做指令

一、查看集羣的狀態信息
  http://10.19.40.63:9200/_cluster/health?pretty
二、查看索引
  curl http://10.19.40.63:9200/_cat/indices/index?v
三、建立索引
  curl -XPUT http://10.19.40.63:9200/index
四、查看索引的基本信息
  curl -XGET http://10.19.40.63:9200/index/_settings
五、查看索引的所有映射
  curl http://10.19.40.63:9200/index/_mapping
六、查看分詞效果
  http://10.19.40.63:9200/_analyze
  {
  "analyzer":"standard",
  "text":"中華人民共和國國歌"
  }

七、建立文檔映射

curl -H "Content-Type:application/json" -XPOST http://10.19.40.63:9200/index//_mapping -d'
  { "fulltext": {
  "_all": {
  "analyzer": "ik"
  }, "properties": {
  "content": {
  "type" : "string",
  "boost" : 8.0,
  "term_vector" : "with_positions_offsets",
  "analyzer" : "ik",
  "include_in_all" : true
    }
  }
}

八、插入文檔

  curl -H "Content-Type:application/json" -XPOST http://10.19.40.63:9200/index/fulltext/1 -d'  {"content":"美國留給伊拉克的是個爛攤子嗎"}'九、查詢索引  curl -H "Content-Type:application/json" -XPOST http://10.19.40.63:9200/index/fulltext/_search -d'  {   "query" : { "match" : { "content" : "美國" }}  }'

相關文章
相關標籤/搜索