Elasticsearch 7.4 Multi Clustering configuration - elasticsearch

I am trying to make an Elasticsearch cluster with two nodes. Most of the documents in Google are about lower version clustering since they talk about discover.zen.ping.unicast.hosts which 7.4 doesn't have.
Two nodes are AWS EC2 instances.
Each Elasticservice is running fine but I don't think they are clustered. ( _cluster/health , _nodes API).
I made changes in /etc/hosts.
elasticsearch.yml for node-1 :
# ---------------------------------- Cluster -----------------------------------
cluster.name: dsm-001
# ------------------------------------ Node ------------------------------------
node.name: node-1
# ----------------------------------- Paths ------------------------------------
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
# ---------------------------------- Network -----------------------------------
#network.host: 192.168.0.1
http.port: 9200
# --------------------------------- Discovery ----------------------------------
discovery.seed_hosts: ["node-1","node-2"]
cluster.initial_master_nodes: ["node-1","node-2"]
elasticsearch.yaml for node-2 :
# ---------------------------------- Cluster -----------------------------------
cluster.name: dsm-001
# ------------------------------------ Node ------------------------------------
node.name: node-2
# ----------------------------------- Paths ------------------------------------
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
# ---------------------------------- Network -----------------------------------
#network.host: 192.168.0.1
http.port: 9200
# --------------------------------- Discovery ----------------------------------
discovery.seed_hosts: ["node-1","node-2"]
cluster.initial_master_nodes: ["node-1","node-2"]

