08.ES 集群搭建

2019-12-14  本文已影响0人  哈哈大圣

ES 集群搭建

一、节点分配

案例:创建一个2节点的集群,索引的分片设置为2,每片一个副本。

1). 节点的三个角色

  1. 【主节点】: master节点主要用于集群的管理及索引 比如新增结点、分片分配、索引的新增和删除等。
  2. 【数据结点】: data 节点上保存了数据分片,它负责索引和搜索操作。
  3. 【客户端结点】: client 节点仅作为请求客户端存在,client的作用也作为负载均衡器,client 节点不存数据,只是将请求均衡转发到其它结点。

2). 配置节点的参数

  1. node.master: #是否允许为主结点。
  2. node.data: #允许存储数据作为数据结点。
  3. node.ingest: #是否允许成为协调节点。

3). 节点以及其他类型

  1. 节点:每个服务器为一个节点(一个ES进程)
  2. 分片:每个分片为一个独立的lucene实例,保存了部分的索引等信息
  3. 副本:对提高分片的高可用性,与对应的分片存储在不同的服务器节点上
  4. 主节点:管理集群,增加. 移除节点等,主节点挂掉后会重新选举一个新的节点

4). 四种组合方式

  1. master=true data=true:即是主结点又是数据结点
  2. master=false data=true:仅是数据结点
  3. master=true data=false:仅是主结点,不存储数据
  4. master=false data=false:即不是主结点也不是数据结点,此时可设置ingest为true表示它是一个客户端。

二、配置节点

1). 配置节点1

  1. 解压elasticsearch-6.2.1.zip到 ~\elasticsearch-6.2.1\1
  2. 结点1对外服务的http端口是:9200
  3. 集群管理端口是9300
  4. 配置elasticsearch.yml
  5. 结点名:xc_node_1
  6. elasticsearch.yml
cluster.name: xuecheng
node.name: xc_node_1
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["0.0.0.0:9300", "0.0.0.0:9301"]
discovery.zen.minimum_master_nodes: 1
node.ingest: true
bootstrap.memory_lock: false
node.max_local_storage_nodes: 2
path.data: D:\elasticSearch\elasticsearch-01\data
path.logs: D:\elasticSearch\elasticsearch-01\logs
http.cors.enabled: true
http.cors.allow-origin: /.*/

1). 配置节点2

  1. 解压elasticsearch-6.2.1.zip到 ~\elasticsearch-6.2.1\2
  2. 结点2对外服务的http端口是:9201
  3. 集群管理端口是9302
  4. 配置elasticsearch.yml
  5. 结点名:xc_node_2
  6. elasticsearch.yml
cluster.name: xuecheng
node.name: xc_node_2
network.host: 0.0.0.0
http.port: 9201
transport.tcp.port: 9301
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["0.0.0.0:9300", "0.0.0.0:9301"]
discovery.zen.minimum_master_nodes: 1
node.ingest: true
bootstrap.memory_lock: false
node.max_local_storage_nodes: 2
path.data: D:\elasticSearch\elasticsearch-02\data
path.logs: D:\elasticSearch\elasticsearch-02\logs
http.cors.enabled: true
http.cors.allow-origin: /.*/

三、创建索引及管理

1). 创建索引

  1. 使用head连接上其中一个节点
  2. 创建索引库,共2个分片,每个分片一个副本。

2). 集群的健康

  1. 通过访问 GET http://localhost:9200/_cluster/health 来查看ElasticSearch的集群健康情况。
    • green : 一切正常
    • yellow: 所有主分片正常,某些副本不正常
    • red: 存在主分片不正常

3). 添加一个节点

  1. http端口是:9202
  2. 集群管理端口是9302
  3. 结点名:xc_node_3
cluster.name: xuecheng
node.name: xc_node_3
network.host: 0.0.0.0
http.port: 9202
transport.tcp.port: 9302
node.master: false
node.data: true
discovery.zen.ping.unicast.hosts: ["0.0.0.0:9300", "0.0.0.0:9301"]
discovery.zen.minimum_master_nodes: 1
node.ingest: true
bootstrap.memory_lock: false
node.max_local_storage_nodes: 2
path.data: D:\elasticSearch\elasticsearch-03\data
path.logs: D:\elasticSearch\elasticsearch-03\logs
http.cors.enabled: true
http.cors.allow-origin: /.*/
上一篇 下一篇

猜你喜欢

热点阅读