mac 下搭建Elasticsearch 5.4.3分布式集群

一、集群角色

多机集群中的节点可以分为master nodes和data nodes,在配置文件中使用Zen发现(Zen discovery)机制来管理不同节点。Zen发现是ES自带的默认发现机制,使用多播发现其它节点。只要启动一个新的ES节点并设置和集群相同的名称这个节点就会被加入到集群中。

Elasticsearch集群中有的节点一般有三种角色:master node、data node和client node。

  1. master node:master几点主要用于元数据(metadata)的处理,比如索引的新增、删除、分片分配等。
  2. data node:data 节点上保存了数据分片。它负责数据相关操作,比如分片的 CRUD,以及搜索和整合操作。这些操作都比较消耗 CPU、内存和 I/O 资源;
  3. 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的单机多节点集群配置

如果想要在一台机器上启动多个节点,步骤如下:

  1. 复制一份ELasticsearch的安装包
  2. 修改端口,比如一个是9200,一个是9205
  3. 删除data目录下的数据(如果是新解压的安装包就不必了)
  4. 同时启动两个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

 

posted @ 2017-08-25 10:54  小啊菜鸡  阅读(1061)  评论(0编辑  收藏  举报