Home > php教程 > php手册 > How to understand Elasticsearch single-machine two-node cluster deployment

How to understand Elasticsearch single-machine two-node cluster deployment

坏嘻嘻
Release: 2018-09-14 16:03:42
Original
12350 people have browsed it

In this article, we still do some basic learning on how to perform CRUD in Elasticsearch.

Elasticsearch stand-alone dual-node cluster deployment

环境:CentOS 7.2       JDK 1.8.0_74
Copy after login


##1. Install the first ElasticSearch (master node)

1. Create an es user. You cannot use the root user to start es.

useradd es
passwd es
Copy after login

The 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.gz
Copy after login

3. 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-node2
Copy after login

4. Modify the configuration file

vi elasticsearch-node2/config/elasticsearch.yml
Copy after login

The modification content is as follows:

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

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: "*"
Copy after login
Copy after login
Copy after login

5. Startup

sh elasticsearch-node2/bin/elasticsearch
Copy after login
[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
Copy after login

Start 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"}
Copy after login

6, error reporting and its handling

[Type 1]

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

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
Copy after login

[Type 2]

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

Solution, change back to root user and modify the configuration file

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

[Type 3]

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

Solution, change back to the root user and modify the configuration file

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

2. 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
Copy after login

2. Modify the configuration file

vi elasticsearch-node3/config/elasticsearch.yml
Copy after login

Modify The content is as follows:

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

Also append the following code at the end of the file

http.cors.enabled: truehttp.cors.allow-origin: "*"
Copy after login
Copy after login
Copy after login

3. Start the

sh elasticsearch-node3/bin/elasticsearch
Copy after login

browser and enter

IP:access port

in 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"}
Copy after login

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
Copy after login

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
Copy after login

2. Get the head plug-in from git

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

3. Unzip the installation package (you can rename it for easy operation)

unzip master.zip
mv elasticsearch-head-master/ head
Copy after login

4. Modify the configuration file

vi head/Gruntfile.js
Copy after login

Change the head port number

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

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://主节点IP:访问端口";
Copy after login

5. Start the head

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

6. Browser login head


How to understand Elasticsearch single-machine two-node cluster deploymentURL input server IP: head access port

Link address input such as the access address of the master node

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
Copy after login

[Type 2]The cluster health value is not connected

Append 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: "*"
Copy after login
Copy after login
Copy after login

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:

How to use Yii2-elasticsearch ah?

CRUD in Elasticsearch

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!

Related labels:
es
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template