Configuring a Self-Managed Elastic Cluster on Linux – Single and multiple nodes
Elasticsearch, renowned for its search engine capabilities, boasts powerful security features for data protection. This comprehensive guide walks you through the process of setting up a Multi-Node ElasticSearch cluster with custom configurations on Linux. Starting from scratch, stack limits, memory map configurations, and Elasticsearch deployment. The guide concludes with verification using CURL.
Elasticsearch, renowned for its power and scalability as a search engine, offers robust security features to safeguard your data. We are set to establish a Multi Node ES cluster with tailored configurations on linux machines. This blog post serves as a step-by-step guide, walking you through the process of configuring an Elastic cluster with everything from scratch using the settings outlined below.
On Linux systems, persistent limits can be set for a particular user by editing the /etc/security/limits.conf
file. To set the maximum number of open files for the elasticsearch
user to 65,535, add the following line to the limits.conf
file:
Open the limits.conf file as root:
sudo vim /etc/security/limits.conf
Add the following line near the bottom:
elasticsearch - nofile 65535
Systemd configurationedit
When using the RPM or Debian packages on systems that use systemd, system limits must be specified via systemd.
The systemd service file (/usr/lib/systemd/system/elasticsearch.service
) contains the limits that are applied by default.
To override them, add a file called /etc/systemd/system/elasticsearch.service.d/override.conf
(alternatively, you may run sudo systemctl edit elasticsearch
which opens the file automatically inside your default editor). Set any changes in this file, such as:
[Service] LimitMEMLOCK=infinity
Once finished, run the following command to reload units:
sudo systemctl daemon-reload
Open the sysctl.conf file as root:
sudo vim /etc/sysctl.conf
Elasticsearch also requires the ability to create many memory-mapped areas. The maximum map count check checks that the kernel allows a process to have at least 262,144 memory-mapped areas and is enforced on Linux only. To pass the maximum map count check, you must configure vm.max_map_count via sysctl to be at least 262144.
Load the new sysctl values:
https://dev.smirnov.app/2024/08/installing-and-configuring-elasticsearch.html
Now We will Configure each node’s elasticsearch.yml file here as per specifications.
Log in to each node and become the elastic user:
- Open the elasticsearch.yml file:
Elasticsearch Configuration File Overview
The supplied YAML file encompasses crucial configurations tailored for a production Elasticsearch cluster. Let’s delve into key sections:
Cluster Configuration
cluster.name: Your_Cluster_Name
Sets a descriptive name for your cluster. All nodes must share the same cluster name to join the same cluster.
Node Configuration
node.name: node-01
Specifies a descriptive name for your node. The default node name is the machine’s hostname upon Elasticsearch startup.
Path Configuration
path.data: /elastic_data_directory/ElasticData
path.logs: /elastic_log_directory/ElasticLogs
Defines data and log directory paths. Your Elastic data and logs will be stored in these paths.
Network Configuration
http.port: 9200
Configures network settings, making Elasticsearch accessible on the specified IP and port. The setting network.host: 0.0.0.0
in the Elasticsearch configuration allows Elasticsearch to bind to all available network interfaces on the server. This means that Elasticsearch will listen for incoming connections on all IP addresses assigned to the server.
Discovery Configuration – Multi Node Cluster
Establishes the discovery process with seed hosts and initial master nodes. For a single-node cluster, use:
cluster.initial_master_nodes
After the cluster forms successfully for the first time, remove the cluster.initial_master_nodes
setting from each node’s configuration. Do not use this setting when restarting a cluster or adding a new node to an existing cluster.
Security Configuration
We put xpack.security.enabled: false to acces elastic without password.
Generate the certificate authority
The command will create elastic-stack-ca.p12 and elastic-certificates.p12 :
ls /usr/share/elasticsearch/elastic-certificates.p12
Copy elastic-certificates.p12 to /etc/elasticsearch/:
cp /usr/share/elasticsearch/elastic-certificates.p12 /etc/elasticsearch/
Give the right permissions to elasticuser on each node:
sudo chown elasticsearch: /etc/elasticsearch/elastic-certificates.p12
On every node in your cluster, copy the elastic-certificates.p12 file to the $ES_PATH_CONF directory.
scp root@xxx.xx.xx.xxx:/etc/elasticsearch/elastic-certificates.p12 /etc/elasticsearch/elastic-certificates.p12
Enables X-Pack Security and configures SSL for transport.
Configuring TLS between nodes is the basic security setup to prevent unauthorised nodes from accessing your cluster.
Refer this documentation to create these certificates and read more about Security configuration: Set up basic security for the Elastic Stack | Elasticsearch Guide [8.11] and security-minimal-setup.html
SSL HTTP Configuration
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.verification_mode: certificate
xpack.security.http.ssl.keystore.path: certificate.pfx
When you enable TLS on the HTTP layer it provides an additional layer of security to ensure that all communications to and from your cluster are encrypted.
For more information on creating certificates, refer to the official documentation.
Set up basic security for the Elastic Stack plus secured HTTPS traffic | Elasticsearch Guide [8.11]
Now we will configure the heap for each node per instructions.
Log in to each master node:
Open the jvm.options file:
vim /$ES_HOME/elasticsearch/config/jvm.options
Change the following lines:
-Xms1g
-Xmx1g
Log in to each data node:
Open the jvm.options file:
vim /$ES_HOME/elasticsearch/config/jvm.options
Change the following lines:
-Xms30g
-Xmx30g
Note : By default, Elasticsearch automatically sets the JVM heap size based on a node’s roles and total memory. Using the default sizing is recommended for most production environments.
To override the default heap size, set the minimum and maximum heap size settings, Xms and Xmx. The minimum and maximum values must be the same.
The heap size should be based on the available RAM:
Set Xms and Xmx to no more than 50% of your total memory. Elasticsearch requires memory for purposes other than the JVM heap. For example, Elasticsearch uses off-heap buffers for efficient network communication and relies on the operating system’s filesystem cache for efficient access to files. The JVM itself also requires some memory. It’s normal for Elasticsearch to use more memory than the limit configured with the Xmx setting.
Source:
- https://www.elastic.co/guide/en/elasticsearch/reference/7.17/settings.html
- https://www.elastic.co/guide/en/elasticsearch/reference/current/add-elasticsearch-nodes.html
Comments
Post a Comment