歡迎光臨
每天分享高質量文章

ElasticSearch ——單臺伺服器部署多個節點

一般情況下單臺伺服器只會部署一個 ElasticSearch node,但是在學習過程中,很多情況下會需要實現 ElasticSearch 的分散式效果,所以需要啟動多個節點,但是學習開發環境(不想開多個虛擬機器實現多個伺服器的效果),所以就想著在一臺伺服器上部署多個結點(下文以2個結點作為例子),兩個節點分別稱為實體一、二。

首先將 elasticsearch-5.0.2 檔案夾再複製一份

# wuxiwei @ wuxiwei in ~/software
$ cp -R elasticsearch-5.0.2 elasticsearch-5.0.2-node-2
# wuxiwei @ wuxiwei in ~/software
$ ls -l
total 145568
drwxr-xr-x  12 wuxiwei  staff       408 12 11 16:23 elasticsearch-5.0.2
drwxr-xr-x  12 wuxiwei  staff       408 12 11 16:27 elasticsearch-5.0.2-node-2

主要工作就是修改 elasticsearch.yml 配置檔案

實體二:config目錄下的 elasticsearch.yml 內容

將 node.name: node-1 修改為 node-2,

分別開啟兩個節點

# wuxiwei @ wuxiwei in ~/software/elasticsearch-5.0.2
$ ./bin/elasticsearch

# wuxiwei @ wuxiwei in ~/software/elasticsearch-5.0.2
$ cd ../elasticsearch-5.0.2-node-2
# wuxiwei @ wuxiwei in ~/software/elasticsearch-5.0.2-node-2
$ ./bin/elasticsearch

查詢是否成功

$ curl -i -XGET 'http://localhost:9200/_cluster/health?pretty'\;
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 457

{
 "cluster_name" : "my",
 "status" : "green",
 "timed_out" : false,
 "number_of_nodes" : 2,
 "number_of_data_nodes" : 2,
 "active_primary_shards" : 20,
 "active_shards" : 40,
 "relocating_shards" : 0,
 "initializing_shards" : 0,
 "unassigned_shards" : 0,
 "delayed_unassigned_shards" : 0,
 "number_of_pending_tasks" : 0,
 "number_of_in_flight_fetch" : 0,
 "task_max_waiting_in_queue_millis" : 0,
 "active_shards_percent_as_number" : 100.0
}

也可以透過 Kibana 檢視節點效果

踩過的坑


(1)如果修改了配置檔案的 http.porttransport.tcp.port 項,一定要將各個節點的值設定不同,否則會出現佔用的情況。正常如果不修改,預設會分配值。

(2)示例二開啟時,實體一報警告(實際操作中可以忽略,不然將無法實現 ES 的分散式叢集作用):

[2016-12-11T18:06:43,678][WARN ][o.e.d.z.ElectMasterService] [node-1] value for setting "discovery.zen.minimum_master_nodes" is too low. This can result in data loss! Please set it to at least a quorum of master-eligible nodes (current value: [-1], total number of master-eligible nodes used for publishing in this round: [2])

是因為預設情況下 discovery.zen.minimum_master_nodes=1 一臺伺服器只能有一個主節點,所以在實體二的配置檔案中可以新增 node.master: false

(3)示例二不能開啟,報如下錯誤:

[2016-12-11T16:53:02,711][INFO ][o.e.d.z.ZenDiscovery     ] [node-2] failed to send join request to master [{node-1}{vP19PMOyT2ilJKRAqgn78w}{jDULCExERXGHp4VXpbyuJA}{127.0.0.1}{127.0.0.1:9300}], reason [RemoteTransportException[[node-1][127.0.0.1:9300][internal:discovery/zen/join]]; nested: IllegalArgumentException[can't add node {node-2}{vP19PMOyT2ilJKRAqgn78w}{qhDDVzwZQ0GXZXhIMmpGKA}{127.0.0.1}{127.0.0.1:9301}, found existing node {node-1}{vP19PMOyT2ilJKRAqgn78w}{jDULCExERXGHp4VXpbyuJA}{127.0.0.1}{127.0.0.1:9300} with the same id but is a different node instance]; ]
[2016-12-11T16:53:02,911][INFO ][o.e.x.m.e.Exporters      ] [node-2] skipping exporter [default_local] as it isn't ready yet
[2016-12-11T16:53:02,912][ERROR][o.e.x.m.AgentService     ] [node-2] exception when exporting documents
org.elasticsearch.xpack.monitoring.exporter.ExportException: exporters are either not ready or faulty
   at org.elasticsearch.xpack.monitoring.exporter.Exporters.export(Exporters.java:188) ~[x-pack-5.0.2.jar:5.0.2]
   at org.elasticsearch.xpack.monitoring.AgentService$ExportingWorker.run(AgentService.java:208) [x-pack-5.0.2.jar:5.0.2]
   at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]

是因為複製的 elasticsearch 檔案夾下包含了 data 檔案中示例一的節點資料,需要把示例二 data 檔案下的檔案清空。

作者:wuxiwei

出處:http://t.cn/RIA6XFh

《Linux雲端計算及運維架構師高薪實戰班》2018年07月16日即將開課中,120天衝擊Linux運維年薪30萬,改變速約~~~~

    *宣告:推送內容及圖片來源於網路,部分內容會有所改動,版權歸原作者所有,如來源資訊有誤或侵犯權益,請聯絡我們刪除或授權事宜。

    – END –


    更多Linux好文請點選【閱讀原文】

    ↓↓↓

    贊(0)

    分享創造快樂