ElasticSearch cluster setup in 2 minutes


ElasticSearch is based on popular Apache Lucene search engine library, another popular variant of  Lucene is Apache SOLR. I'm attracted towards ElasticSearch dues to it's simplicity in JSON style configuration and data access support, I don't intend this blog to be a comparison on ElasticSearch Vs SOLR but I wanted to share my experience around how simple it was to bring up a two node cluster of ElasticSearch.

SOLR 4.2 now includes advanced support for clustering and data sharding similar to ElasticSearch, SOLR depends on Apache Zookeeper instances for these features, you don't need any additional components for ElasticSearch to support these features. The largest reference implementation of ElasticSearch that I know of is Github which recently migrate from SOLR. Here is an interesting techblog on their experiences with this migration
https://github.com/blog/1397-recent-code-search-outages


Step 1: Download ElasticSearch

Download Elastic Search wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.0.Beta1.tar.gz


Step 2: Setup instances

tar -xvf elasticsearch-0.90.0.Beta1.tar.gz

Rename the instance
mv elasticsearch-0.90.0.Beta1 elastic_inst1

Create another copy for the second instance
cp -R elastic_inst1 elastic_inst2

Step 3: Configure instances

NOTE: This step is not mandatory Elasticsearch is smart enough to auto assign a node name and also discover nodes and add them to a cluster, as a best practice it is recommended to assign node and cluster names

vi elastic_inst1/config/elasticsearch.yml
cluster.name: elasticsearch_dc1
node.name: "elastic_inst1"

vi elastic_inst2/config/elasticsearch.yml
cluster.name: elasticsearch_dc1
node.name: "elastic_inst2"


Step 4: Start the instances


./elastic_inst1/bin/elasticsearch -f

./elastic_inst2/bin/elasticsearch -f
When you start the second instance you should see highlighted messages which indicates that the node was automatically added to the cluster


[2013-03-17 19:23:36,845][INFO ][cluster.service          ] [elastic_inst2] detected_master [elastic_inst1][NiEZKK6FSNGuLVNrw_OmbQ][inet[/192.168.0.101:9300]], added {[elastic_inst1][NiEZKK6FSNGuLVNrw_OmbQ][inet[/192.168.0.101:9300]],}, reason: zen-disco-receive(from master [[elastic_inst1][NiEZKK6FSNGuLVNrw_OmbQ][inet[/192.168.0.101:9300]]])

Step 5:  Test instances

Hit following URL from browser to check Cluster health
http://localhost:9200/_cluster/health?pretty
You should see similar output
{
"cluster_name" : "elasticsearch_dc1",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 2,
"number_of_data_nodes" : 2,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0
}

Step 6: Shutdown a node or entire cluster

You can run these commands from your favorite browser REST API plugins or through curl from command line

curl -XPOST http://localhost:9200/_cluster/nodes/_shutdown

You should see a similar output

{"cluster_name":"elasticsearch_dc1","nodes":{"NiEZKK6FSNGuLVNrw_OmbQ":{"name":"elastic_inst1"},"JC4FSShJQzOeMtpRUu_6Ng":{"name":"elastic_inst2"}}}

To shutdown an individual instance within the cluster, use following commands
curl -XPOST http://localhost:9200/_cluster/nodes/elastic_inst1/_shutdown
curl -XPOST http://localhost:9201/_cluster/nodes/elastic_inst2/_shutdown

BERIKAN KOMENTAR ()
Jangan Lupa Tinggalkan Komentarnya di Kolom komentar jika ada bug, atau artikelnya error atau tulisannya salah ya sahabat
 
wisata tradisi game kuliner
close