ElasticSearch初探-安裝

寫在前面的話

通過一個半月的不懈努力, 小說項目已經完成了一大半, 前端界面以及api對接所有完成, 後臺系統完成一小部分功能。前端

記得當初作這個項目的初衷是由於感受本身所學太雜, 並且本身對一些技術如Kafka, ES很感興趣,因此想經過這個項目對這些東西進行融合,加深對其印象linux

在項目中, 我採用ElasticSearch來處理項目中的小說搜索git

Elasticsearch 是什麼

  • Elasticsearch是一個基於Apache Lucene(TM)的實時分佈式搜索和分析引擎,可是若是要直接使用lucene, 卻很是困難。 由於Lucene只是一個庫, 想要使用它,你必須使用Java來做爲開發語言並將其直接集成到你的應用中,更糟糕的是,Lucene很是複雜,你須要深刻了解檢索的相關知識來理解它是如何工做的。。。github

  • Elasticsearch也使用Java開發並使用Lucene做爲其核心來實現全部索引和搜索的功能,可是它的目的是經過簡單的RESTful API來隱藏Lucene的複雜性,從而讓全文搜索變得簡單apache

  • Elasticsearch能夠很輕鬆的橫向擴展, 可支持PB級的結構和非結構數據處理npm

關於Elasticsearch的應用場景

  • 海量數據的分析
  • 站內搜索引擎
  • 數據倉庫

對ES(Elasticsearch)的瞭解

  1. 加深對ES的理解的最好方式就是運行它, 那麼咱們先來安裝bootstrap

  2. 安裝環境centos

CentOS 7api

JDK 1.8 (必須)跨域

ES-6.8.2 和JDK的版本是對應關係

  • 下載

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.8.2.tar.gz

  • 下載完成後, 解壓

tar -zxvf elasticsearch-6.8.2.tar.gz

  • 建立用戶組, 受權

ES不能使用root用戶來啓動

groupadd elasticsearch
useradd -r -g elasticsearch elasticsearch
chown -Rf elasticsearch:elasticsearch elasticsearch-6.8.2
複製代碼
  • 啓動ES

./bin/elasticsearch

  1. ES默認只能經過本地來執行, 若是須要修改, 修改配置文件 elasticsearch.yml

network.host: 0.0.0.0

  1. 若是想要在後臺啓動, 能夠經過如下命令

nohup ./bin/elasticsearch &

./bin/elasticsearch -d

  • 驗證是否啓動

ES默認監聽9200端口

curl 'http://localhost:9200/'

{
  "name" : "7J76WwT",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "Wsfbm6vLS2uOyoDqWVppdw",
  "version" : {
    "number" : "5.5.2",
    "build_hash" : "b2f0c09",
    "build_date" : "2017-08-14T12:33:14.154Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"
}

複製代碼

可以輸出相似的內容說明已經啓動成功

到此, 關於ES的簡介和單機版安裝就完成了

擴展

按照上述的安裝方式, 在遠程鏈接ES的時候會出現出現如下問題, 咱們來解決下

當咱們設置 network.host: 0.0.0.0 在啓動過程當中會出現如下問題

max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

這裏錯誤是每一個進程最大同時打開文件數過小

修改/etc/security/limits.conf文件,增長配置, 須要從新進行登陸才能生效

*               soft    nofile          65536
*               hard    nofile          65536
複製代碼

能夠經過如下命令來查看

ulimit -Hn
ulimit -Sn
複製代碼

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

修改/etc/sysctl.conf文件,增長配置

vm.max_map_count=262144
sysctl -p 查看是否生效
複製代碼

system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own ris

這個問題是因爲centos的版本問題引發的, 在elasticsearch配置中配置

bootstrap.memory_lock: false
 bootstrap.system_call_filter: false
複製代碼

插件head安裝

在ES中的配置容許跨域

http.cors.enabled: true
http.cors.allow-origin: "*"
複製代碼

下載head項目 推薦採用Git下載, 點擊下載

這裏須要安裝Node, 你們另行baidu查詢

git clone git://github.com/mobz/elasticsearch-head.git

cd elasticsearch-head

//安裝依賴插件
npm install

//運行
npm run start
複製代碼

經過 http://localhost:9100/ 訪問

head安裝完成樣子
相關文章
相關標籤/搜索