Elasticsearch是一個基于Apache Lucene(TM)的開源搜索引擎,無論在開源還是專有領域,Lucene可以被認為是迄今為止最先進、性能最好的、功能最全的搜索引擎庫,但是,Lucene只是一個庫,想要使用它,你必須使用Java來作為開發語言并將其直接集成到你的應用中,更糟糕的是,Lucene非常復雜,你需要深入了解檢索的相關知識來理解它是如何作業的,Elasticsearch也使用Java開發并使用Lucene作為其核心來實作所有索引和搜索的功能,但是它的目的是通過簡單的RESTful API來隱藏Lucene的復雜性,從而讓全文搜索變得簡單,
v安裝Elasticsearch
1.0 安裝Java環境
安裝Elasticsearch之前,需要安裝Java8或Java8以上的Java環境,如果沒有安裝Java的,可以看之前的一篇文章《CentOS安裝Java JDK》,

1.1 下載ES
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.1-linux-x86_64.tar.gz
在這里你可以找到elasticsearch最新的安裝包,
下載之后用sudu rz -y上傳到linux服務器的/opt目錄,
1.2 解壓檔案
tar -zxvf elasticsearch-7.0.0.tar.gz
1.3 安裝完事洗掉壓縮包
rm -rf elasticsearch-7.0.0-linux-x86_64.tar.gz
v創建用戶
2.0 創建Elasticsearch用戶組
groupadd esgroup
2.1 創建es用戶
useradd esuser
passwd esuser
enter password
注意:為es用戶設定密碼時:1、密碼不得包含用戶名,即:esuser 2、密碼長度大于8位
本示例中我設定的測驗密碼是:toutoudemo
2.2 把用戶esuser添加到esgroup用戶組
usermod -G esgroup esuser
2.3 設定sudo權限
[root@localhost toutou]# visudo
#在root ALL=(ALL) ALL 一行下面
#添加estest用戶 如下:
esuser ALL=(ALL) ALL
#添加成功保存后切換到es用戶操作
[root@localhost toutou]# su esuser
[es@localhost root]$
2.4 驗證esuser的sudo權限
sudo -l -U esuser

2.5 更改elasticsearch-7.3.1檔案夾以及內部檔案的所屬用戶為esuser, 用戶組組為esgroup
sudo chown -R esuser:esgroup elasticsearch-7.3.1
v配置Elasticsearch
3.1 設定elasticsearch.yml
cluster.name: my-application
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
cluster.initial_master_nodes: ["node-1"]
elasticsearch.yml屬性含義:
屬性 cluster.name 如果在同一網段下有多個集群,就可以用這個屬性來區分不同的集群,
屬性 node.name 節點名可以忽略
屬性 node.master 指定該節點是否有資格被選舉成為node,默認是true
屬性 index.number_of_shard 設定默認索引分片個數,默認為5片
屬性 index.number_of_replica 設定默認索引副本個數,默認為1個副本
屬性 path.conf 設定組態檔的存盤路徑,默認是es根目錄下的config檔案夾,
屬性 path.data 設定索引資料的存盤路徑,默認是es根目錄下的data檔案夾
屬性 path.work 設定臨時檔案的存盤路徑,默認是es根目錄下的work檔案夾
屬性 path.logs 設定日志檔案的存盤路徑,默認是es根目錄下的logs檔案夾
屬性 path.repo 快照存盤路徑
屬性 gateway.recover_after_nodes 設定集群中N個節點啟動時進行資料恢復,默認為1
屬性 network.host 映射出來的ip
屬性 transport.tcp.port 設定節點間互動的tcp埠,默認是9300
屬性 http.port: 9200 設定對外服務的http埠,默認為9200
屬性 index.number_of_replicas 索引的復制副本數量
屬性 indices.fielddata.cache.size fielddata快取限制,默認無限制
屬性 indices.breaker.fielddata.limit fielddata級別限制,默認為堆的60%
屬性 indices.breaker.request.limit request級別請求限制,默認為堆的40%
屬性 indices.breaker.total.limit 保證上面兩者組合起來的限制,默認堆的70%
屬性 discovery.zen.ping.multicast.enabled 是否廣播模式,默認true,廣播模式即同一個網段的ES服務只要集群名[cluster.name]一致,則自動集群
屬性 discovery.zen.ping.unicast.hosts 手動指定,哪個幾個可以ping通的es服務做集群,注意該設定應該設定在master節點上,data節點無效
3.2 修改/etc/sysctl.conf
注意切換回root 用戶 執行
vm.max_map_count=262144
保存退出后,使用sysctl -p 重繪生效
3.3 修改檔案/etc/security/limits.conf
* hard nofile 65536
* soft nofile 65536
* soft nproc 2048
* hard nproc 65536
v啟動Elasticsearch
bin/elasticsearch

v安裝elasticsearch-head
elasticsearch-head是基于nodejs開發的,所以需要安裝nodejs環境
4.0 載nodejs 安裝包
wget https://nodejs.org/dist/v10.13.0/node-v10.13.0-linux-x64.tar.xz
4.1 安裝nodejs
tar -xvf node-v10.13.0-linux-x64.tar.xz
4.2 配置nodejs環境變數
vim /etc/profile
##配置nodejs 的HOME目錄
export NODEJS_HOME=/usr/local/node-v10.13.0-linux-x64
##加入nodejs的環境變數
export PATH=${JAVA_HOME}/bin:${NODEJS_HOME}/bin:$PATH
保存/etc/profile,并執行 source /etc/profile 使其生效,
4.3 驗證nodejs安裝是否成功
node -v
4.4 下載es-head并解壓
wget https://github.com/mobz/elasticsearch-head/archive/master.zip
unzip master.zip
4.5 進入解壓head目錄
執行 npm install
若提示npm不可用,則需要安裝npm sudo apt-get install npm
4.6 運行elasticsearch-head服務
npm run start
啟動后瀏覽器中輸入http://localhost:9100,效果如下:

4.7 配置es的連接地址
vim /opt/elasticsearch-head/_site/app.js
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://ip:9200";
4.8 修改Elasticsearch 服務配置屬性
修改elasticsearch服務組態檔允許跨域(在elasticsearch.yml檔案中添加)
http.cors.enabled: true
http.cors.allow-origin: "*"
4.9 測驗效果

作 者:請叫我頭頭哥
出 處:http://www.cnblogs.com/toutou/
關于作者:專注于基礎平臺的專案開發,如有問題或建議,請多多賜教!
著作權宣告:本文著作權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段宣告,且在文章頁面明顯位置給出原文鏈接,
特此宣告:所有評論和私信都會在第一時間回復,也歡迎園子的大大們指正錯誤,共同進步,或者直接私信我
聲援博主:如果您覺得文章對您有幫助,可以點擊文章右下角【推薦】一下,您的鼓勵是作者堅持原創和持續寫作的最大動力!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/423374.html
標籤:其他
上一篇:python基礎
