How to Install Elasticsearch Cluster


Elasticsearch Cluster建置



Elasticsearch 底層為Apache Lucene 開源搜尋引擎,以分散式平台,十分高效能。
主要優點:
    分散式儲存。
    簡單新增Cluster
    搜尋速度快
設備:
    ubuntu server 14.04
   Java 8
   Elasticsearch 2.1.1

1. 安裝Elasticsearch之前需要安裝JAVA
首先使用apt-get新增JAVA Repository
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
測試是否安裝成功 java -version
設定JAVA_HOME
sudo vi /etc/bash.bashrc
#加入JAVA_HOME
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export PATH=$JAVA_HOME/bin:$PATH


2.安裝Elasticsearch Cluster三台集群 使用ubuntu 14.04版本
Elasticsearch官方下載檔案,使用的檔案為deb,後面階段要讓Elasticsearch開機時自動啟動所以選擇deb,可以選擇其他檔案格式。
wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-2.1.1.deb 
下載完畢後使用dpkg安裝deb
sudo dpkg -i elasticsearch-2.1.1.deb
安裝完成將 Elasticsearch設定自動啟動功能,重新開機測試是否正常
sudo update-rc.d elasticsearch defaults
查看是否有啟動成功
curl -X GET 'http://localhost:9200'
Elasticsearch Server將會回傳json格式
{
  "name" : "test",
  "cluster_name" : "Neil",
  "version" : {
    "number" : "2.1.1",
    "build_hash" : "8ff36d139e16f8720f2947ef62c8167a888992fe",
    "build_timestamp" : "2015-01-27T13:32:39Z",
    "build_snapshot" : false,
    "lucene_version" : "5.4.1"
  },
  "tagline" : "You Know, for Search"
}

手動啟動
sudo service elasticsearch start
3.設定yml檔
設定elasticsearch.yml檔案路徑,權限問題無法使用ls查看,直接修改即可
sudo vi /etc/elasticsearch/elasticsearch.yml
Master Server設定
cluster.name: neil
node.name: ${HOSTNAME}
node.master: true node.data: false
#指定10.1.0.5為Master Server
discovery.zen.ping.unicast.hosts: ["10.1.0.5"]
discovery.zen.ping.multicast.enabled: false
discovery.zen.minimum_master_nodes: 1 
Slave node-1 設定
cluster.name: neil
node.name: ${HOSTNAME}
node.master: false
node.data: true
#指定10.1.0.5為Master Server
discovery.zen.ping.unicast.hosts: ["10.1.0.5"]
discovery.zen.ping.multicast.enabled: false
discovery.zen.minimum_master_nodes: 1 


Slave node-2 設定
cluster.name: neil
node.name: ${HOSTNAME}
node.master: false
node.data: true
#指定10.1.0.5為Master Server
discovery.zen.ping.unicast.hosts: ["10.1.0.5"]
discovery.zen.ping.multicast.enabled: false
discovery.zen.minimum_master_nodes: 1 

Elasticsearch現在已經更新到5.x多版本了,設定大同小異沒有什麼變動,如果你需要用以上的設定安裝5.x 版本一樣也是可以使用的,差別在於plugin安裝,如果安裝elasticsearch-head不能跟舊版本一樣使用 plugin install elasticsearch-ehad會出問題 , 需要安裝grunt來當 Server,啟動Elasticsearch-head即可。

資料來源:
 https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html

沒有留言:

張貼留言