While the cluster.initial_master_nodes property requires names that match actual elasticsearch node names ("node-1" and "node-2"), the discovery.seed_hosts property expects host names or addresses (e.g. "server1", 192.168.1.12") and not Elasticsearch node names. This is what you need to fix first.
But as you run your nodes in AWS, you are expected to install the EC2 Discovery Plugin to help you locating
the seed addresses of your Elasticsearch nodes (see the Elasticsearch Reference Documentation: EC2 Discovery Plugin)
With Elasticsearch 7 the cluster coordination layer has been rewritten, making your cluster much more robust, but also making the first start-up of a node extremely important. The cluster.initial_master_nodes property is only used when starting up a node for the very first time. If you did so, and your node did not join the expected cluster (and most likely created its own cluster), you need to stop your node, delete the data directory (to clear the cluster state) and restart it.

For Additional Help
Finally, I figured it out.
If Daniel's answer doesn't work for you, add the following.
---------------------------Network-----------------------------------
network.host: Your Public DNS (IPv4) // For example, ec2-1-1-1-1.ap-northeast-1.compute.amazonaws.com
----------------------------Discovery------------------------------------
discovery.seed_hosts : [" ip" , "ip" ] // like Daniel said.
discovery.seed_providers: ec2

Related

I have setup the ElasticSearch on my ubuntu but when i try to run sudo systemctl start elasticsearch.service i got an error

Error:
Job for elasticsearch.service failed because the control process exited with error code.
sudo systemctl status elasticsearch.service:
elasticsearch.service - Elasticsearch
Loaded: loaded (/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2022-10-14 02:30:18 PKT; 4min 51s ago
/var/log/elasticsearch/elasticsearch.log:
org.elasticsearch.ElasticsearchSecurityException: invalid configuration for xpack.security.transport.ssl - [xpack.security.transport.ssl.enabled] is >
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:67) ~[elasticsearch-8.4.3.jar:?]
etc/elasticsearch/elasticsearch.yml:
======================== Elasticsearch Configuration =========================
NOTE: Elasticsearch comes with reasonable defaults for most settings.
Before you set out to tweak and tune the configuration, make sure you
understand what are you trying to accomplish and the consequences.
The primary way of configuring a node is via this file. This template lists
the most important settings you may want to configure for a production cluster.
Please consult the documentation for further information on configuration options:
https://www.elastic.co/guide/en/elasticsearch/reference/index.html
---------------------------------- Cluster ----------------------------------
Use a descriptive name for your cluster:
cluster.name: my-application
------------------------------------ Node ------------------------------------
Use a descriptive name for the node:
node.name: node-1
Add custom attributes to the node:
node.attr.rack: r1
----------------------------------- Paths ------------------------------------
Path to directory where to store the data (separate multiple locations by comma):
path.data: /var/lib/elasticsearch
Path to log files:
path.logs: /var/log/elasticsearch
----------------------------------- Memory -----------------------------------
Lock the memory on startup:
bootstrap.memory_lock: true
Make sure that the heap size is set to about half the memory available
on the system and that the owner of the process is allowed to use this
limit.
Elasticsearch performs poorly when the system is swapping the memory.
---------------------------------- Network -----------------------------------
By default Elasticsearch is only accessible on localhost. Set a different
address here to expose this node on the network:
network.host: localhost
By default Elasticsearch listens for HTTP traffic on the first free port it
finds starting at 9200. Set a specific HTTP port here:
http.port: 9200
For more information, consult the network module documentation.
--------------------------------- Discovery ----------------------------------
Pass an initial list of hosts to perform discovery when this node is started:
The default list of hosts is ["127.0.0.1", "[::1]"]
discovery.seed_hosts: ["host1", "host2"]
Bootstrap the cluster using an initial set of master-eligible nodes:
cluster.initial_master_nodes: ["node-1", "node-2"]
For more information, consult the discovery and cluster formation module documentation.
--------------------------------- Readiness ----------------------------------
Enable an unauthenticated TCP readiness endpoint on localhost
readiness.port: 9399
---------------------------------- Various -----------------------------------
Allow wildcard deletion of indices:
action.destructive_requires_name: false

Elastic Search “master_not_discovered_exception” centos

After deleting /var/lib/elasticseach: Corrected here
I had to delete it because I had some error when trying to search from an index and some stackoverflow answer stated that it was preferable to delete data path and restart elasticsearch.
I'm on centos, and Im trying to configure it for laravel scout.
When I try to do anything such as PUT /index or GET /_cluster/health?pretty I get
{
"error": {
"root_cause": [
{
"type": "master_not_discovered_exception",
"reason": null
}
],
"type": "master_not_discovered_exception",
"reason": null
},
"status": 503
}
Here's my elasticsearch.yml
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: myCluster
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: myNode
node.roles: [master]
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /var/lib/elasticsearch
#
# Path to log files:
#
path.logs: /var/log/elasticsearch
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#transport.host: localhost
network.host: 0.0.0.0
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.seed_hosts: ["127.0.0.1", "[::1]"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
cluster log
[2020-11-07T13:03:59,571][WARN ][r.suppressed ] [NODE] path: /products, params: {index=products}
org.elasticsearch.discovery.MasterNotDiscoveredException: null
at org.elasticsearch.action.support.master.TransportMasterNodeAction$AsyncSingleAction$2.onTimeout(TransportMasterNodeAction.java:220) [elasticsearch-7.9.2.jar:7.9.2]
at org.elasticsearch.cluster.ClusterStateObserver$ContextPreservingListener.onTimeout(ClusterStateObserver.java:325) [elasticsearch-7.9.2.jar:7.9.2]
at org.elasticsearch.cluster.ClusterStateObserver$ObserverClusterStateListener.onTimeout(ClusterStateObserver.java:252) [elasticsearch-7.9.2.jar:7.9.2]
at org.elasticsearch.cluster.service.ClusterApplierService$NotifyTimeout.run(ClusterApplierService.java:605) [elasticsearch-7.9.2.jar:7.9.2]
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:678) [elasticsearch-7.9.2.jar:7.9.2]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) [?:?]
at java.lang.Thread.run(Thread.java:832) [?:?]
[2020-11-07T13:04:05,597][WARN ][o.e.c.c.ClusterFormationFailureHelper] [NODE] master not discovered yet, this node has not previously joined a bootstrapped (v7+) cluster, and [cluster.initial_master_nodes] is empty on this node: have discovered [{NODE}{2hEi19WjSn2EsdfsdfYZmmbf158Q}{ZeP6OSGJTa24ggregerghaNOMlYOng}{SERVER_IP}{SERVER_IP:9300}{m}{xpack.installed=true, transform.node=false}]; discovery will continue using [127.0.0.1:9300, [::1]:9300] from hosts providers and [{NODE}{2hazEi19WjSnergza2EYgZmmbfr158Q}{ZeP6OSGJTa24haNOddMlYOng}{SERVER_IP}{SERVER_IP:9300}{m}{xpack.installed=true, transform.node=false}] from last-known cluster state; node term 0, last-accepted version 0 in term 0
I'm fairly new to elastic and for what I'm trying to achieve it's way too complicated.
Since you deleted the data directory, your node never joined a cluster or was bootstrapped before, this is what it is saying in the log line.
You need to set the option cluster.initial_master_nodes so your node will know which nodes are the initial masters.
Uncomment the line for the cluster.initial_master_nodes and add the name of your node.
cluster.initial_master_nodes: ["myNode"]
This will make your node bootstrap itself as the master.
Also, you are setting the option network.host, this will make elasticsearch assumes that you are running into production mode and will force a series of checks, you need to check if you did everything in the important system configurations part of the documentation or your node won't start and give you some exceptions.
If you are accessing your node through localhost, you can comment the network.host option and use it in the development mode.

