mac 下搭建Elasticsearch 5.4.3分布式集群
一、集群角色
多機集群中的節點可以分為master nodes和data nodes,在配置文件中使用Zen發現(Zen discovery)機制來管理不同節點。Zen發現是ES自帶的默認發現機制,使用多播發現其它節點。只要啟動一個新的ES節點並設置和集群相同的名稱這個節點就會被加入到集群中。
Elasticsearch集群中有的節點一般有三種角色:master node、data node和client node。
- master node:master幾點主要用於元數據(metadata)的處理,比如索引的新增、刪除、分片分配等。
- data node:data 節點上保存了數據分片。它負責數據相關操作,比如分片的 CRUD,以及搜索和整合操作。這些操作都比較消耗 CPU、內存和 I/O 資源;
- client node:client 節點起到路由請求的作用,實際上可以看做負載均衡器。( 對於沒有很多請求的業務,client node可以不加,master和data足矣)
二、基於2.X的集群配置
選取10.90.4.9這臺機器做為client node,elasticsearch.yml中的配置如下:
cluster.name: ucas node.name: node-09 node.master: true node.data: false network.host: 0.0.0.0 discovery.zen.ping.unicast.hosts: ["10.90.4.9"] discovery.zen.ping.multicast.enabled: true
註意端口不是9200,而是9300。也可以不寫端口。
啟動10.90.4.9上的es服務器,現在只是一個單機集群。
在10.90.4.8這臺機器上配置好同樣的ES作為master node,elasticsearch.yml中的配置如下:
cluster.name: ucas node.name: node-08 node.master: true node.data: true network.host: 0.0.0.0 discovery.zen.ping.unicast.hosts: ["10.90.4.9"] discovery.zen.ping.multicast.enabled: true
10.90.4.7作為data node,配置如下:
cluster.name: ucas node.name: node-07 node.master: false node.data: true network.host: 0.0.0.0 discovery.zen.ping.unicast.hosts: ["10.90.4.9"] discovery.zen.ping.multicast.enabled: true
訪問http://10.90.4.9:9200/_plugin/head/
如圖,node-09為client節點,不存儲數據。
三、基於5.4的多機集群配置
ELasticsearch 5.4要求JDK版本最低為1.8,由於服務器上的JDK版本為1.7並且Java環境變量寫在/etc/profile裏面,改JDK會影響其他程序,這次基於5.4在我的mac和另外一臺Ubuntu 做測試。
mac上的本機ip為192.168.1.111,設為master節點,配置如下:
cluster.name: my-application node.name: node-111 network.host: 192.168.1.111 http.port: 9200 http.cors.enabled: true http.cors.allow-origin: "*" node.master: true node.data: true discovery.zen.ping.unicast.hosts: ["192.168.1.111"]
Ubuntu機器的ip位192.168.1.102,配置如下:
cluster.name: my-application node.name: node-102 network.host: 192.168.1.102 http.port: 9200 http.cors.enabled: true http.cors.allow-origin: "*" node.master: false node.data: true discovery.zen.ping.unicast.hosts: ["192.168.1.111"]
先啟動mac上的master,再啟動Ubuntu上的slave節點,觀察輸出,會有一個node-102探測到master節點的提示:
2017-06-07T11:33:39,369][INFO ][o.e.c.s.ClusterService ] [node-102] detected_master {node-111}{3dQd1RRVTMiKdTckM68nPQ}{H6Zu7PAQRWewUBcllsQWTQ}{192.168.1.111}{192.168.1.111:9300}, added {{node-111}{3dQd1RRVTMiKdTckM68nPQ}{H6Zu7PAQRWewUBcllsQWTQ}{192.168.1.111}{192.168.1.111:9300},}, reason: zen-disco-receive(from master [master {node-111}{3dQd1RRVTMiKdTckM68nPQ}{H6Zu7PAQRWewUBcllsQWTQ}{192.168.1.111}{192.168.1.111:9300} committed version [8]])‘
訪問head,一個master一個slave組成集群,界面如下:
四、基於5.4的單機多節點集群配置
如果想要在一臺機器上啟動多個節點,步驟如下:
- 復制一份ELasticsearch的安裝包
- 修改端口,比如一個是9200,一個是9205
- 刪除data目錄下的數據(如果是新解壓的安裝包就不必了)
- 同時啟動兩個es
master配置文件:
cluster.name: myelasticsearch
node.name: node-1
network.host: 192.168.253.6
http.port: 9201
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master:true
node.data: true
discovery.zen.ping.unicast.hosts: ["192.168.253.6"]
data配置文件:
cluster.name: myelasticsearch
node.name: node-2
network.host: 192.168.253.6
http.port: 9201
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master:true
node.data: true
discovery.zen.ping.unicast.hosts: ["192.168.253.6"]
參考文獻:
http://blog.csdn.net/napoay/article/details/52202877
mac 下搭建Elasticsearch 5.4.3分布式集群