How to understand Elasticsearch single-machine two-node cluster deployment
Sep 14, 2018 pm 04:03 PMIn this article, we still do some basic learning on how to perform CRUD in Elasticsearch.
Elasticsearch stand-alone dual-node cluster deployment
環(huán)境:CentOS?7.2???????JDK?1.8.0_74
##1. Install the first ElasticSearch (master node)
1. Create an es user. You cannot use the root user to start es.useradd es passwd esThe root user enters the /home/es directory. 2. Obtain the ElasticSearch installation package.
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.2.tar.gz3. Unzip and rename (to facilitate the differentiation of another ES when clustering)
tar xf elasticsearch-6.1.2.tar.gzmv elasticsearch-6.1.2.tar.gz elasticsearch-node24. Modify the configuration file
vi elasticsearch-node2/config/elasticsearch.ymlThe modification content is as follows:
cluster.name: my-application 各節(jié)點(diǎn)此名稱必須一致node.name: node-2 節(jié)點(diǎn)名稱,不能與其他節(jié)點(diǎn)相同 network.host: ***.***.***.*** 自己的服務(wù)器IPhttp.port: **** 訪問端口transport.tcp.port: **** 集群各節(jié)點(diǎn)間的通訊端口 discovery.zen.ping.unicast.hosts: ["主節(jié)點(diǎn)IP:通訊端口","輔節(jié)點(diǎn)IP:通訊端口"]Add the following content to the end of the file , so that the connection head displays the health value (note that there should be no spaces before each line of code)
http.cors.enabled: truehttp.cors.allow-origin: "*"5. Startup
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_stateStart successfully, enter
IP:access port## in the browser #The webpage displays the following content, indicating that the deployment is successful
{ "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, error reporting and its handling
[Type 1]Caused by: java.lang.RuntimeException: can not run elasticsearch as root
This problem is because running es cannot be used root user, so switch to es user and start again
chown -R es:es elasticsearch-node2/su - es sh elasticsearch-node2/bin/elasticsearch
[Type 2]
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
Solution, change back to root user and modify the configuration file
vi /etc/security/limits.conf#在最后面追加下面內(nèi)容es hard nofile 65536es soft nofile 65536
[Type 3]
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
Solution, change back to the root user and modify the configuration file
vi /etc/sysctl.conf #在最后面追加下面內(nèi)容vm.max_map_count=655360#執(zhí)行命令:sysctl -p2. Install the second ElasticSearch (secondary node)
The installation method is the same as the first The two are consistent, pay attention to modifying the configuration fileroot user enters the /home/es directory
1. Unzip and change the name
tar xf elasticsearch-6.1.2.tar.gzmv elasticsearch-6.1.2.tar.gz elasticsearch-node3
2. Modify the configuration file
vi elasticsearch-node3/config/elasticsearch.yml
Modify The content is as follows:
cluster.name: my-application 各節(jié)點(diǎn)此名稱必須一致node.name: node-3 節(jié)點(diǎn)名稱,不能與其他節(jié)點(diǎn)相同network.host: ***.***.***.*** 自己的服務(wù)器IPhttp.port: **** 訪問端口(注意不要與第一個(gè)端口重復(fù)) transport.tcp.port: **** 集群各節(jié)點(diǎn)間的通訊端口(注意不要與第一個(gè)端口重復(fù))discovery.zen.ping.unicast.hosts: ["主節(jié)點(diǎn)IP:通訊端口","輔節(jié)點(diǎn)IP:通訊端口"]
Also append the following code at the end of the file
http.cors.enabled: truehttp.cors.allow-origin: "*"
3. Start the
sh elasticsearch-node3/bin/elasticsearch
browser and enter
IP:access portin the browser The webpage displays the following content, indicating that the second deployment is successful
{ "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"}
3. Install the Elasticsearch-head plug-in
1. You need to install node.js before installing the head plug-in
curl -sL https://rpm.nodesource.com/setup_8.x | bash - yum install -y nodejs
After the installation is complete, execute the command to view the node and npm versions
[root@host]# node -vv8.12.0[root@host]# npm -v6.4.1
2. Get the head plug-in from git
wget https://github.com/mobz/elasticsearch-head/archive/master.zip
3. Unzip the installation package (you can rename it for easy operation)
unzip master.zip mv elasticsearch-head-master/ head
4. Modify the configuration file
vi head/Gruntfile.js
Change the head port number
connect: { server: { options: { port: ****, 改為head訪問端口 base: '.', keepalive: true } } }
vi head/_site/app.js
Change the head link address
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:訪問端口";
5. Start the head
nohup npm run start > ../head.log 2>&1 &
6. Browser login head
URL input server IP: head access port
7. Common errors in installing head
[Type 1] Started successfully, but the webpage cannot be accessed
Solution
Turn off the server firewall
service iptables stop
[Type 2]The cluster health value is not connectedAppend the following code to elasticsearch.yml ( Note that there should be no spaces in front of the code)
http.cors.enabled: truehttp.cors.allow-origin: "*"
Q: Why do es nodes use node2 and node3? Answer: Because we used node1 to build a set of unclustered ES before, we used 2 and 3 for the subsequent clusters
Related recommendations:
The above is the detailed content of How to understand Elasticsearch single-machine two-node cluster deployment. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
