How to Install Multiple Elasticssearch Nodes on Single Server

April 12, 2017 | By
| Reply More

Elasticsearch is an open-source, broadly-distributable, readily-scalable, enterprise-grade search engine which is accessible through an extensive and elaborate API. It can power extremely fast searches that support your data discovery applications and can be used for a lot of different use cases like "classical" full-text search, analytics store, autocomplete, spelling checker, alerting engine, and as a general purpose document store. Analytical workloads tend to count things and summarize your lots of data that might even be Big Data. You can use this for fuzzy searching which is one that is lenient toward spelling errors. It is always important to test changes and improvements to your searches with realistic amounts of data before shipping them to production as Fuzzy searches are CPU-intensive, so should be added with care, and probably not to every field. Elasticsearch also helps in auto completion and instant search. Searching while the user types come in many forms like it can be simple suggestions of e.g. existing tags, trying to predict a search based on search history, or just doing a completely new search for every throttled keystroke. There are a lot of different features in Elasticsearch to assist building these features, such as match_phrase_prefix, prefix queries, indexing grams, and a family of different suggesters.

This article is about installing multiple Elasticsearch nodes on a single CentOS 7 server.

But you may use the similar steps to be executed on your other Linux distributions.

Prerequisites

In order to accomplish this task of installing and configuring more than one Elasticsearch nodes on a single server, you just need to access your server using root user credentials may be it's CentOS 6 or CentOS 7, whatever server's you like to use for your environment. Let's connect to your server and create a non-root general user first.

#ssh root@server_ip

1) Adding New User

After login using root user, use below commands to create a new general purpose user to be used during the installation.

# adduser elasticsearch
Changing password for user elasticsearch.
New password:****
Retype new password: ****
passwd: all authentication tokens updated successfully.

Add the new user to the 'wheel' group to give it sudo privileges.

# usermod -aG wheel elasticsearch

2) System Update

Now update your system with updates and security patches using below command on your CentOS 7 server.

# yum update -y

Once your system is ready with prerequisites, then move to next step for the installation of Java Version 8 on your system.

3) Installing Java (JVM) Version 8

Elasticsearch is built using Java that requires at least Java 8 in order to run. Only Oracle’s Java and the OpenJDK are supported. The same JVM version should be used on all Elasticsearch nodes and clients. So, it's recommended that Java version 1.8.0_121 or later must be installed otherwise Elasticsearch will refuse to start if any other version of Java is used.

To install the required version of JAVA, you can use the below command.

$sudo yum install java-1.8.0-openjdk.x86_64

After installation is done, run the command below check the version of the installed java.

$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

The version of Java that Elasticsearch will use can be configured by setting the 'JAVA_HOME' environment variable. Once the prerequisites have been completed, the move to the net session to download, install and then configure the nodes.

How to Download Elasticsearch

Elasticsearch is provided in multiple package formats but 'zip' and 'tar.gz' packages are suitable for installation on any system, which is the easiest choice for getting started with Elasticsearch. The 'rpm' package is more suitable for installation on Red Hat, Centos, SLES, OpenSuSE and other RPM-based systems. It can be downloaded from the Elasticsearch website or from our RPM repository using 'wget' commands.

Let's download the two different versions of Elastisearch package that we will be installing on CentOS 7.

$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.2.tar.gz
$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.0.1.tar.gz

Now we have two different version of Elasticsearch packages available to be installed. Extract the archives and move to the extracted folder to compile and installing the package.

$ tar -zxf elasticsearch-5.0.1.tar.gz
$ tar -zxf elasticsearch-5.2.2.tar.gz

Configure the first node of Elasticsearch

Now start with the latest version of Elasticsearch to be installed first. Let's open the default configuration file using your command line editor placed in the 'config' directory.

$ vim elasticsearch-5.2.2/config/elasticsearch.yml

Press 'i' to switch to insertion mode and insert the following configuration parameters in the file.

cluster.name: elastic_cluster1
node.name: node-1
node.master: true
node.data: true
transport.host: localhost
transport.tcp.port: 9300
http.port: 9200
network.host: 0.0.0.0

Here the http.port and transport.port are not specified in the default configuration, ES tries to pick the next available port at startup, starting at a base of 9200 for HTTP and 9300 for its internal transport. Let's save and close the configuration file using ':wq!' and now configure your secondary node.

Configure secondary node

To configure your secondary node, open the same configuration file placed in the default location of the archive and insert the following contents in it using your editor.

$ vim elasticsearch-5.0.1/config/elasticsearch.yml
cluster.name: elastic_cluster1
node.name: node-2
#node.master: true
node.data: true
transport.host: localhost
transport.tcp.port: 9302
http.port: 9202
network.host: 0.0.0.0

Save and close the file and move to the next section to start its services.

How to start Elasticsearch services

As we have configured both nodes of Elasticsearch with different versions, now we need to start both on our CentOS 7 server by executing its binary script.

$ cd elasticsearch-5.2.2
$ bin/elasticsearch -d

This will start the elasticsearch process in the background. Now change your directory to the secondary node of elasticsearch and run the same commands.

$ cd elasticsearch-5.0.1
$ bin/elasticsearch -d

That's it, now you can check the status of your listening ports to be sure that both nodes are running on their specific ports mentioned in the configuration.

$ netstat -tlnp
$ ps -ef | grep elastic

elasticsearch ports

You can also use the following command to confirm the service has successfully started.

$ curl -X GET 'http://localhost:9200'
{
  "name" : "node-1",
  "cluster_name" : "elastic_cluster1",
  "cluster_uuid" : "yrMHCKfJS2msgvQj-HWkag",
  "version" : {
    "number" : "5.2.2",
    "build_hash" : "f9d9b74",
    "build_date" : "2017-02-24T17:26:45.835Z",
    "build_snapshot" : false,
    "lucene_version" : "6.4.1"
  },
  "tagline" : "You Know, for Search"
}

Similarly for the secondary node running on port '9202' use below command.

$ curl -X GET 'http://localhost:9202'
{
  "name" : "node-2",
  "cluster_name" : "elastic_cluster1",
  "cluster_uuid" : "I4Xk5Yr3RTuyp0Q0IsmxNQ",
  "version" : {
    "number" : "5.0.1",
    "build_hash" : "080bb47",
    "build_date" : "2016-11-11T22:08:49.812Z",
    "build_snapshot" : false,
    "lucene_version" : "6.2.1"
  },
  "tagline" : "You Know, for Search"
}

Conclusion

That's it. In this article, we have learned about installing multiple elasticsearch nodes on a single CentOS 7 server. Now you can use Elasticsearch in a number of different configurations for Logstash, some analytics usage, powering user-facing search on large indexes, and many internal applications. Managing JVMs with large heaps is scary business due to garbage collection run times. It is better to have even smaller heaps as it’s easier to capture and analyze heap dumps. To get optimal Lucene performance, it is also important to have sufficient RAM available for OS file caching of the index files. If we run a single node with a small heap then we would be wasting both CPU and RAM.

Filed Under : LINUX HOWTO

Tagged With : ,

Free Linux Ebook to Download

Leave a Reply

All comments are subject to moderation.