Tutorial

How To Install Elasticsearch on an Ubuntu VPS

Published on December 13, 2013
author

Christopher J. Kendell

How To Install Elasticsearch on an Ubuntu VPS

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead: This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.

Elasticsearch is a platform for distributed, RESTful search and analysis. It can scale as needed, and you can get started using it right away on a single DigitalOcean droplet. In this tutorial, we will download, install, and start using Elasticsearch on Ubuntu. The steps provided have currently been tested on: Ubuntu 12.04.3 x64 and Ubuntu 13.10 x64.

Dependencies


First, update the list of available packages by running apt-get update.

Next, we must install the Java runtime. There are two options here.

  • Install the OpenJDK runtime supplied by Ubuntu.
  • Install the Elasticsearch recommended Java runtime, Oracle Java.

The first option works perfectly fine if you would just like to play around and get acquainted with Elasticsearch or run a small collection of nodes. The latter option is the one recommended by Elasticsearch for guaranteed compatibility.

OpenJDK


To accomplish the first option, we can simply run apt-get install openjdk-6-jre.

Oracle Java


For the second option, we’ll follow the steps in the Elasticsearch documentation. To begin, we must add a repository that contains the Oracle Java runtime

sudo add-apt-repository ppa:webupd8team/java

We must then run apt-get update to pull in package information from this new repository. After doing so, we can install the Oracle Java runtime

sudo apt-get install oracle-java7-installer

While executing the above command you will be required to accept the Oracle binary license. If you don’t agree to the license, you may instead install the OpenJDK runtime instead.

Test your Java installation


You can then check that Java is installed by running java -version.

That’s all the dependencies we need for now, so let’s get started with obtaining and installing Elasticsearch.

Download and Install


Elasticsearch can be downloaded directly from their site in zip, tar.gz, deb, or rpm packages. You don’t need to do this ahead of time, as we will download the files that we need as we need them in the text below.

Install


Given the download options provided by Elasticsearch, we have a few options:

  • Install from the zip or tar.gz archive.
  • Install from the deb package.
  • Install from the rpm package.

That last option is not the Ubuntu way, so we’ll ignore it.

Installing from zip or tar.gz archive is best if you just want to play around with Elasticsearch for a bit. Installing from either of these options simply makes available the binaries needed for running Elasticsearch. Installing from the deb package fully installs Elasticsearch and starts the server running immediately. This includes installing an init script at /etc/init.d/elasticsearch which starts Elasticsearch on boot. If you are only looking to play around with Elasticsearch, I suggest installing from the zip or tar.gz. That way, you can discover Elasticsearch while starting and stopping the server at will.

Installing from zip or tar.gz archive


The zip and tar.gz downloads both contain pre-compiled binaries for Elasticsearch.

To begin, download the source somewhere convenient. After extracting the archive, you will be able to run the binaries directly from the resulting directory, so you should place them somewhere accessible by every user you want to have access to Elasticsearch. For this tutorial, we’ll just download to our current user’s directory. If you download them to /tmp, they are likely to disappear when you reboot your VPS. If this is what you want, go ahead and place the download there. You can create a new temporary directory in /tmp quickly by running mktemp -d.

In any case, make sure you’re in the directory you want to extract Elasticsearch into before proceeding.

Download the archive


Run either

wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.7.zip

or

wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.7.tar.gz

The first command downloads the zip archive, and the second command downloads the tar.gz archive. If you downloaded the zip package, make sure you have previously run apt-get install unzip then run

unzip elasticsearch-0.90.7.zip

Alternatively, if you’ve downloaded the tar.gz package, run

tar -xf elasticsearch-0.90.7.tar.gz

Either option will create the directory elasticsearch-0.90.7. Change into that directory by entering cd elasticsearch-0.90.7, and you’ll find the binaries in the bin folder.

Installing from the Debian software package


The best package to download for Ubuntu is the deb package. The RPM can work but it needs to be converted first, and we will not cover doing so here. Grab the deb package by running

wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.7.deb

Installing directly from a Debian package is done by running

dpkg -i elasticsearch-0.90.7.deb

This results in Elasticsearch being properly installed in /usr/share/elasticsearch. Recall that installing from the Debian package also installs an init script in /etc/init.d/elasticsearch that starts the Elasticsearch server running on boot. The server will also be immediately started after installation.

Configuration files


If installed from the zip or tar.gz archive, configuration files are found in the config folder of the resulting directory. If installing from the Debain package, configuration files are found in /etc/elasticsearch.

In either case, there will be two main configuration files: elasticsearch.yml and logging.yml. The first configures the Elasticsearch server settings, and the latter, unsurprisingly, the logger settings used by Elasticsearch.

“elasticsearch.yml” will, by default, contain nothing but comments.

“logging.yml” provides configuration for basic logging. You can find the resulting logs in /var/log/elasticsearch.

Remove Elasticsearch Public Access

Before continuing, you will want to configure Elasticsearch so it is not accessible to the public Internet–Elasticsearch has no built-in security and can be controlled by anyone who can access the HTTP API. This can be done by editing elasticsearch.yml. Assuming you installed with the package, open the configuration with this command:

sudo vi /etc/elasticsearch/elasticsearch.yml

Then find the line that specifies network.bind_host, then uncomment it and change the value to localhost so it looks like the following:

network.bind_host: localhost

Then insert the following line somewhere in the file, to disable dynamic scripts:

script.disable_dynamic: true

Save and exit. Now restart Elasticsearch to put the changes into effect:

sudo service elasticsearch restart

We’ll cover other basic configuration options later, but first we should test the most basic of Elasticsearch installs.

