Elasticsearch Cluster Master-Data Node on CentOS7
1 min read

Elasticsearch Cluster Master-Data Node on CentOS7

### การทำ cluster ต้องมี 2 เครื่องขึ้นไปในการทำโดยถ้าแยก data-node ต้องมี master 3 เครื่องขึ้นไป ถ้ามี 3 master สามารถ down ได้ 1 เครื่อง โดยที่ระบบยังทำงานปรกติ

1) Import Elasticsearch PGP Key

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

2) Add Repo Elasticsearch

โดยเข้าไปที่ /etc/yum.repos.d/ สร้างไฟล์ไว้ในนี้ชื่อ elasticsearch.repo แล้วใส่คำสั่งต่อไปนี้ไว้ในไฟล์

[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/oss-7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

3) Install elasticsearch

yum install elasticsearch-oss

3) Config Elasticsearch cluster master node

ไปที่ไฟล์ /etc/elasticsearch/elasticsearch.yml แล้วเพิ่มคำสั่งต่อไปนี้ไว้ที่ท้ายไฟล์

** cluster.initial_master_nodes ให้ใช้วิธี

Config Master Node

***cluster.name ต้องเหมือนกันทุกโหนด***

cluster.name: ใส่ชื่อ cluster ที่จะตั้งหรือใส่ชื่อ app
node.name: ชื่อโหนด
node.data: false
node.master: true
network.host: ip-เครื่อง
discovery.seed_hosts: ["ip-master-1","ip-master-2","ip-master-3"]
cluster.initial_master_nodes: ["ip-master-1","ip-master-2","ip-master-3"]

Config Data Node

cluster.name: ใส่ชื่อ cluster ที่จะตั้งหรือใส่ชื่อ app
node.name: ชื่อโหนด
node.data: true
node.master: false
network.host: ip-เครื่อง
discovery.seed_hosts: ["ip-master-1","ip-master-2","ip-master-3"]
cluster.initial_master_nodes: ["ip-master-1","ip-master-2","ip-master-3"]

จากนั้นสั่งรีสตาร์ททีละเครื่อง แล้วเช็คสถานะ cluster ได้จาก command ต่อไปนี้

curl -XGET http://ip:9200/_cluster/health?pretty
curl -XGET http://ip:9200/_cat/nodes?v