Tuesday, June 7, 2016

Install Elasticsearch in Ubuntu 16.04

Steps to install Elasticsearch on Ubuntu 16.04

Install Elasticsearch

Run the following to import elasticsearch public GPG
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

Create the elastic source list
echo "deb http://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list

update the apt packages on database
sudo apt-get update

then install elasticsearch
sudo apt-get -y install elasticsearch

elasticsaerch will be installed on /etc/elasticsearch

Configure Elasticsearch

Next we should configure elasticsearch by modifying the elasticsearch.yml file
sudo nano /etc/elasticsearch/elasticsearch.yml

Set Cluster Name

first you need to set up cluster name to the name of your cluster, otherwise the default is "elasticsearch"
cluster.name: myCluster

Set Node Name

then configure the node name, otherwise a random name will be assigned
node.name: Barbara-Gordon

Set Network address and port

the default network host is set to localhost and port 9200, which only allow elastic to be accessed locally, you can set it to 0.0.0.0 so that elasticsearch can be accessed locally and from outside.
network.host: 0.0.0.0
http.port: 9200

Set master and data configuration

An elasticsearch can behave either master or data node, or can also be both which you can configure on node.master and node.slave item, if we try to set a standalone server then set it to
node.master = true
node.slave = true

Set number of shards and replica

On elasticsearch data can be stored in many shards and replicated a few times, which you can configure on index.number_of_shards and index.number_of_replicas, if we try to set a standalone server, it can be set to
index.number_of_shards: 1
index.number_of_replicas: 0
because on a standalone server you want to put data on single shards without replication

Run Elasticsearch

to run elasticsearch you can start, stop and check status with the following command
sudo service elasticsearch start
sudo service elasticsearch stop
sudo service elasticsearch status

you can test wheter elasticsaerch is running by viewing the status log or try to hit the api by running this command
curl localhost:9200

the result should be as follow
{
"name" : "Barbara-Gordon",
"cluster_name" : "myCluster",
"version" : {
"number" : "2.3.3",
"build_hash" : "218bdf10790eef486ff2c41a3df5cfa32dadcfde",
"build_timestamp" : "2016-05-17T15:40:04Z",
"build_snapshot" : false,
"lucene_version" : "5.5.0"
},
"tagline" : "You Know, for Search"
}

No comments :

Post a Comment