暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

ELK 之 Elasticsearch 8 配置总览,节点和集群Discovery 配置

小数据自留地 2023-01-28
2780

随着疫情恢复,业务量和日志量继续暴涨,最近还在继续保障Elasticsearch服务, 需要到给ES集群继续添加节点。这里再重新梳理下ES节点需要关注的配置,在学习的过程中发现铭毅天下大佬都已经写过相当细的文章,后文做个抛砖引玉。需要注意的是本文仍然是针对ES 8.2,和在ES 7 之前的版本还是存在一些差别。

Elasticsearch 配置总览


ES的官方文档明确指出,ES的默认配置已经非常不错,需要修改的都针对服务器和集群具体情况个性化调整的地方,这一点比其他hadoop生态的系统要做得人性化很多,Hadoop上手就得做各种配置调优。

ES提供基于节点上静态文件配置和cluster update settings API 二种方式进行集群配置。关于cluster update settings API,updates made using the cluster update settings API can be persistent, which apply across cluster restarts, or transient, which reset after a cluster restart.  在通过api方式设定的配置,persistent会一直生效,transient在重启后配置就失效了。同样的配置生效的优先级如下

  1. Transient setting

  2. Persistent setting

  3. elasticsearch.yml setting

  4. Default setting value


节点上的配置文件应该只包括针对该节点node-specific的配置, 每个节点都包括如下3个配置文件:

  • elasticsearch.yml for configuring Elasticsearch

  • jvm.options for configuring Elasticsearch JVM settings

  • log4j2.properties for configuring Elasticsearch logging


Log4j配置基本不需要改动,jvm 作为每个大数据项目都避不开的调优,在ES下直接使用默认配置就好,这里还是说明一下默认配置:

  • JDK: ES 8.2 使用的是自带的 openjdk 18

  • GC:使用的G1GC(14-:-XX:+UseG1GC) 

  • JVM heap:By default, Elasticsearch automatically sets the JVM heap size based on a node’s roles and total memory. Using the default sizing is recommended for most production environments.  ES使用节点内存的50% 作为 Xms 和 Xmx, 一般不超过32G


唯一需要个性化调整的节点配置文件为elasticsearch.yml, 其中需要重点了解的配置项为node.roles 节点角色和集群发现 Discovery

Elasticsearch 8 节点角色


关于Elasticsearch 8节点的相关知识,强烈建议先阅读铭毅天下大佬的这篇文章Elasticsearch 8.X 节点角色划分深入详解。文章非常详细的分析了ES 8 后升级ES节点角色,我们自身现在还是聚焦于master节点和data 节点二种主要类型,其他的协调,ingest等功能性节点,我们暂时没有用到。

Master node: lightweight cluster-wide actions such as creating or deleting an index, tracking which nodes are part of the cluster, and deciding which shards to allocate to which nodes. 主要负责集群层面的管理,创建和删除索引,分片的部署位置等。这点和Hbase的master node所承担的责任类似。Master nodes must have a path.data directory whose contents persist across restarts, just like data nodes, because this is where the cluster metadata is stored. The cluster metadata describes how to read the data stored on the data nodes, so if it is lost then the data stored on the data nodes cannot be read. 在数据存储方面,master node还存储了集群的元数据,记录了数据如何在数据节点上存储的。这点类似HDFS 的namenode的功能, 同样这个也会导致如果master节点全部都挂掉了,数据将无法在进行读写,这点和Hbase集群不同的,高可用的集群最好还是要配置最少3个Master节点。

Data node:   hold the shards that contain the documents you have indexed. Data nodes handle data related operations like CRUD, search, and aggregations. 数据落地存储、数据增、删、改、查、搜索、聚合操作等处理操作。ES在文档中特别强调了:master , data_content和data_hot(or data) 是一个集群必不可少的, 我们的集群就曾经出现过因为data_content所在的节点挂掉了,导致集群无法登录的情况: 小数据之ELK 8 之 built-in users故障

Discovery


配置文件中的Discovery部分可以配置很多选型,最核心的和必须部分就是discovery.seed_hosts,在最简配置的情况下也只需要配置这一个参数即可。关于这一块的知识点可以先看看铭毅天下大佬的 关于 Elasticsearch 集群核心配置,腾讯大佬的灵魂9问,你能接住几个。这里再将官方文档中的discovery.seed_hosts和cluster.initial_master_nodes 说明记录下

  • discovery.seed_hosts: Provides a list of the addresses of the master-eligible nodes in the cluster. 配置候选主节点,每次启动都需要,每个节点都需要配置。


  • cluster.initial_master_nodes:Sets the initial set of master-eligible nodes in a brand-new cluster. By default this list is empty, meaning that this node expects to join a cluster that has already been bootstrapped. Remove this setting once the cluster has formed. Do not use this setting when restarting nodes or when adding new nodes to an existing cluster.仅在集群首次启动会使用,在集群组成后删除,节点重启前或者新节点加入老集群都不需要配置这个。


小结


谈到ELK,大家首先想到的会是倒排索引,分词器这些,从运维的角度来看,节点集群配置这些知识仍然是基本功,是作为一个大数据运维的本手,理解好这些才能做好ES集群的高可用的保障。

文章转载自小数据自留地,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论