Elastic Certified Engineer复习记录-集群配置-题目篇

文章目录

  • 前言
  • 集群组建
    • 1. 集群的发现和单一节点的配置
    • 2. 地址绑定、端口监听及节点彼此发现的配置
    • 3. 防止脑裂,设置初始推荐master节点
    • 4. 节点身份设置
    • 5. 关闭系统交换区
    • 6. 配置JVM参数
    • 7.配置log参数
    • 8.禁止通过模糊匹配删除索引
    • 9.总结
    • 10.参考文献

前言

对应考纲里的
Installation and Configuration
Configure the nodes of a cluster to satisfy a given set of requirements

Secure a cluster using Elasticsearch Security

集群组建

这里最基本的就是网段中的节点能通过什么方式发现彼此,认为大家是一个集群的,还不会出现脑裂的问题。

1. 集群的发现和单一节点的配置

Deploy the cluster `eoc-01-cluster`, so that it satisfies the following requirements:
(i)   has three nodes, named `node1`, `node2`, and `node3`,
(ii)  all nodes are eligible master nodes

题目里说我们需要部署一个叫eoc-01-cluster的集群,那我们只需要在$ES_HOME/config/elasticsearch.yml里填上cluster.name: eoc-01-cluster就好。因为在同一个局域网中,ES的节点们会尝试用cluster name来进行第一步的彼此发现。

然后有两条要求:
第一个是需要有仨节点,分别叫node1, node2, and node3,我们就需要在每个节点的elasticsearch.yml里填上cluster.name之外,给他们每个人一个名字,node.name: node1,这个节点名称并没有强制要求唯一,但是为了后续的使用和运维的方便,我们在真正使用的时候还是建议每个节点给出一个好用的名字,比如:${产线名称}-${产品名称}-${集群名称}-${环境}-${IP地址中的最后一位} =》 fin-earning-text-prod-192之类的。

第二个是所有节点都有master资格,那我们只需要再添一行node.master: true就完成了。一般情况,我们在配置集群节点身份的时候需要考虑的是node.masternode.datanode.ingest这仨属性,分别代表了是否有资格成为master节点、data节点和ingest节点。

那么在这一题中,我们的配置文件如下(以node1为例,node2、node3类似,下同):

cluster.name: eoc-01-cluster
node.name: node1
node.master: true

2. 地址绑定、端口监听及节点彼此发现的配置

Bind `node1` to the IP address “151.101.2.217” and port “9201”
Bind `node2` to the IP address “151.101.2.218” and port “9202”
Bind `node3` to the IP address “151.101.2.219” and port “9203”
Configure the cluster discovery module of `node2` and `node3` so as to use `node1` as seed host

题目中说我们需要把node1绑定IP地址151.101.2.217,以及端口9201,这就用到了配置中的http.hosthttp.port两个配置了,他们分别代表了监听/绑定的地址和端口信息。在实际使用中,特别是在单节点多实例的使用中,这两个属性十分常见。

那么在这一题中,我们的配置文件如下:

http.host: 151.101.2.217
http:port: 9201

3. 防止脑裂,设置初始推荐master节点

Configure the nodes to avoid the split brain scenario

在集群启动过程中,我们无法保证所有节点都同时启动,所以当出现满足集群启动但是存在偶数个master节点的候选节点在进行选举的过程的时候,很容易出现脑裂的问题,这时ES通过initial_master_nodes这个参数来指定初始化master节点,以避免这种情况出现。

那么在这一题中,我们的配置文件如下:

initial_master_nodes: ["node1"]

4. 节点身份设置

Configure `node1` to be a data node but not an ingest node
Configure `node2` and `node3` to be both an ingest and data node

在1.里面我们曾经对节点的master资格进行过设置,在这一题中我们需要对他们重新进行一些定义。

这题分两部分,第一部分是设置node1作为一个data node,但是不能是ingest node,那我们就需要在node1的配置文件中指定三个属性(因为他是data node的话就不能是master node了),node.master: falsenode.data: truenode.ingest: false

第二部分是设置node2和node3可以同时作为ingest和data node,一样的,他们也不能成为master node,我们就需要将上面三个属性设置成:node.master: falsenode.data: truenode.ingest: true

那么这题中,我们的配置文件就会成这样:
node1:

node.master: false 
node.data: true 
node.ingest: false 

node2:

node.master: false 
node.data: true 
node.ingest: false 

5. 关闭系统交换区

Configure `node1` to disallow swapping on its host

对于承载ES节点的无论物理机还是虚拟机,他们都默认会开启交换区,因为他们都会尽可能完全使用文件系统缓存,并尝试把不用的应用内存换出去,但是这样一来,有可能会影响一部分JVM的堆栈区甚至导致它的运行页被换到硬盘上去。因此,这种内存交换可能会影响到ES的响应性能,比如GC的过程变得很长(STW的时间也会相应变长)所带来的节点响应慢,集群状态上报超时以至于节点被标记为离线,在一个分布式的系统中,这样的节点可能会被标记为不可用或进入重启流程等。

#官网资料的描述如下:

Most operating systems try to use as much memory as possible for file system caches and eagerly swap out unused application memory. This can result in parts of the JVM heap or even its executable pages being swapped out to disk.

Swapping is very bad for performance, for node stability, and should be avoided at all costs. It can cause garbage collections to last for minutes instead of milliseconds and can cause nodes to respond slowly or even to disconnect from the cluster. In a resilient distributed system, it’s more effective to let the operating system kill the node.

