2. Configuration - madhusudhankonda/elasticsearch-next-steps GitHub Wiki

Configuration

Elasticsearch just works out of the box. It follows a design paradigm called Convention over Configuration to work with defaults. We can tweak the configuration according to our needs and indeed you are expected to change them especially if you are working in production environments

Elasticsearch directory structure

There are few directories that would require our attention:

Directory Details
<INSTALL_DIR>/config Configuration directory
<INSTALL_DIR>/bin Executable directory
<INSTALL_DIR>/logs Logs directory
<INSTALL_DIR>/data Data store directory

Elasticsearch Configuration

Going through the configuration of the servers will be helpful. Go to <INSTALL_DIR>/config and open up elasticsearch.yml file using your favourite editor. The elasticsearch.yml file dictates the configuration of the server. As you may find, most of the properties are commented out, meaning the server is set with defaults. Let's go over bunch of properties which are important:

Property Notes
cluster.name Name of your cluster. By default, this value is elasticsearch
node.name An appropriate name given to your node. For eg: london-dev1
path.data Location of your data directory. By default it uses <INSTALL_DIR/data>
path.logs Location of your logs directory. By default it uses <INSTALL_DIR/logs>
http.port The port exposed by the Elasticsearch server. Default is 9200
network.host The network IP address of the server. Defaults to your localhost IP address

Kibana Configuration

The main config file for the Kibana server is located at <KIBANA_INSTALL_DIR>/config directory. The file is kibana.yml file. Few important properties worth noting are:

Property Notes
server.host The server address. By default it's localhost
server.port The server port. Default value is 5601
server.name Kiban server's name
elasticsearch.hosts The list of elasticsearch servers that Kibana connects to. For example: ["https://london-es.chocolateminds.com", "https://nyc-es.chocolateminds.com"]. Default is ["http://localhost:9200"]

Using ES_PATH_CONF

Create a node_conf directory, with all the relevant setting files (elasticsearch.yml, jvm options, log4j settings). On your installation directory, specify the path to this directory using the ES_PATH_CONF when executing the binary. Elasticsearch will pick up the configuration from this directory and run the node.

ES_PATH_CONF=node2_conf ./elasticsearch

where node2_config if your configuration settings directory for node2

Starting a Second Node

If you wish to start a second node on your machine with the same binary, you have two options:

  • Set the path.data and path.logs to second node directory paths respectively
  • Add a node configuration in a separate directory and run using ES_PATH_CONF variable

Running a second node on the same machine is not encouraged

Provide those paths as command-line arguments to the script as shown below and execute the command:

  • Windows OS: elasticsearch -Epath.data=c:\dev\temp\data -Epath.logs=c:\dev\temp\logs

  • Mac OS: ./elasticsearch -Epath.data=Users/mkonda/DEV/PLATFORM/elasticsearch-7.9.2/data2 -Epath.logs=Users/mkonda/DEV/PLATFORM/elasticsearch-7.9.2/logs2

This will start the additional node in the server. Let's issue the same cluster health command once again:

{
  "cluster_name" : "elasticsearch",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 2,
  "number_of_data_nodes" : 2,
  "active_primary_shards" : 6,
  "active_shards" : 12,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}

As the second node was started and joined the existing cluster named elasticsearch, the status of the cluster is now green