Elasticsearch開篇,把之前積累的一些東西整理一下,該篇介紹windows和Linux上安裝Elasticsearch。html
ElasticSearch 是一個基於Lucene的搜索服務器。它提供了一個分佈式多用戶能力的全文搜索引擎,基於RESTful web接口。Elasticsearch是用Java開發的,並做爲Apache許可條款下的開放源碼發佈。目前咱們將Elasticsearch用於日 志的實時採集和Mapreduce分析結果的查詢業務中。html5
Elasticsearch支持分佈式索引,近實時搜索,高效穩定,協議簡單(經過http協議和json格式交互數據),無中心化,任何節點都是對等的,能夠經過多副原本容錯,自動發現節點等特性。java
如今碼農常常用的github就是經過Elasticsearch來構建分佈式索引的。node
Elasticsearch在windows安裝
1,首先對比關係數據庫和elasticsearch的關係。linux
Mysql |
Elasticsearch |
database |
index |
table |
type |
table schema |
mapping |
row |
document |
field |
field |
2,下載地址:git
https://www.elastic.co/downloads/elasticsearchgithub
目錄結構:web
目錄(Directory) |
描述(Description) |
bin |
運行ElasticSearch實例和插件管理所需的腳本 |
config |
配置文件所在的目錄 |
lib |
ElasticSearch所使用的庫 |
ElasticSearch啓動後,它將建立如下目錄(若是它們不存在):sql
目錄(Directory) |
描述(Description) |
data |
存儲ElasticSearch所使用的全部數據 |
logs |
實例運行期間產生的事件和錯誤信息的文件 |
plugins |
用於存儲安裝的插件 |
work |
臨時文件 |
3,windows下安裝數據庫
解壓elasticsearch-1.4.0.zip
- E:\workspace\fish-search>cd /d E:\tools\elasticsearch-1.4.0\bin
-
- E:\tools\elasticsearch-1.4.0\bin>elasticsearch.bat
- [2014-11-28 14:31:32,666][INFO ][node ] [Christopher Summers] version[1.4.0], pid[8344], build[bc94bd8/2014-11-05T14:26:12Z]
- [2014-11-28 14:31:32,666][INFO ][node ] [Christopher Summers] initializing ...
- [2014-11-28 14:31:32,671][INFO ][plugins ] [Christopher Summers] loaded [], sites []
- [2014-11-28 14:31:46,889][INFO ][node ] [Christopher Summers] initialized
- [2014-11-28 14:31:46,889][INFO ][node ] [Christopher Summers] starting ...
- [2014-11-28 14:31:49,936][INFO ][transport ] [Christopher Summers] bound_address {inet[/0:0:0:0:0:0:0:0:9300]}, publish_address {inet[/10.0.10.172:9300]}
- [2014-11-28 14:31:50,337][INFO ][discovery ] [Christopher Summers] elasticsearch/Ca3EKAj5RC6yHLr5QcgjCw
- [2014-11-28 14:31:54,141][INFO ][cluster.service ] [Christopher Summers] new_master [Christopher Summers][Ca3EKAj5RC6yHLr5QcgjCw][fish-PC][inet[/10.0.10.172:9300]], reason: zen-disco-join (elected_as_master)
- [2014-11-28 14:31:54,210][INFO ][http ] [Christopher Summers] bound_address {inet[/0:0:0:0:0:0:0:0:9200]}, publish_address {inet[/10.0.10.172:9200]}
- [2014-11-28 14:31:54,210][INFO ][node ] [Christopher Summers] started
- [2014-11-28 14:31:55,605][INFO ][gateway ] [Christopher Summers] recovered [0] indices into cluster_state
啓動後,訪問:http://localhost:9200/
- {
-
- "status" : 200,
- "name" : "Christopher Summers",
- "cluster_name" : "elasticsearch",
- "version" : {
- "number" : "1.4.0",
- "build_hash" : "bc94bd81298f81c656893ab1ddddd30a99356066",
- "build_timestamp" : "2014-11-05T14:26:12Z",
- "build_snapshot" : false,
- "lucene_version" : "4.10.2"
- },
- "tagline" : "You Know, for Search"
- }
表示啓動成功
讓咱們看看JSON的每一個字段表明的含義:
status: 發出請求後的HTTP的錯誤代碼。200表示一切正常。
name: 咱們Elasticsearch實例的名字。在默認狀況下,Elasticsearch會隨機給一個名稱,在elasticsearch的jar包中,config/names.txt文件中定義了這些默認的名稱,Elasticsearch就是在該文件中隨機獲取的名稱。
version: 這個對象有一個number字段,表明了當前運行的Elasticsearch版本號,和一個Snapshot_build字段,表明了你當前運行的版本是不是從源代碼構建而來。
Tagline: 包含了Elasticsearch的第一個tagline: "You Know, for Search."
Linux ES集羣安裝
三臺機器,分別是:
10.0.1.75
10.0.1.76
10.0.1.77
分別修改各臺服務器的${ELASTICSEARCH_HOME}/config/elasticsearch.yml文件
10.0.1.75:
- cluster.name: bicloud //集羣名稱(集羣中全部機器,名稱要同樣)
- node.name: fish75 //節點名稱(名稱要不同)
- node.master: true //true能夠競選主節點
- node.data: true //是否爲數據節點
10.0.1.76:
- cluster.name: bicloud //集羣名稱(集羣中全部機器,名稱要同樣)
- node.name: fish76 //節點名稱(名稱要不同)
- node.master: true //true能夠競選主節點
- node.data: true //是否爲數據節點
10.0.1.77:
- cluster.name: bicloud //集羣名稱(集羣中全部機器,名稱要同樣)
- node.name: fish77 //節點名稱(名稱要不同)
- node.master: true //true能夠競選主節點
- node.data: true //是否爲數據節點
各個服務器的Elasticsearch的配置文件配置好以後,而後啓動就能夠了。
- [root@bicloud75 bin]# ./elasticsearch -d
- #啓動完成以後查看進程是否存在
- [root@bicloud75 bin]# jps
- 28710 Elasticsearch
http://10.0.1.77:9200/_nodes/process?pretty
插件的安裝
elasticsearch-head插件
elasticsearch-head是一個elasticsearch的集羣管理工具,它是徹底由html5編寫的獨立網頁程序,你能夠經過插件把它集成到es。
- [root@bicloud75 bin]# ./plugin -install mobz/elasticsearch-head
- -> Installing mobz/elasticsearch-head...
- Trying https://github.com/mobz/elasticsearch-head/archive/master.zip...
- Downloading ...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................DONE
- Installed mobz/elasticsearch-head into /home/elasticsearch-1.6.0/plugins/head
安裝成功後,訪問:http://localhost:9200/_plugin/head/
粗線綠框表示主分片,細線綠框爲備份分片。
elasticsearch-bigdesk插件
bigdesk是elasticsearch的一個集羣監控工具,能夠經過它來查看es集羣的各類狀態,如:cpu、內存使用狀況,索引數據、搜索狀況,http鏈接數等。
- [root@bicloud77 bin]# ./plugin -install lukas-vlcek/bigdesk
- -> Installing lukas-vlcek/bigdesk...
- Trying https://github.com/lukas-vlcek/bigdesk/archive/master.zip...
- Downloading ........................................................................................................................................................................................................................................................DONE
- Installed lukas-vlcek/bigdesk into /home/elasticsearch-1.6.0/plugins/bigdesk
- Identified as a _site plugin, moving to _site structure ...
安裝成功後,訪問:http://localhost:9200/_plugin/bigdesk/#nodes
marvel安裝
marvel是elasticsearch出品的一個收費插件。
- [root@bicloud75 bin]# ./plugin -i elasticsearch/marvel/latest
- -> Installing elasticsearch/marvel/latest...
- Trying http://download.elasticsearch.org/elasticsearch/marvel/marvel-latest.zip...
- Downloading .........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................DONE
- Installed elasticsearch/marvel/latest into /home/elasticsearch-1.4.2/plugins/marvel
安裝成功後,訪問路徑:http://10.0.1.75:9200/_plugin/marvel/