For details about Elasticsearch, see ***CentOS install Elasticsearch
To build a cluster, you only need to add some configurations. This article mainly introduces the configurations related to the cluster
Assuming that node number is 3, IP is respectively: 10.20.1.52, 10.20.1.53, 10.20.1.54
A, configuration,
shell> cd /usr/local/ elasticsearch - 5.6.4 / config shell > vim elasticsearch. YmlCopy the code
Edit the following:
#
# ---------------------------------- Cluster -----------------------------------
#
Default: elasticSearch; If only this cluster exists in the current network environment, you do not need to configure this cluster. (A more meaningful name is recommended.)
cluster.name: test
#
# ------------------------------------ Node ------------------------------------
#
Node-1,node-2, node-3
node.name: node-1
# specify whether this node is eligible to be elected as node. Default: true; The es default is that the first machine in the cluster is master, and if this machine fails, the master is reelected
node.master: true
# specifies whether this object stores index data. Default: true
node.data: true
#
# ----------------------------------- Paths ------------------------------------
The "basic configuration" already described in # standalone
path.data: /usr/local/ elasticsearch - 5.6.4 / data path. Logs: / usr /local/ elasticsearch - 5.6.4 / logs#
# ---------------------------------- Network -----------------------------------
The "basic configuration" already described in # standalone
# 3 machine set respectively for their IP: 10.20.1.52, 10.20.1.53, 10.20.1.54Network. The host: 10.20.1.52#
# --------------------------------- Discovery ----------------------------------
# initial list of master nodes in the cluster, if not using the default 9300 port.
# followed by the port number [10.20.1.52 ""," 10.20.1.53:9203 ", "10.20.1.54:9204"]
discovery.zen.ping.unicast.hosts: ["10.20.1.52"."10.20.1.53"."10.20.1.54"]
# Prevent "split brain" (simply split into two separate clusters), usually set to (master_ELIGible_nodes / 2) + 1
(3/2 + 1 = 2
discovery.zen.minimum_master_nodes: 2
Copy the code
Second, the test
Start three nodes to test the cluster
1. Browser input:http://10.20.1.52:9200/_cluster/health?pretty=true, view the cluster status
2. Create an index test
Look at the index list, it should all be empty initially (no indexes created)
GET /_cat/indices? v&prettyCopy the code
Create index Customer on one of the machines (10.20.1.52)
PUT /customer? prettyCopy the code
Other machines (10.20.1.54) look at the index and you can see that the data is “synchronized”
GET /_cat/indices? v&prettyCopy the code