ElasticSearch的分散式安裝
阿新 • • 發佈:2019-02-20
(1)介紹:ElasticSearch是一個基於Lucene的搜尋伺服器。它提供了一個分散式多使用者能力的全文搜尋引擎,基於RESTful web介面。Elasticsearch是用Java開發的,並作為Apache許可條款下的開放原始碼釋出,是當前流行的企業級搜尋引擎。設計用於雲端計算中,能夠達到實時搜尋,穩定,可靠,快速,安裝使用方便。
(2)安裝過程:先去官網上下載最新的版本version:5.6.1,下載和解壓後的檔案中的bin包含程式啟動的程式,config主要是配置相關的東西;
ok,現在啟動elasticsearch,在檔案目錄下:
elasticsearch-5.6.1$ ./bin/elasticsearch
[2017-09-24T13:26:29,986][INFO ][o.e.c.s.ClusterService ] [master] new_master {master}{IM-ZTkHdTs2ghXu5ejzfDQ}{YcUoqGTNQmeKxYQaffRuMA}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined) [2017-09-24T13:26:29,999][INFO ][o.e.h.n.Netty4HttpServerTransport] [master] publish_address {127.0.0.1:9200}, bound_addresses {127.0.0.1:9200} [2017-09-24T13:26:29,999][INFO ][o.e.n.Node ] [master] started [2017-09-24T13:26:30,250][INFO ][o.e.g.GatewayService ] [master] recovered [1] indices into cluster_state
出現如上log表示已經啟動了,啟動後,elaticsearch預設的web埠是9200,去網頁上看下:localhost:9200,當看到如下:
{ "name" : "master", "cluster_name" : "daic", "cluster_uuid" : "hHye4IE9TlujANc4GtZxKw", "version" : { "number" : "5.6.1", "build_hash" : "667b497", "build_date" : "2017-09-14T19:22:05.189Z", "build_snapshot" : false, "lucene_version" : "6.6.1" }, "tagline" : "You Know, for Search" }
(3)既然是分散式,那為什麼只有一個master節點,不急,下面安裝slave節點,不妨就做slave1和slave2節點吧;
將下載的壓縮包也解壓到slave1和slava2資料夾,這樣elasticsearch看起來就可以啟動3個一樣的的了,但這3者之間還沒有發生任何關係,下面配置將讓它們發生關係;首先在之前配置的節點中開啟elasticsearch.yml檔案:
vim config/elasticsearch.yml
將其配置成master節點:http.cors.enabled: true
http.cors.allow-origin: "*" //web外掛訪問時會存在跨域問題,後面會介紹
cluster.name: daic //叢集名字
node.name: master
node.master: true //master節點
network.host: 127.0.0.1 //本機
同樣開啟slave1的elasticsearch.yml檔案,配置成slave1節點;cluster.name: daic //叢集名字,和mater一致
node.name: slave1
network.host: 127.0.0.1//當前的ip,測試在同樣的機器上
http.port: 9201 //埠設為9201
discovery.zen.ping.unicast.hosts: ["127.0.0.1"]//配置連線到master的主機地址
開啟slave1,:
./bin/elasticsearch
在網頁中輸入localhost:9201看下,返回:{
"name" : "slave1",
"cluster_name" : "daic",
"cluster_uuid" : "hHye4IE9TlujANc4GtZxKw",
"version" : {
"number" : "5.6.1",
"build_hash" : "667b497",
"build_date" : "2017-09-14T19:22:05.189Z",
"build_snapshot" : false,
"lucene_version" : "6.6.1"
},
"tagline" : "You Know, for Search"
}
ok,slave1啟動了,同樣開啟slave2資料夾下的elasticsearch.yml檔案,配置成slave2節點;
cluster.name: daic //叢集名字,和mater一致
node.name: slave2
network.host: 127.0.0.1//當前的ip,測試在同樣的機器上
http.port: 9202 //埠設為9202
discovery.zen.ping.unicast.hosts: ["127.0.0.1"]//配置連線到master的主機地址
開啟slave2,:
./bin/elasticsearch
在網頁中輸入localhost:9202看下,返回:{ "name" : "slave2", "cluster_name" : "daic", "cluster_uuid" : "hHye4IE9TlujANc4GtZxKw", "version" : { "number" : "5.6.1", "build_hash" : "667b497", "build_date" : "2017-09-14T19:22:05.189Z", "build_snapshot" : false, "lucene_version" : "6.6.1" }, "tagline" : "You Know, for Search" }至此,master、slave1、slave2配置全部完成,但這樣看起來還是不爽對不對,沒關係,我們可以在webui中看,webui外掛的配置見下節。