A, requirements,

Recently I have been looking at ES related knowledge. Here I will briefly record the setup steps of ES cluster. Because the local machine is limited, here we simulate a cluster of three nodes on the same machine.

2. Preconditions

1. ES cannot be started with root, so you need to create a user.

2. The same data and log directories cannot be used between local ES nodes.

3. Split brain between clusters is maintained by the clusters themselves.

Third, the construction steps

1. Download ES

# download wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.12.0-linux-x86_64.tar.gz # extract tar ZXVF. - C) make a copy of cp-r es01/ es02 cp-r es01/ es03

2, create,esThe user also authorizes the ES directory

Chown-r es es01 chown-r es es02 chown-r es es02 chown-r es es02 chown-r es es02 chown-r es es02 chown-r es es02 Mkdir data &&mkdir log CD data mkdir es01 mkdir es02 mkdir es03 CD log mkdir es01 mkdir es03 es02 mkdir es03

⚠️ Since starting ES with root will report an error, you need to create a new user here and then start ES with the new user.

3. Modify the ES configuration file

The configuration file attribute Node 01 Node. Node 03 explain
Es0 [1, 2, 3] / config / < br / > elasticsearch. Yml es01 es02 es03 ES01, ES02, ES03 represent three directories on the same machine
cluster.name es-cluster es-cluster es-cluster The name of the cluster. The names of the clusters that make up the cluster must be consistent.
node.name es01 es01 es01 Node name. The name of each node in the cluster must be unique.
path.data /home/es/<br/>es/data/es01 /home/es/<br/>es/data/es02 /home/es/<br/>es/data/es03 The data directory
path.logs /home/es/<br/>es/log/es01 /home/es/<br/>es/log/es02 /home/es/<br/>es/log/es03 Log directory
network.host localhost localhost localhost Listening address, can write local IP address, through which can access ES
http.port 9200 9201 9202 Listen on port
transport.port 9205 9206 9207 Communication interfaces between clusters, such as cluster elections
discovery.<br/>seed_hosts: [“localhost:9095”, “localhost:9096”, “localhost:9097”] [“localhost:9095”, “localhost:9096”, “localhost:9097”] [“localhost:9095”, “localhost:9096”, “localhost:9097”] The list of addresses that qualify as the primary node
cluster.<br/>initial_master_nodes [“es01”, “es02”, “es03”] [“es01”, “es02”, “es03”] [“es01”, “es02”, “es03”] Initial list of candidate master nodes. Must be the same value as Node. name.
node.master true true true true: Indicates that it can be elected as a master node.
node.data true true true true:Indicates that data can be stored.
http.cors.enabled true true true true:Indicates that cross domains are allowed.
http.cors.allow-origin * * * Represents support for all domains
Es0 [1, 2, 3] / config /. < br / > JVM options
-Xms512m -Xms512m -Xms512m Depending on your circumstances, do not exceed half of the native physical memory, and do not exceed a maximum of 30GB
-Xmx512m -Xmx512m -Xmx512m .

Important attributes:

  1. cluster.initial_master_nodes

    Link: https://www.elastic.co/guide/en/elasticsearch/reference/7.12/modules-discovery-bootstrap-cluster.html

Link: https://www.elastic.co/guide/en/elasticsearch/reference/7.12/important-settings.html#initial_master_nodes

4, A complete configuration for elasticsearch.yml under the ES01 directory

cluster.name: es-cluster
node.name: es01
path.data: /home/es/es/data/es01
path.logs: /home/es/es/log/es01
network.host: localhost
http.port: 9200
transport.port: 9205
discovery.seed_hosts: ["localhost:9205", "localhost:9206", "localhost:9207"]
cluster.initial_master_nodes: ["es01", "es02", "es03"]
node.master: true
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"

5. Start the ES cluster

#! / bin/bash # - d background start - p specified pid stored in the file/home/es/es/es01 / pid01 / home/es/es/es01 / bin/elasticsearch - d - p pid01 /home/es/es/es02/bin/elasticsearch -d -p pid02 /home/es/es/es03/bin/elasticsearch -d -p pid03

6. Check if the cluster is started

curl http://localhost:9202/_cat/nodes? v

curl http://localhost:9202/_cat/health? v

Four, reference links

1, https://www.elastic.co/cn/downloads/elasticsearch.

2, https://www.elastic.co/guide/en/elasticsearch/reference/current/important-settings.html#discovery-settings

3, https://www.elastic.co/guide/en/elasticsearch/reference/7.12/modules-discovery-bootstrap-cluster.html.

4, https://www.elastic.co/guide/en/elasticsearch/reference/7.12/important-settings.html#initial_master_nodes

5, https://www.elastic.co/guide/en/elasticsearch/reference/7.12/modules-discovery-settings.html

6, https://www.elastic.co/guide/en/elasticsearch/reference/7.12/jvm-options.html