Test your Elasticsearch install


You have now either extracted the zip or tar.gz archives to a directory, or installed Elasticsearch from the Debian package. Either way, you have the Elasticsearch binaries available, and can start the server. If you used the zip or tar.gz archives, make sure you’re in the resulting directory. If you installed using the Debian package, the Elasticsearch server should already be running, so you don’t need to start the server as shown below.

Let’s ensure that everything is working. Run

 ./bin/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 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

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

You should see the following response

{
  "ok" : true,
  "status" : 200,
  "name" : "Xavin",
  "version" : {
    "number" : "0.90.7",
    "build_hash" : "36897d07dadcb70886db7f149e645ed3d44eb5f2",
    "build_timestamp" : "2013-11-13T12:06:54Z",
    "build_snapshot" : false,
    "lucene_version" : "4.5.1"
  },
  "tagline" : "You Know, for Search"
}

If you see a response similar to the one above, Elasticsearch is working properly. Alternatively, you can query your install of Elasticsearch from a browser by visiting <your-Droplet-IP>:9200. You should see the same JSON as you saw when using curl above.

If you installed by the zip or tar.gz archive, the server can be stopped using the RESTful API

curl -X POST 'http://localhost:9200/_cluster/nodes/_local/_shutdown'

The above command also works when Elasticsearch was installed using the Debian package, but you can also stop the server using service elasticsearch stop. You can restart the server with the corresponding service elasticsearch start.

Using Elasticsearch


Elasticsearch is up and running. Now, we’ll go over some basic configuration and usage.

Basic configuration


When installed by zip or tar.gz archives, configuration files are found in the config folder inside the resulting directory. When installed via Debian package, configuration files can be found in /etc/elasticsearch/. The two configuration files you will find are elasticsearch.yml and logging.yml. The first is a general Elasticsearch configuration. The provided file contains nothing but comments, so default settings are used. Reading through the file will provide a good overview of the options, but I will make a few suggestions below. None of the settings are necessary. You can work with Elasticsearch without doing any of the following, but it’ll be a raw development environment.

The setting “cluster.name” is the method by which Elasticsearch provides auto-discovery. What this means is that if a group of Elasticsearch servers on the same network share the same cluster name, they will automatically discover each other. This is how simple it is to scale Elasticsearch, but be aware that if you keep the default cluster name and there are other Elasticsearch servers on your network that are not under your control, you are likely to wind up in a bad state.

Basic usage


Let’s add some data to our Elasticsearch install. Elasticsearch uses a RESTful API, which responds to the usual CRUD commands: Create, Read, Update, and Destroy.

To add an entry

curl -X POST 'http://localhost:9200/tutorial/helloworld/1' -d '{ "message": "Hello World!" }'

You should see the following response

{“ok”:true,“_index”:“tutorial”,“_type”:“helloworld”,“_id”:“1”,“_version”:1}

What we have done is send a HTTP POST request to the Elasticserach server. The URI of the request was /tutorial/helloworld/1. It’s important to understand the parameters here:

  • “tutorial” is index of the data in Elasticsearch.
  • “helloworld” is the type.
  • “1” is the id of our entry under the above index and type.

If you saw the response above to the curl command, we can now query for the data with

curl -X GET 'http://localhost:9200/tutorial/helloworld/1'

which should respond with

{"_index":"tutorial","_type":"helloworld","_id":"1","_version":1,"exists":true, "_source" : { "message": "Hello World!" }}

Success! We’ve added to and queried data in Elasticsearch.

One thing to note is that we can get nicer output by appending ?pretty=true to the query. Let’s give this a try

curl -X GET 'http://localhost:9200/tutorial/helloworld/1?pretty=true'

Which should respond with

{
  "_index" : "tutorial",
  "_type" : "helloworld",
  "_id" : "1",
  "_version" : 1,
  "exists" : true, "_source" : { "message": "Hello World!" }
}

which is much more readable. The output will also be pretty printed without needing to append the query string if you have set format=yaml in the Elasticsearch configuration file.

Conclusion


We have now installed, configured and begun using Elasticsearch. Since it responds to a basic RESTful API. It is now easy to begin adding to and querying data using Elasticsearch from your application.

<div class=“author”>Submitted by: ckendell</div>

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar
Christopher J. Kendell

author

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
10 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

From 1.6 and upwards the “disable_script” doesn’t need to be set. It’s a deprecated setting and new defaults are

script.inline: sandbox script.indexed: sandbox script.file: on

Official installation documentation for latest version (currently v1.5) http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-repositories.html

Thanks for the documet

Quick and easy way to install: http://forgerecipes.com/recipes/9

Make sure you have java 7 or above. Java 6 didn’t work with v1.4.x

Minor typo in the article: init script in /init.d/elasticsearch should be: “init script in /etc/init.d/elasticsearch”

Hi guys! What do you think about install eleasticsearch as search engine for a (medium size) symfony2 app on (1gb ram) droplet?, index will have no more than 1500 documents. is it enough memory for this and for run jvm?

Updated instructions that worked for me in case anyone is having problems.

This comment has been deleted

    Before running sudo add-apt-repository ppa:webupd8team/java you should add sudo apt-get install software-properties-common python-software-properties.

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    Join the Tech Talk
    Success! Thank you! Please check your email for further details.

    Please complete your information!

    Featured on Community

    Get our biweekly newsletter

    Sign up for Infrastructure as a Newsletter.

    Hollie's Hub for Good

    Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

    Become a contributor

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    Welcome to the developer cloud

    DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

    Learn more