1. Up the /etc/hosts on all 3 nodes
192.168.0.50 elk1.local
192.168.0.51 elk2.local
192.168.0.52 elk3.local
Note : Minimum 2 nodes should be up to make cluster healthy.
2.Install elasticsearch on all 3 nodes
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
echo '[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md' > /etc/yum.repos.d/elasticsearch.repo
###install elasticsearch
yum -y install elasticsearch
###Enable elasticsearch
systemctl enable elasticsearch
3. Edit /etc/elasticsearch/elasticsearch.yml as per cluster name (eg. elk-cluster)
cluster.name: elk-cluster
node.name: elk1.local
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 192.168.0.50
discovery.seed_hosts: ["elk1.local", "elk2.local", "elk3.local"]
cluster.initial_master_nodes: ["elk1.local", "elk2.local", "elk3.local"]
change the only node.name and network.host for other 2 elasticsearch nodes
4. Restart elasticsearch service on all 3 elasticsearch node
systemctl restart elasticsearch
After restart 1 master node will be elected.
5. Check master node in elasticsearch cluster
curl -X GET "192.168.0.50:9200/_cat/master?v&pretty"
More : https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-master.html
More information about setting up cluster : https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html