1、Elasticsearch介紹java
以前有學習使用過Solr。Elasticsearch也是基於Lucene的搜索服務器。它提供了一個分佈式多用戶能力的全文搜索引擎,基於RESTful web接口。Elasticsearch是用Java開發的,並做爲Apache許可條款下的開放源碼發佈,是當前流行的企業級搜索引擎。設計用於雲計算中,可以達到實時搜索,穩定,可靠,快速,安裝使用方便。官方客戶端在Java、.NET(C#)、PHP、Python、Apache Groovy、Ruby和許多其餘語言中都是可用的。node
2、CentOS 7.3安裝ES linux
//ES不可使用root啓動,須要建立用戶 //建立一個用戶組 取名爲es groupadd es //建立一個用戶,將其添加到es組裏面 useradd yangk -g es //爲其設置目錄權限,我安裝的ES是在/yangk/elasticsearch-7.0.1 chown -R yangk:es /yangk/elasticsearch-7.0.1 //切換用戶 su 用戶 //啓動es -d是後臺啓動 ./elasticsearch -d //配置其能夠遠程訪問 //修改/yangk/elasticsearch-7.0.1/config/elasticsearch.yml找到 Network network.host: 0.0.0.0 //在末尾添加,開啓跨域訪問 http.cors.enabled: true http.cors.allow-origin: "*"
此時啓動的時候還有可能出現如下錯誤git
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535] [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] [3]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
第一個問題:github
//這個錯誤,主要是由於linux會限制進程的最大打開文件數 //首先切換到root su root //編輯vi /etc/security/limits.conf //在文件末尾增長 yangk - nofile 65536 # 將 yangk替換爲本身的用戶名
第二個問題web
這個是ES使用的虛擬內存過小,直接調大便可,在 root 用戶下執行下面命令: sysctl -w vm.max_map_count=262144
第三個問題數據庫
仍是找到 config/elasticsearch.yml 文件,編輯,找到 Discovery 配置附近,修改 # 取消註釋,並修改屬性 cluster.initial_master_nodes: ["127.0.0.1"]
配置完以後啓動仍是出現報錯npm
[INFO ][o.e.b.BootstrapChecks ] [gFOuNlS] bound or publishing to a non-loopback address, enforcing bootstrap checks ERROR: [2] bootstrap checks failed
解決方案bootstrap
//切換到root用戶 //修改vi /etc/security/limits.conf。增長 * soft nofile 65536 * hard nofile 131072 * soft nproc 4096 * hard nproc 4096 //修改vi /etc/security/limits.d/XX-nproc.conf #修改成,這個有可能存在 * soft nproc 4096 //修改 /etc/sysctl.conf 增長 vm.max_map_count=655360 //執行命令 sysctl -p
這樣就啓動成功跨域
3、ES圖形化界面
下載地址:https://github.com/mobz/elasticsearch-head
這是一個node.js的項目,須要先安裝node環境
而後在cmd裏面進入elasticsearch-head根目錄安裝項目所需依賴
//安裝grunt npm install -g grunt-cli //安裝head所需依賴 npm i //啓動項目 run run start 或者 grunt server //啓動項目有可能會出現grunt權限不足等。只須要軟鏈接一下就能夠了 ln -s /yangk/node-v8.11.3-linux-x64/bin/grunt /usr/local/bin/grunt
4、ES和關係型數據庫的比較
在elastic search 6.0以後的版本已經對type這個概念逐漸淡化。因此把索引比做數據庫中的表,文檔比做行更爲恰當。