Elasticsearch: setting up cluster with two nodes

I've set two master nodes in my cluster but it only shows "elastic-master" not "elastic-slave".(second node is not shown).How can I resolve it?
I've already followed Elasticsearch documents but nothing changed!
My host file setting:
sudo nano /etc/hosts
192.168.143.30 elastic-master
192.168.143.23 elastic-slave
My config file:
# ---------------------------------- Cluster ------------------------------
cluster.name: elastic-a
# ------------------------------------ Node -------------------------------
node.name: elastic-master
node.master: true
node.data: true
# ---------------------------------- Network ------------------------------
network.host: 192.168.143.30
http.port: 9200
# --------------------------------- Discovery -----------------------------
discovery.seed_hosts: ["192.168.143.30","192.168.143.23"]
cluster.initial_master_nodes: ["elastic-slave", "elastic-master"]
My config file on second one:
# ---------------------------------- Cluster ------------------------------
cluster.name: elastic-a
# ------------------------------------ Node -------------------------------
node.name: elastic-slave
node.master: true
node.data: true
# ---------------------------------- Network ------------------------------
network.host: 192.168.143.23
http.port: 9200
# --------------------------------- Discovery -----------------------------
discovery.seed_hosts: ["192.168.143.30","192.168.143.23"]
cluster.initial_master_nodes: ["elastic-slave", "elastic-master"]
"First stopped the service (sudo service elasticsearch stop). Delete the data (sudo rm -rf /var/lib/elasticsearch/*) and restart the service (sudo service elasticsearch restart). Now work all !!"
Found answer in here:
Add nodes to make local cluster Elasticsearch [7.8]

how to enable Elasticsearch on LAN

I just installed Elasticsarch 7.5.0 on my ubuntu server. I can get elasticsearch from the localhost and I want to be able to access it from another computer, but this is not working. I tried config from the official site: network.host: 0.0.0.0, network.host: 192.168.1.2, but when I restart elasticseach after changing my config, I get this:
Job for elasticsearch.service failed because the control process exited with error code.
See "systemctl status elasticsearch.service" and "journalctl -xe" for details.
I have also tried network.host: global, but nothing seem to be working. Any Idea what is the issue here?
my elasticsearch.yml file looks like this:
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /var/lib/elasticsearch
#
# Path to log files:
#
path.logs: /var/log/elasticsearch
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#network.host: 0.0.0.0
#network.bind_host: 0.0.0.0
#network.publish_host: 0.0.0.0
#
#
#network.host: 192.168.0.1
#network.host: 10.10.10.16
#network.host: 0.0.0.0
network.host: '_global_'
#
# Set a custom porti for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["127.0.0.1", "0.0.0.0"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
I finally found the issue:
network.host: _enp0s3_
discovery.seed_hosts: 0.0.0.0
after setting these parameters it worked find.

How to set up multi-node Elasticsearch cluster in development mode?

I have an ES cluster (v 5.6.12) up and running in dev mode, config below:
node1.com
cluster.name: elastic-test
node.name: "node-1"
path.data: /path/to/data
path.logs: /path/to/logs
network.host: 127.0.0.1
http.host: 0.0.0.0
discovery.zen.ping.unicast.hosts: ["node1.com", "node2.com"]
node.master: true
I am trying to connect node 2 to the same cluster:
node2.com
cluster.name: elastic-test
node.name: "node-2"
path.data: /path/to/data
path.logs: /path/to/logs
network.host: 127.0.0.1
http.host: 0.0.0.0
discovery.zen.ping.unicast.hosts: ["node1.com", "node2.com"]
node.master: true
I tried to change the network.host to their respective addresses, but this takes them out of dev mode. I also tried setting the bind and publish hosts to make the node discover-able to other nodes:
network.bind_host: 127.0.0.1
network.publish_host: node1.com
But again, this takes the nodes into production.
Is it actually possible to have multiple nodes on different servers communicate within development mode?
Short answer NO. For most use cases running a single node cluster for DEV suffices but there could be scenarios where multi node clusters are required in DEV environment, however it is not possible to currently form a multi node cluster without binding to a non local IP address.
That being said, difference between development mode and production mode with respect to Elasticsearch is just preventing ES cluster from starting if some settings are not configured appropriately. So, as long as you are able to configure the settings described in the below link then you can form a cluster and name it as DEV so users don't misidentify it as a production cluster
https://www.elastic.co/guide/en/elasticsearch/reference/5.6/system-config.html#dev-vs-prod

Resources