elasticsearch应用之分布式配置(四)

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

 

Caused by: java.lang.IllegalStateException: failed to obtain node locks, tried [[/opt/ES/elasticsearch-6.2.2/data/my-application]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
解决方法:

当我在开启多个elasticsearch 实例时,遇到上述异常,解决方法是:在 config/elasticsearch.yml文件中新增一个配置变量:

node.max_local_storage_nodes: 256 #replace 256 with another num that greater than 1

 访问http://10.90.4.9:9200/_plugin/head/

先启动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]])'

查看集群是否配置正确:http://192.168.1.197:9200/_cluster/health/?pretty

列出集群所有指数:

http://192.168.1.197:9200/_cat/indices?v

 ES官方网址:https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started.html

posted on 2018-03-20 15:04  让代码飞  阅读(188)  评论(0)    收藏  举报

导航

一款免费在线思维导图工具推荐:https://www.processon.com/i/593e9a29e4b0898669edaf7f?full_name=python