在这题中,明确要求在node1中关闭交换区,所以我们需要在命令行中执行以下命令:sudo swapoff -a

6. 配置JVM参数

Configure the JVM settings of each node so that it uses a minimum and maximum of 8 GB for the heap

我们知道,ES是一个运行在JVM上的Java项目,所以它的调优中很重要的一环就是JVM的调优。

所以这一题中,我们需要在$ES_HOME/config/jvm.options设置XmxXms这俩参数:

-Xms8g
-Xmx8g

我在文章 集群配置 里提到过两个JVM参数的配置建议、理由等,这里不再赘述。

7.配置log参数

Configure the logging settings of each node so that
	(i)  the logs directory is not the default one,
	(ii) the log level for transport-related events is "debug"

ES的log用的是log4j的,所以当我们遇到需要自定义一些日志输出的时候,只需要修改$ES_HOME/config/log4j2.properties里相关的内容就好。

在这一题中,首先提到了让logs目录不在默认位置,那么我们首先想到的是之前elasticsearch.yml文件里的path.logs,那么这里我们只需要将这个值的注释放开,然后在后面填上需要的路径就好,但是要注意,这个路径需要存在而且启动ES实例的用户要有写入权限,否则会报错。

题目第二部分说到,对于transport相关行为的日志设置成debug level的。这里其实会有很多种修改方式:

  1. 在我们修改elasticsearch.yml的时候,可以直接在后面加一行logger.org.elasticsearch.transport: debug,只要相关的日志key是正确的,那么在节点生效的时候就可以直接将这个配置进行加载和生效。
  2. 修改刚才提到的log4j2.properties,添加transport相关的属性:
logger.transport.name = org.elasticsearch.transport
logger.transport.level = debug
  1. 在启动ES实例的命令中通过-E ${params}的方式将这个配置传进去,比如:
bin/elasticsearch -E logger.org.elasticsearch.transport=debug
  1. 通过集群配置接口_cluster/settings修改集群配置,比如:
PUT /_cluster/settings
{
  "transient": {
    "logger.org.elasticsearch.transport": "debug"
  }
}

这里需要highlight一下的是:

  1. 我们一般使用的时候,推荐修改log4j2.properties的方式,其次是修改elasticsearch.yml的方式,因为这样一来在我们下次的节点重启时,这些日志的配置也能生效,而且当有其他同学需要参与相关配置的修改的时候,可以很方便的找到我们当时的配置。
  2. 其次是通过修改集群配置的方式进行修改,虽然这个修改可以设置成永久的(persistent),但是没有相关的文档、知识的传承,可能很难保证以后的使用中能知道这个配置的存在。
  3. 最不推荐的是通过启动参数的方式进行修改,因为如果不是单节点调试的情况,我们可能会把这个参数写在启动脚本里,可能对大多数人来说根本不可能想到这种额外参数的存在,因为这种方式十分冷门,甚至说几乎没人知道和使用。

8.禁止通过模糊匹配删除索引

Configure the nodes so as to disable the possibility to delete indices using wildcards

我们知道,ES的各种针对索引名称的命令基本上都支持包括[?]、[*]等通配符进行模糊匹配的方式进行指定,对于删除索引的接口也一样,但是对于删除索引的操作,ES的接口包括Kibana里面都是可以直接进行删除不需要确认的,而且,索引的删除操作基本上可以说是不可逆的。那么这样一来就存在如果通配符编写失误造成某些索引的误删除的风险。
这题里提到,希望我们通过配置将模糊匹配索引名称进行删除的功能禁用掉。那么就需要用到ES中关于索引删除的一个配置action.destructive_requires_name了,这个配置字面意思是对于破坏性的操作(比如删除索引),需要指定名字。那么还是一样,我们有几种方式可以禁止:

  1. 修改elasticsearch.yml文件,在里面加入action.destructive_requires_name: true
  2. 通过集群配置接口_cluster/settings修改集群配置,比如:
PUT /_cluster/settings
{
  "transient": {
    "action.destructive_requires_name": "false"
  }
}

这里也是,我们会首先推荐第一种方式,其次是第二种。

9.总结

在本文中,我们以一组复习大纲为主线,了解了ECE考试中集群配置方面的基础操作,包括了:

  1. 集群中节点的启动
  2. 集群组网
  3. 节点身份设置
  4. 防止脑裂
  5. 交换区禁止
  6. 配置JVM参数
  7. 配置log参数
  8. 禁止通过模糊匹配方式删除索引

最终我们的配置文件们可能成为的样子:
elasticsearch.yml:

# 集群组网
cluster.name: eoc-01-cluster
#节点身份设置
node.name: node1
node.master: true
#节点ip、端口绑定
http.host: 151.101.2.217
http:port: 9201
#防止脑裂
initial_master_nodes: ["node1"]
#自定义日志输出
path.logs: /usr/local/logs/
logger.org.elasticsearch.transport: debug
#禁止模糊匹配删除索引
action.destructive_requires_name: true

jvm.options

-Xms8g
-Xmx8g

大家可以对照上面的题目自己设置和练习一下。

10.参考文献

节点配置
=》 [7.2] » Modules » Node
禁用交换区
=》[7.2] » Set up Elasticsearch » Important System Configuration » Disable swapping
日志配置
=》[7.2] » Set up Elasticsearch » Configuring Elasticsearch » Logging configuration

你可能感兴趣的:(ECE考试)