A, requirements,

Recently in the es related knowledge, here is a simple record of the building steps of ES cluster. Because local machines are limited, here is a simulation of building a cluster of three nodes on the same machine.

Second, preconditions

Es cannot be started as user root, so you need to create a user.

2. Local es nodes cannot use the same data and log directories.

3. The split brain between clusters can be maintained by the cluster itself.

3. Construction steps

1. Download ES

# downloadWget HTTP: / / https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.12.0-linux-x86_64.tar.gz# decompressionTar - ZXVF elasticsearch 7.12.0 - Linux - x86_64. Tar. Gz# renameThe mv elasticsearch - 7.12.0 es01Make 2 copies
cp -r es01/ es02
cp -r es01/ es03
Copy the code

2, create,esThe user also authorizes the ES directory

Create es user
useradd es
Set es user password
passwd es
Change the owner of the es01, ES02, and ES03 directories downloaded in the previous step to the newly created ES user
chown -R es es01
chown -R es es02
chown -R es es03
Create data directory and log directory
mkdir data && mkdir log
cd data 
mkdir es01
mkdir es02
mkdir es03
cd log
mkdir es01
mkdir es02
mkdir es03
Copy the code

⚠️ You need to create a new user and start es with the new user because an error occurs when es is started as user root.

3. Modify the ES configuration file

The configuration file attribute Node 01 Node. Node 03 explain
Es0 / config / [1, 2, 3]

elasticsearch.yml
es01 es02 es03 Es01, ES02, and ES03 indicate three directories on the same machine
cluster.name es-cluster es-cluster es-cluster The cluster name must be the same as the cluster name.
node.name es01 es01 es01 Node name. Each node in the cluster must have a unique name.
path.data /home/es/

es/data/es01
/home/es/

es/data/es02
/home/es/

es/data/es03
The data directory
path.logs /home/es/

es/log/es01
/home/es/

es/log/es02
/home/es/

es/log/es03
Log directory
network.host localhost localhost localhost Listen to address, can write local IP, through this address 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.

seed_hosts:
[“localhost:9095”, “localhost:9096”, “localhost:9097”] [“localhost:9095”, “localhost:9096”, “localhost:9097”] [“localhost:9095”, “localhost:9096”, “localhost:9097”] A list of addresses that qualify as master nodes
cluster.

initial_master_nodes
[“es01”, “es02”, “es03”] [“es01”, “es02”, “es03”] [“es01”, “es02”, “es03”] Initial list of candidate master nodes. The value must be the same as node.name.
node.master true true true true: indicates that the node can be elected as the master node.
node.data true true true true:Indicates that data can be stored.
http.cors.enabled true true true true:Indicates that cross-domain is allowed.
http.cors.allow-origin * * * All domain names are supported
Es0 / config / [1, 2, 3]

jvm.options
-Xms512m -Xms512m -Xms512m Set to your own situation, do not exceed half of the native physical memory, maximum 30GB
-Xmx512m -Xmx512m -Xmx512m .

Important attributes:

  1. cluster.initial_master_nodes

    Link: www.elastic.co/guide/en/el…

Link: www.elastic.co/guide/en/el…

4, es01 directory elasticSearch. yml complete configuration

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: "*"
Copy the code

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
Copy the code

6. Check whether the cluster is started

curl http://localhost:9202/_cat/nodes? vCopy the code

curl http://localhost:9202/_cat/health? vCopy the code

4. Reference links

1, www.elastic.co/cn/download…

2, www.elastic.co/guide/en/el…

3, www.elastic.co/guide/en/el…

4, www.elastic.co/guide/en/el…

5, www.elastic.co/guide/en/el…

6, www.elastic.co/guide/en/el…