分佈式搜索引擎Elasticsearch——安裝部署

文章轉自 大唐,文章原地址:http://tangzhaohui.net/358


搭建環境:

os Ubuntu Server 12.04
java java 1.6.0_31

一、單機安裝

Elasticsearch 安裝很簡單。

1. 下載安裝包

wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.6.tar.gz
tar zxvf elasticsearch-0.90.6.tar.gz

2. 運行

在bin目錄下,運行:./elasticsearch

3. 查看

在瀏覽器打開:http://localhost:9200/,即可查看運行狀態。

二、集羣安裝

只要節點在同一網段下,設置一致的cluster.name,啓動的Elasticsearch即可相互檢測到對方,組成集羣。

1. 基礎安裝

首先按照“單擊安裝”方法,在每個集羣節點上安裝單擊版本Elasticsearch。

2. 設置一致的cluster.name

編輯 conf/elasticsearch.yml,根據具體業務設置cluster.name

3. 設置node.name

爲了便於集羣管理和拍錯,給每一個節點設置一個獨特的node.name,否則Elasticsearch會隨機給節點賦予一個node.name。

4. 設置path.data

生產環境中,需要將索引存儲在特定的存儲磁盤。設置path.data即可。

5. 使用elasticsearch-servicewrapper插件

elasticsearch-servicewarpper是Java Service Wrapper實現的Elasticsearch執行包。Github工程地址:https://github.com/elasticsearch/elasticsearch-servicewrapper

i. 下載源文件:git clone https://github.com/elasticsearch/elasticsearch-servicewrapper.git

ii. 拷貝service目錄到Elasticsearch的bin目錄即可。

iii. 執行bin/service目錄下的“elasticsearch”腳本,可以使Elasticsearch以服務的形式運行。

iv. “elasticsearch”腳本有如下參數:

參數 描述
console 前臺運行es
start 後臺運行es
stop 停止es
restart 重啓es
install 使es作爲服務在服務器啓動時自動啓動
remove 取消啓動時自動啓動

v. service目錄下的elasticsearch.conf配置文件,主要用來設置java運行環境參數。

三、集羣監控

這裏介紹主流的三種監控方式。

1. Elasticsearch-head

i. 插件形式安裝

sudo elasticsearch/bin/plugin -install mobz/elasticsearch-head

打開http://localhost:9200/_plugin/head/

ii. 獨立服務形式安裝

git clone git://github.com/mobz/elasticsearch-head.git

直接用瀏覽器打開 elasticsearch-head目錄中的index.html就可以了。當然你也可以部署到nginx,方便團隊成員查看。詳細介紹請查閱https://github.com/mobz/elasticsearch-head

2. bigdesk

bigdesk是elasticsearch的一個集羣監控工具,可以通過它來查看es集羣的各種狀態,如:cpu、內存使用情況,索引數據、搜索情況,http連接數等。項目git地址: https://github.com/lukas-vlcek/bigdesk。和head一樣,它也是個獨立的網頁程序,使用方式和head一樣。

i. 插件形式安裝

bin/plugin -install lukas-vlcek/bigdesk

如果你在本地運行,瀏覽器打開http://localhost:9200/_plugin/bigdesk/,bigdesk會自動連接當前網段中存在的es節點。

ii. 獨立服務形式安裝

git clone https://github.com/lukas-vlcek/bigdesk.git

直接用瀏覽器打開 bigdesk目錄中的index.html就可以了。當然你也可以部署到nginx,方便團隊成員查看。詳細介紹請查閱https://github.com/lukas-vlcek/bigdesk

3. Elasticsearch本身的status api

i. 瀏覽器訪問

http://localhost:9200/_cluster/health 的到json格式的信息。其本身也有green/yellow/red等不同的狀態。

ii. 腳本檢測

當然你也可以寫一個簡單的腳本,定時獲取集羣狀態,或者與nagios結合,提供更加及時的監控報警。

四、Elasticsearch集羣狀態

服務 描述
Elasticsearch集羣
  1. 服務器地址:mydomain0, mydomain1
  2. 安裝路徑:/home/mydomain/opt/elasticsearch-0.90.6
  3. 啓動命令:./bin/service/ elasticsearch start (stop/restart類似)
  4. data存儲路徑:/data1/elasticsearch/
  5. conf路徑:/home/mydomain/opt/elasticsearch-0.90.6/conf
  6. logs路徑:/home/mydomain/opt/elasticsearch-0.90.6/logs
  7. plugins(插件)路徑:/home/mydomain/opt/elasticsearch-0.90.6/plugins
elasticsearch-head
  1. 服務器地址:mydomain0
  2. 訪問方法:綁定host “192.168.0.1 mydomain0 es.mydomain.com”,瀏覽器打開http://es.mydomain.com/。(記得在頁面最上面的輸入框輸入你要查看的es節點地址
  3. 安裝路徑:/home/mydomain/opt/elasticsearch-head
  4. nginx配置文件:/opt/nginx/conf/sites/elasticsearch.conf
bigdesk
  1. 服務器地址:mydomain0
  2. 訪問方法:綁定host “192.168.0.1 mydomain0 es.mydomain.com”,瀏覽器打開http://es.mydomain.com/bigdesk。(記得在頁面最上面的輸入框輸入你要查看的es節點地址
  3. 安裝路徑:/home/mydomain/opt/bigdesk
  4. nginx配置文件:/opt/nginx/conf/sites/elasticsearch.conf

參考:

  1. Elasticsearch官網:http://www.elasticsearch.org/
  2. Elasticsearch中文網站:http://es-cn.medcl.net/
  3. elasticsearch-servicewrapper插件 https://github.com/elasticsearch/elasticsearch-servicewrapper
  4. bigdesk集羣監控 https://github.com/lukas-vlcek/bigdesk
  5. head監控 https://github.com/mobz/elasticsearch-head

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章