搜尋
首頁php教程php手册如何理解Elasticsearch單機雙節點集群部署

   這篇文章,我們還是做些基礎的學習,在Elasticsearch如何進行CRUD。

Elasticsearch單機雙節點叢集部署

环境:CentOS 7.2       JDK 1.8.0_74


#一、安裝第一個ElasticSearch(主節點)

#1、創建es用戶,啟動es不能使用root用戶

useradd es
passwd es

root用戶進入/home/es目錄下

2、取得ElasticSearch安裝套件

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

3、解壓縮、改名(方便叢集時區別另一個ES)

tar xf elasticsearch-6.1.2.tar.gzmv elasticsearch-6.1.2.tar.gz elasticsearch-node2

4、修改設定檔

vi elasticsearch-node2/config/elasticsearch.yml

修改內容如下:

cluster.name: my-application      
  各节点此名称必须一致node.name: node-2           
        节点名称,不能与其他节点相同        
         network.host: ***.***.***.***   
        自己的服务器IPhttp.port: ****         
           访问端口transport.tcp.port: ****  
    集群各节点间的通讯端口 discovery.zen.ping.unicast.hosts: ["主节点IP:通讯端口","辅节点IP:通讯端口"]

檔案最後追加以下內容,以便連接head顯示健康值(注意每行程式碼前面不要有空格)

http.cors.enabled: truehttp.cors.allow-origin: "*"

5、啟動

sh elasticsearch-node2/bin/elasticsearch
[2018-01-24T15:36:41,990][INFO ][o.e.n.Node               ] [KMyyO-3] started
[2018-01-24T15:36:41,997][INFO ][o.e.g.GatewayService     ] [KMyyO-3] recovered [0] indices into cluster_state

啟動成功,瀏覽器中輸入IP:存取連接埠

網頁顯示以下內容,說明部署成功

{
  "name" : "node-2",
  "cluster_name" : "my-application",
  "cluster_uuid" : "j2aJ7CsRSuSo0G8Bgky2Ww",    
  "version" : {
    "number" : "6.1.2",
    "build_hash" : "5b1fea5",
    "build_date" : "2018-01-10T02:35:59.208Z",
    "build_snapshot" : false,
    "lucene_version" : "7.1.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"}

6、報錯及其處理
【類型一】

Caused by: java.lang.RuntimeException: can not run elasticsearch as root

該問題是因為執行es不能使用root用戶,因此要切換es用戶再次啟動

chown -R es:es elasticsearch-node2/su - es
sh elasticsearch-node2/bin/elasticsearch

【類型二】

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

解決方法,換回root用戶,修改設定檔

vi /etc/security/limits.conf#在最后面追加下面内容es hard nofile 65536es soft nofile 65536

【類型三】

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

解決方法,換回root用戶,修改設定檔

vi /etc/sysctl.conf 
#在最后面追加下面内容vm.max_map_count=655360#执行命令:sysctl -p

#二、安裝第二個ElasticSearch(子節點)
安裝方法與第一個一致,注意修改設定檔
root用戶進入/home/es目錄下

1、解壓縮、改名

tar xf elasticsearch-6.1.2.tar.gzmv elasticsearch-6.1.2.tar.gz elasticsearch-node3

2、修改設定檔

vi elasticsearch-node3/config/elasticsearch.yml

修改內容如下:

cluster.name: my-application      
  各节点此名称必须一致node.name: node-3      
               节点名称,不能与其他节点相同network.host: ***.***.***.***   
                   自己的服务器IPhttp.port: ****          
                              访问端口(注意不要与第一个端口重复)                              transport.tcp.port: ****            集群各节点间的通讯端口(注意不要与第一个端口重复)discovery.zen.ping.unicast.hosts: ["主节点IP:通讯端口","辅节点IP:通讯端口"]

檔案最後同樣追加下面程式碼

http.cors.enabled: truehttp.cors.allow-origin: "*"

3.啟動

sh elasticsearch-node3/bin/elasticsearch

瀏覽器,瀏覽器中輸入  IP:存取連接埠
網頁顯示以下內容,說明第二個部署成功

{
  "name" : "node-3",
  "cluster_name" : "my-application",
  "cluster_uuid" : "j2aJ7CsRSuSo0G8Bgky2Ww",
  "version" : {
    "number" : "6.1.2",
    "build_hash" : "5b1fea5",
    "build_date" : "2018-01-10T02:35:59.208Z",
    "build_snapshot" : false,
    "lucene_version" : "7.1.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"}

三、安裝Elasticsearch-head外掛程式
1、安裝head外掛程式之前需要安裝node.js

curl -sL https://rpm.nodesource.com/setup_8.x | bash -
yum install -y nodejs

安裝完成後執行指令查看node與npm版本

[root@host]# node -vv8.12.0[root@host]# npm -v6.4.1

2、從git取得head外掛

wget https://github.com/mobz/elasticsearch-head/archive/master.zip

3、解壓縮安裝套件(可以改名,方便操作)

unzip master.zip
mv elasticsearch-head-master/ head

4、修改設定檔

vi head/Gruntfile.js

更改head連接埠號碼

connect: {          server: {
                   options: {
                              port: ****,    改为head访问端口
                              base: '.',
                              keepalive: true                             }
                    }
          }
vi head/_site/app.js

更改head連結位址

init: function(parent) {
                        this._super();                        this.prefs = services.Preferences.instance();                        this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://主节点IP:访问端口";

5、啟動head

nohup npm run start > ../head.log 2>&1 &

6.瀏覽器登入head
如何理解Elasticsearch單機雙節點集群部署

URL輸入伺服器IP:head訪問連接埠
連結位址輸如主節點的存取位址
7、安裝head常見錯誤
【類型一】啟動成功,但網頁不能存取
解決方法
關閉伺服器防火牆

service iptables stop

【類型二】叢集健康值未連線
在elasticsearch.yml裡追加下列程式碼(注意程式碼前面不要有空格)

http.cors.enabled: truehttp.cors.allow-origin: "*"

問:為什麼es節點用node2、node3?
回答:因為之前用node1搭建了一套未集群的ES,所以後面集群就用2和3了

相關推薦:

Yii2-elasticsearch 怎麼用啊?

Elasticsearch中的CRUD


#

以上是如何理解Elasticsearch單機雙節點集群部署的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。