? ?這篇文章,我們還是做些基礎(chǔ)的學(xué)習(xí),在Elasticsearch如何進(jìn)行CRUD。
Elasticsearch單機(jī)雙節(jié)點(diǎn)集群部署
環(huán)境:CentOS?7.2???????JDK?1.8.0_74
一、安裝第一個(gè)ElasticSearch(主節(jié)點(diǎn))
1、創(chuàng)建es用戶,啟動(dòng)es不能使用root用戶
useradd es passwd es
root用戶進(jìn)入/home/es目錄下
2、獲取ElasticSearch安裝包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.2.tar.gz
3、解壓、改名(方便集群時(shí)區(qū)別另一個(gè)ES)
tar xf elasticsearch-6.1.2.tar.gzmv elasticsearch-6.1.2.tar.gz elasticsearch-node2
4、修改配置文件
vi elasticsearch-node2/config/elasticsearch.yml
修改內(nèi)容如下:
cluster.name: my-application 各節(jié)點(diǎn)此名稱必須一致node.name: node-2 節(jié)點(diǎn)名稱,不能與其他節(jié)點(diǎn)相同 network.host: ***.***.***.*** 自己的服務(wù)器IPhttp.port: **** 訪問(wèn)端口transport.tcp.port: **** 集群各節(jié)點(diǎn)間的通訊端口 discovery.zen.ping.unicast.hosts: ["主節(jié)點(diǎn)IP:通訊端口","輔節(jié)點(diǎn)IP:通訊端口"]
文件最后追加以下內(nèi)容,以便連接head顯示健康值(注意每行代碼前面不要有空格)
http.cors.enabled: truehttp.cors.allow-origin: "*"
5、啟動(dòng)
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
啟動(dòng)成功,瀏覽器中輸入 IP:訪問(wèn)端口
網(wǎng)頁(yè)顯示以下內(nèi)容,說(shuō)明部署成功
{ "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、報(bào)錯(cuò)及其處理
【類型一】
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
該問(wèn)題是因?yàn)檫\(yùn)行es不能使用root用戶,因此要切換es用戶再次啟動(dòng)
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#在最后面追加下面內(nèi)容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 #在最后面追加下面內(nèi)容vm.max_map_count=655360#執(zhí)行命令:sysctl -p
二、安裝第二個(gè)ElasticSearch(輔節(jié)點(diǎn))
安裝方法與第一個(gè)一致,注意修改配置文件
root用戶進(jìn)入/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
修改內(nèi)容如下:
cluster.name: my-application 各節(jié)點(diǎn)此名稱必須一致node.name: node-3 節(jié)點(diǎn)名稱,不能與其他節(jié)點(diǎn)相同network.host: ***.***.***.*** 自己的服務(wù)器IPhttp.port: **** 訪問(wèn)端口(注意不要與第一個(gè)端口重復(fù)) transport.tcp.port: **** 集群各節(jié)點(diǎn)間的通訊端口(注意不要與第一個(gè)端口重復(fù))discovery.zen.ping.unicast.hosts: ["主節(jié)點(diǎn)IP:通訊端口","輔節(jié)點(diǎn)IP:通訊端口"]
文件最后同樣追加下面代碼
http.cors.enabled: truehttp.cors.allow-origin: "*"
3.啟動(dòng)
sh elasticsearch-node3/bin/elasticsearch
瀏覽器,瀏覽器中輸入 IP:訪問(wèn)端口
網(wǎng)頁(yè)顯示以下內(nèi)容,說(shuō)明第二個(gè)部署成功
{ "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
安裝完成后執(zhí)行命令查看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端口號(hào)
connect: { server: { options: { port: ****, 改為head訪問(wèn)端口 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://主節(jié)點(diǎn)IP:訪問(wèn)端口";
5、啟動(dòng)head
nohup npm run start > ../head.log 2>&1 &
6、瀏覽器登錄head
URL輸入服務(wù)器IP:head訪問(wèn)端口
鏈接地址輸如主節(jié)點(diǎn)的訪問(wèn)地址
7、安裝head常見(jiàn)錯(cuò)誤
【類型一】啟動(dòng)成功,但是網(wǎng)頁(yè)不能訪問(wèn)
解決方法
關(guān)閉服務(wù)器防火墻
service iptables stop
【類型二】集群健康值未連接
在elasticsearch.yml里追加下列代碼(注意代碼前面不要有空格)
http.cors.enabled: truehttp.cors.allow-origin: "*"
問(wèn):為什么es節(jié)點(diǎn)用node2、node3?
答:因?yàn)橹坝胣ode1搭建了一套未集群的ES,所以后面集群就用2和3了
相關(guān)推薦:
以上是如何理解Elasticsearch單機(jī)雙節(jié)點(diǎn)集群部署的詳細(xì)內(nèi)容。更多信息請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

熱AI工具

Undress AI Tool
免費(fèi)脫衣服圖片

Undresser.AI Undress
人工智能驅(qū)動(dòng)的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover
用于從照片中去除衣服的在線人工智能工具。

Clothoff.io
AI脫衣機(jī)

Video Face Swap
使用我們完全免費(fèi)的人工智能換臉工具輕松在任何視頻中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費(fèi)的代碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
功能強(qiáng)大的PHP集成開發(fā)環(huán)境

Dreamweaver CS6
視覺(jué)化網(wǎng)頁(yè)開發(fā)工具

SublimeText3 Mac版
神級(jí)代碼編輯軟件(SublimeText3)