Wednesday, August 31, 2016

Installing ElasticSearch On ubuntu 16.04 and 14.04

Installing ElasticSearch On ubuntu 16.04 and 14.04



Updated On DEC 2016: Installation Script In Method 2 updated for installation of elastic search 5.x

Elasticsearch is a highly scalable open-source full-text search and analytics engine build on top of Apache Lucene(A free and open-source information retrieval software library). It allows you to store, search, and analyze big volumes of data quickly and in near real time. It is generally used as the underlying engine/technology that powers applications that have complex search features and requirements.

Here we are going to see, How to install and setup elasticsearch on Ubuntu Linux 16.04 and 14.04..
Here I am going to show you two ways to install elasticsearch on Ubuntu Linux..

The first one is manual installation of elasticsearch.. You have to follow instructions one by one ..
The second one is an easy way, there we use shell-script to install the elasticsearch as it would take care of all things.. The script will install and setup elasticsearch for you..

Installation :

Method 1 :

First things first, Before we start to install elasticsearch, we need to install Java Runtime Environment (JRE).. because Elasticsearch itself written in the Java. (Elasticsearch requires Java 7 or higher).
This step shows you how to install OpenJDK-8.
First, update the list of available packages by running apt-get update.

sudo apt-get update

Then, install OpenJDK with the command:

For Ubuntu 16.04 :

sudo apt-get -y install openjdk-8-jdk openjdk-8-jre

For Ubuntu 14.04 :

sudo add-apt-repository -y ppa:openjdk-r/ppa && sudo apt-get update && sudo apt-get -y install openjdk-8-jdk openjdk-8-jre

To verify your JRE is installed and can be used, run the command: java -version

The result should look like this:

openjdk version "1.8.0_91" OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14) OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
If You Have Already Installed Version of JAVA in Your System.. Please Set OpenJDK 8 as Default Version.. Otherwise you may encounter problems while starting elasticsearch.. You can configure multiple versions of java by running following command.. sudo update-alternatives --config java Now, select apropriate version of JAVA..
to verify the java version run.. java -version

Download and Install Elasticsearch :

Elasticsearch can be downloaded directly from official site as zip, tar.gz and deb

I will recommend.. Installing from zip or tar archive.. Because as far as I knew it is the best way to get Elasticsearch on Ubuntu ... from my experience the another way (installing from .deb) is very worst... has many nasty issues(tried on Ubuntu 16.04)..

Download the archive

cd && wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/zip/elasticsearch/2.3.5/elasticsearch-2.3.5.zip

The above command downloads the zip archive, make sure that you have unzip installed in your system... if don't have installed unzip in your system.. run the following command.. to install unzip

sudo apt-get install unzip

Now unzip/decompress the downloaded archive.. you can do this with command given below..

unzip elasticsearch-2.3.5.zip

Move Extracted/unzipped directory to /opt :

We don't want to pollute our home folder and make it ugly with too many folders apart from default one.. and moving elasticsearch to /opt directory will also make it available to other users in your system too..

If you already have directory named elasticsearch-* in your /opt directory you will/may encounter problems while trying to move our newly extracted folder into /opt . so better remove them before you move our new elasticsearch folder into /opt. to do this run following command.... sudo rm -r /opt/elasticsearch-2*

Now move newly extracted elasticsearch directory to /opt with following command..

sudo mv elasticsearch-2.3.5/ /opt/

Now your elasticsearch is ready to use, You can run it with following command..

/opt/elasticsearch-2.3.5/bin/elasticsearch

But it's so convenient, if we can able to start it from commandline.. by simply typing 'elasticsearch' .. just like normal system commands.. to do so.. we have to create a symbolic link for elasticsearch in /bin folder.. Run following commands....

First remove symbolic link if one already exists..

sudo rm /bin/elasticsearch

now.. create new symbolic link ...

sudo ln -s /opt/elasticsearch-2.3.5/bin/elasticsearch /bin/

That's it .. now you can start elasticsearch just by typing "elasticsearch" in your terminal window..

Now the other method (method 2) show you the easiest way of getting elasticsearch up and running on your Ubuntu installation..

Method 2 :

In this method ... You just need to run the following code ... the script will take care of remaining things..

wget -O - https://raw.githubusercontent.com/shivarajnaidu/UV-Shell-Scripts/master/ElasticSearch-Installation-Scripts/elasticsearch-installation-script-for-ubuntu.sh | bash -s

Update :

The installation script is updated to support installation of elasticsearch v5.x. If you want to install elasticsearch 5.x, just run above command with argument '5' (with out quotes).

wget -O - https://raw.githubusercontent.com/shivarajnaidu/UV-Shell-Scripts/master/ElasticSearch-Installation-Scripts/elasticsearch-installation-script-for-ubuntu.sh | bash -s 5

Test your Elasticsearch installation

Start elasticsearch by typing "elasticsearch" on your command-line..
Let's ensure that everything is working well... open terminal and Run following..

elasticsearch
Elasticsearch should now be running on port 9200. Do note that Elasticsearch takes some time to fully start, so running the curl command below or checking from browser immediately might fail. It shouldn't take longer than ten seconds to start responding, so if the below command fails, something else is likely wrong. Ensure the server is started by running

To test elasticsearch run following command in terminal..

curl -X GET 'http://localhost:9200'

or even you can check from your web browser by visiting http://localhost:9200

if elasticsearch works well.. You should see the following response..

shivaraj@shivaraj-A14RM0E:~$ curl -X GET 'http://localhost:9200' { "name" : "Suicide", "cluster_name" : "elasticsearch", "version" : { "number" : "2.3.5", "build_hash" : "90f439ff60a3c0f497f91663701e64ccd01edbb4", "build_timestamp" : "2016-07-27T10:36:52Z", "build_snapshot" : false, "lucene_version" : "5.5.0" }, "tagline" : "You Know, for Search" } shivaraj@shivaraj-A14RM0E:~$
Hi friends, If you found any issue or typo error, please feel free to report it.. You can either open an issue on github or you can also report it on our Facebook Page via message (www.fb.com/opensourceinside) .