Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Setting Up a Three-Node Elasticsearch Cluster on CentOS 7

Tech 1

Prerequisites

Java Runtime Environment

Install the Java 8 runtime environment:

yum install -y java-1.8.0

Swap Deactivation

Disable swap memory to ensure stability:

# Edit fstab to comment out swap entries
vim /etc/fstab

# Immediately disable all swap partitions
swapoff -a

System Resource Tuning

File Descriptors Increase the open file descriptor limit in /etc/security/limits.conf:

*    soft    nofile    65536
*    hard    nofile    65536

Virtual Memory Areas Adjust the maximum map count in /etc/sysctl.conf:

vm.max_map_count = 655360

Apply the changes:

sysctl -p

Thread Count Set the process thread limit in /etc/security/limits.conf:

*    soft    nproc     65535
*    hard    nproc     65535

Installation and Configuration

Fetch and Extract

Download the Elasticsearch 7.10.0 package and extract it:

wget https://repo.huaweicloud.com/elasticsearch/7.10.0/elasticsearch-7.10.0-linux-x86_64.tar.gz
tar -zxvf elasticsearch-7.10.0-linux-x86_64.tar.gz -C /opt/

Node Configuration

Edit the elasticsearch.yml file located in the config directory. Below is a sample configuration for node-1. Repeat this for the other two nodes, changing node.name and network.host accordingly.

cluster.name: prod-search-cluster
node.name: node-1
node.master: true
node.data: true

path.data: /var/lib/elasticsearch
data
data
path.logs: /var/log/elasticsearch

network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300

http.cors.enabled: true
http.cors.allow-origin: "*"

discovery.zen.ping.unicast.hosts: ["192.168.1.10:9300", "192.168.1.11:9300", "192.168.1.12:9300"]

Service Management

Create a systemd unit file /etc/systemd/system/elasticsearch.service to manage the service:

[Unit]
Description=Elasticsearch Search Engine
After=network.target

[Service]
Type=simple
User=elasticsearch
Group=elasticsearch
LimitNOFILE=65536
LimitMEMLOCK=infinity
ExecStart=/opt/elasticsearch-7.10.0/bin/elasticsearch
Restart=on-failure

[Install]
WantedBy=multi-user.target

Reload the daemon and start the service:

systemctl daemon-reload
systemctl start elasticsearch
systemctl enable elasticsearch

Verification

Check the cluster membership and health by querying the nodes endpoint:

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

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.