Skip to content

Instantly share code, notes, and snippets.

@jverweijL
Last active July 5, 2017 09:06
Show Gist options
  • Save jverweijL/1bb7c3840bc0b11dc5d79ebcc2208b98 to your computer and use it in GitHub Desktop.
Save jverweijL/1bb7c3840bc0b11dc5d79ebcc2208b98 to your computer and use it in GitHub Desktop.
Recipe for installing Elasticsearch with Liferay DXP

Prerequisites

Before following this tutorial, you will need:

  • A Ubuntu 16.04 Droplet set up by following the Initial Server Setup with Ubuntu 16.04, including creating a sudo non-root user.

  • The Oracle JDK 8 installed, which you can do by following the "Installing the Oracle JDK" section of this Java installation article

Except otherwise noted, all of the commands that require root privileges in this tutorial should be run as a non-root user with sudo privileges.

Step 1 - Find the Right Version of Elasticsearch

If Liferay Portal isn’t running, start it.

Visit port 9200 on localhost to access the embedded Elasticsearch:

http://localhost:9200 A JSON document is returned that varies slightly, but should look similar to this:

{
  "name" : "Wiz Kid",
  "cluster_name" : "LiferayElasticsearchCluster",
  "version" : {
    "number" : "2.2.0",
    "build_hash" : "8ff36d139e16f8720f2947ef62c8167a888992fe",
    "build_timestamp" : "2016-01-27T13:32:39Z",
    "build_snapshot" : false,
    "lucene_version" : "5.4.1"
  },
  "tagline" : "You Know, for Search"
}

The version of Elasticsearch that you want is the value of the "number" field. In this example, it’s 2.2.0.

Step 2 — Downloading and Installing Elasticsearch

Elasticsearch can be downloaded directly from elastic.co in zip, tar.gz, deb, or rpm packages. For Ubuntu, it's best to use the deb (Debian) package which will install everything you need to run Elasticsearch.

First, update your package index.

sudo apt-get update Download the Elasticsearch version as found in step 1, in this case 2.2.0.

wget https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.2.0/elasticsearch-2.2.0.deb

Then install it in the usual Ubuntu way with dpkg.

sudo dpkg -i elasticsearch-2.2.0.deb

This results in Elasticsearch being installed in /usr/share/elasticsearch/ with its configuration files placed in /etc/elasticsearch and its init script added in /etc/init.d/elasticsearch.

To make sure Elasticsearch starts and stops automatically with the server, add its init script to the default runlevels.

sudo systemctl enable elasticsearch.service

Before starting Elasticsearch for the first time, please check the next sections about the recommended minimum configuration.

Step 3 — Installing plugins

Install the following required Elasticsearch plugins:

analysis-icu
analysis-kuromoji
analysis-smartcn
analysis-stempel

To install these plugins, navigate to Elasticsearch Home and enter

cd /usr/share/elasticsearch/
sudo ./bin/plugin install [plugin-name]

Replace [plugin-name] with the Elasticsearch plugin’s name.

Step 4 — Configuring Elasticsearch

Now that Elasticsearch and its Java dependencies have been installed, it is time to configure Elasticsearch. The Elasticsearch configuration files are in the /etc/elasticsearch directory. There are two files:

elasticsearch.yml configures the Elasticsearch server settings. This is where all options, except those for logging, are stored, which is why we are mostly interested in this file.

logging.yml provides configuration for logging. In the beginning, you don't have to edit this file. You can leave all default logging options. You can find the resulting logs in /var/log/elasticsearch by default.

The first variables to customize on any Elasticsearch server are node.name and cluster.name in elasticsearch.yml. As their names suggest, node.name specifies the name of the server (node) and the cluster to which the latter is associated.

If you don't customize these variable, a node.name will be assigned automatically in respect to the Droplet hostname. The cluster.name will be automatically set to the name of the default cluster.

The cluster.name value is used by the auto-discovery feature of Elasticsearch to automatically discover and associate Elasticsearch nodes to a cluster. Thus, if you don't change the default value, you might have unwanted nodes, found on the same network, in your cluster.

To start editing the main elasticsearch.yml configuration file with nano or your favorite text editor.

sudo nano /etc/elasticsearch/elasticsearch.yml Remove the # character at the beginning of the lines for cluster.name and node.name to uncomment them, and then update their values. Your first configuration changes in the /etc/elasticsearch/elasticsearch.yml file should look like this:

/etc/elasticsearch/elasticsearch.yml . . . cluster.name: liferay-cluster . . . These the minimum settings you can start with using Elasticsearch. However, it's recommended to continue reading the configuration part for more thorough understanding and fine-tuning of Elasticsearch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment