通過一個半月的不懈努力, 小說項目已經完成了一大半, 前端界面以及api對接所有完成, 後臺系統完成一小部分功能。前端
記得當初作這個項目的初衷是由於感受本身所學太雜, 並且本身對一些技術如Kafka, ES很感興趣,因此想經過這個項目對這些東西進行融合,加深對其印象linux
在項目中, 我採用ElasticSearch來處理項目中的小說搜索git
Elasticsearch是一個基於Apache Lucene(TM)的實時分佈式搜索和分析引擎,可是若是要直接使用lucene, 卻很是困難。 由於Lucene只是一個庫, 想要使用它,你必須使用Java來做爲開發語言並將其直接集成到你的應用中,更糟糕的是,Lucene很是複雜,你須要深刻了解檢索的相關知識來理解它是如何工做的。。。github
Elasticsearch也使用Java開發並使用Lucene做爲其核心來實現全部索引和搜索的功能,可是它的目的是經過簡單的RESTful API來隱藏Lucene的複雜性,從而讓全文搜索變得簡單apache
Elasticsearch能夠很輕鬆的橫向擴展, 可支持PB級的結構和非結構數據處理npm
加深對ES的理解的最好方式就是運行它, 那麼咱們先來安裝bootstrap
安裝環境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
複製代碼
./bin/elasticsearch
network.host: 0.0.0.0
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
複製代碼
在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/ 訪問