4.Elasticsearch集群部署详解

原文地址:blog.csdn.net/laoyang360 https://blog.csdn.net/wojiushiwo987/article/details/72850834

1、题记

之前应用都是Elasticsearch单节点,随着业务的拓展、数据量的增多,部署分布式Elasticsearch刻不容缓。

本文以Elaticsearch2.3.4版本为基础,讲解Elasticsearch三个节点的分布式部署、核心配置的含义以及分布式部署遇到的坑。

2、三节点 Elasticsearch 分布式部署。

步骤1:配置好主节点Master信息。

# ======================== Elasticsearch Configuration =========================
 13 # ---------------------------------- Cluster -----------------------------------
 14 #
 15 # Use a descriptive name for your cluster:
 16 # 簇名称,分布式部署,确保该名称唯一。
 17 cluster.name: my-application
 18 #
 19 # ------------------------------------ Node ------------------------------------
 20 #
 21 # Use a descriptive name for the node:
 22 # 节点名称
 23 node.name: laoyng
 24 node.master: true
 25 node.data: true
 26 #
 27 # Add custom attributes to the node:
 28 #
 29 # node.rack: r1
 30 #
 31 # ----------------------------------- Paths ------------------------------------
 32 # 数据存储
 33 # Path to directory where to store the data (separate multiple locations by comma):
 34 #
 35 path.data: /data/elasticsearch/data
 36 path.logs: /data/logs/elasticsearch
 37 path.plugins: /data/elasticsearch/plugins
 38 path.scripts: /data/elasticsearch/scripts
 39 #
 40 # Path to log files:
 41 #
 42 # path.logs: /path/to/logs
 43 #
 44 # ----------------------------------- Memory -----------------------------------
 45 #
 46 # Lock the memory on startup:
 47 #
 48 bootstrap.mlockall: true
 49 #
 50 # Make sure that the `ES_HEAP_SIZE` environment variable is set to about half the memory
 51 # available on the system and that the owner of the process is allowed to use this limit.
 52 #
 53 # Elasticsearch performs poorly when the system is swapping the memory.
 54 #
 55 # ---------------------------------- Network -----------------------------------
 56 #
 57 # Set the bind address to a specific IP (IPv4 or IPv6):
 58 # IP地址
 59 network.host: 110.10.11.130
 60 #
 61 # Set a custom port for HTTP:
 62 # 端口
 63 http.port: 9200

 68 # --------------------------------- Discovery ----------------------------------
 69 #
 70 # Pass an initial list of hosts to perform discovery when new node is started:
 71 # The default list of hosts is ["127.0.0.1", "[::1]"]
 76 discovery.zen.ping.unicast.hosts: [" 110.10.11.130 :9300", "10.118.110.112:9300", "110.0.11.143:9300"]
 77 # Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
 78 #
 79 # discovery.zen.minimum_master_nodes: 3
 80 #
 81 discovery.zen.minimum_master_nodes: 2
 82 # For more information, see the documentation at:
 85 # ---------------------------------- Gateway -----------------------------------
 86 #
 87 # Block initial recovery after a full cluster restart until N nodes are started:
 88 #
 89 # gateway.recover_after_nodes: 3
 90 gateway.recover_after_nodes: 3
 91 gateway.recover_after_time: 5m
 92 gateway.expected_nodes: 1
 93 #
 97 # ---------------------------------- Various -----------------------------------
 98 #
 99 # Disable starting multiple nodes on a single system:
100 #
101 # node.max_local_storage_nodes: 1
102 #
103 # Require explicit names when deleting indices:
104 #
105 # action.destructive_requires_name: true
106 #index.analysis.analyzer.ik.type : “ik”
107 script.engine.groovy.inline.search: on
108 script.engine.groovy.inline.aggs: on
109 indices.recovery.max_bytes_per_sec: 100mb
110 indices.recovery.concurrent_streams: 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87

步骤2:拷贝到节点2 cient节点;修改节点名称信息。

只列举不一样的配置:

node.name: laoyng02
node.master: true
node.data: false
network.host: 10.118.110.112
  • 1
  • 2
  • 3
  • 4

步骤3:拷贝到节点3 data节点;修改节点名称

只列举不一样的配置:

node.name: laoyng03
node.master: false
node.data:  true
network.host:  110.0.11.143
  • 1
  • 2
  • 3
  • 4

步骤4:分别运行Master,client,data节点(顺序无关)

./elasticsearch -d
  • 1

部署成功标志

这里写图片描述

2、部署节点原理

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

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

1)master node——master节点点主要用于元数据(metadata)的处理,比如索引的新增、删除、分片分配等。 
2)client node——client 节点起到路由请求的作用,实际上可以看做负载均衡器。

3)data node——data 节点上保存了数据分片。它负责数据相关操作,比如分片的 CRUD,以及搜索和整合操作。这些操作都比较消耗 CPU、内存和 I/O 资源;

3.elasticearch配置含义解释

1)集群名和节点名:

#cluster.name: elasticsearch
#node.name: "Franz Kafka"
  • 1
  • 2

2)是否参与master选举和是否存储数据

#node.master: true
#node.data: true
  • 1
  • 2

3)分片数和副本数

#index.number_of_shards: 5
#index.number_of_replicas: 1
  • 1
  • 2

4)master选举最少的节点数,这个一定要设置为N/2+1,其中N是:具有master资格的节点的数量,而不是整个集群节点个数。

#discovery.zen.minimum_master_nodes: 2
  • 1

5)discovery ping的超时时间,拥塞网络,网络状态不佳的情况下设置高一点

#discovery.zen.ping.timeout: 3s
  • 1

6)关闭自动发现节点:

discovery.zen.ping.multicast.enabled: false
  • 1

单播模式安全,也高效,但是缺点就是如果增加了一个新的机器的话,就需要每个节点上进行配置才生效了。

多播是需要看服务器是否支持的,由于其安全性,其实现在基本的云服务(比如阿里云)是不支持多播的,所以即使你开启了多播模式,你也仅仅只能找到本机上的节点。

7)定义发现的节点:

discovery.zen.ping.unicast.hosts: [" 110.10.11.130 :9300", "10.118.110.112:9300", "110.0.11.143:9300"]
  • 1

此处也可以写成hostname的形式。 
注意,分布式系统整个集群节点个数N要为奇数个!!

4、分布式部署遇到的坑

三节点不能联通的原因:

1、各节点的hostname没有正确设置,和节点名称设置为一致。

2、关闭防火墙,service iptables stop;否则,打开防火墙会导致无法正常通信,head插件不能看到节点数据信息。

参考: 
1、[官网部署参考]: 
https://www.elastic.co/guide/en/elasticsearch/guide/current/deploy.html

2、http://blog.csdn.net/napoay/article/details/52202877

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值