ElasticStack 官方文档阅读(集群管理篇)

决定通读一下ES官方文档,甚至于一起再读一些相关书籍,带大家一起感受一下在“大规模数据检索”这个领域,我们需要克服的若干问题,以及未来的还有何发展,进行自我认识和理解。

考试流程

  1. 安装Chrome 考试环境检测插件 : PSI In-application Extension (www.psionline.com)

Elastic Stack 产品一览

  1. ElasticSearch : 基于Lucene ,实现集群高可用,准实时PB级数据秒级响应
  2. Logstash : 服务器端数据处理管道,同时从多个来源采集数据,转换数据,然后将数据发送到ES这种数据存储引擎
  3. Kibana : 数据可视化,ES集群管理
  4. 各种Beats : 数据采集、监控端点
  5. Integrations
    • Web site crawler
    • Elastic APM
    • Endpoint Security
  6. Osquery Manager
  7. Ingest

ES 设置相关文档阅读记录

  1. 2022-02-24 - Elasticsearch Guide [8.0] » Set up Elasticsearch » Configuring Elasticsearch » Configuring Elasticsearch (部分实践)

    • 环境变量: ES_PATH_CONFES_HOME
    • 静态配置
    • 动态配置 : 瞬时配置、持久配置、配置文件、默认配置优先级依次降低
  2. 2022-02-24 - Elasticsearch Guide [8.0] » Set up Elasticsearch » Configuring Elasticsearch » Important Elasticsearch configuration (部分实践)

    • 路径 : 由于7.13之前的多数据路径配置方式不再支持,涉及单节点和高可用集群的滚动重启迁移
    • 集群名称 : 用于识别节点自组织成一个可用集群,注意防止出现两个集群命名冲突,导致加入错误节点到集群当中
    • 节点名称 : 友好标识,存在于各个返回结果中
    • 网络主机 : 默认本机环回地址,如果配置正常IP地址,则默认进入生产模式,不可不察
    • 互相发现 : 两个重要配置项,用于节点选举和互相发现并连接,其中,discovery.seed_hosts - 声明多个可以用来做master节点的主机地址(还可以动态外挂seeds provider),支持域名;
      cluster.initial_master_nodes配置说明 - 集群启动阶段本质是不安全的一个环境(inherently unsafe),所以在生产模式启动一个新的集群,就必须显式地从备选节点列表(seed_hosts)配置一个master nodes列表,在首次启动集群的时候,所以,注意的是,如果首次启动集群后,要把此项配置删除,避免影响后续集群增加新的节点或者重启集群。
    • JVM堆内存 : 根据节点角色和总内存,自动设置,也可以手动更改
    • 堆转储路径设置: 默认在数据路径下,保证文件是不存在的,让ES自动创建才能正常生成转储文件
    • GC日志 : 可以关闭之前的,重新设置适合的
    • 临时文件 : 存储启动过程或者临时脚本,避免系统误伤,还是需要多多注意,要从自动清除策略中排除一下。
    • JVM主要错误异常 : -XX:ErrorFile=...
    • 集群备份 : 快照生命周期管理是最简单的方式,官方明确告诉我们,不能拷贝数据目录,达到备份的目的 哇咔咔。。。
  3. 2022-02-24 - Elasticsearch Guide [8.0] » Set up Elasticsearch » Configuring Elasticsearch » Secure settings

    • keystore : 目前es使用keystore工具对安全配置项进行管理 ,并且对于keystore的改动,需要重启服务才能生效(一些配置可以标记成reloadable也是可以运行时生效的)
    • 每个节点,都需要指定独立为其配置安全配置项,并且在集群中所有节点的安全配置要保持一样的配置值
  4. 2022-02-24 - Elasticsearch Guide [8.0] » Set up Elasticsearch » Configuring Elasticsearch » Auditing security settings (未实践)

  5. 2022-02-24 - Elasticsearch Guide [8.0] » Set up Elasticsearch » Configuring Elasticsearch » Circuit breaker (未实践)

    • 目的解析 : 为了防止集群过载(占用内存和CPU的资源超过预期范围)
    • 除非特别说明,熔断配置,均可以通过PUT /_cluster/settings进行更新设置
    • 熔断配置 : 内存OOM
    • 熔断错误异常 : circuit_breaking_exception
    • 父熔断器 : indices.breaker.total.use_real_memory 配置ture OR false ???
    • 字段数据熔断器 : 字段数据默认占堆内存的40%以下
    • 请求熔断器:
    • 请求中熔断(?)
    • 占用熔断器 : Lucene的段
    • 脚本编译熔断器
    • 正则熔断器
  6. 2022-02-24 - Elasticsearch Guide [8.0] » Set up Elasticsearch » Configuring Elasticsearch » Cluster-level shard allocation and routing settings (未实践)

    • 在集群级别进行分片分配和路由设置
    • 目的解析 : 分片的分配处理程序,主要用于在集群内的节点上进行分片分配的工作,在recovery(?)replica allocation(?)rebalancing(?)nodes are added or removed(节点增减)的各个过程中执行,所以这些配置项,用于控制分片分配工作的力度、强度、广度、深度
    • 机制 : 由某一个属于master的角色的节点决定哪个节点需要怎么分配分片,以及何时移除分片(在节点处于rebalancing时)。一共有Cluster-level shard allocation settingsDisk-based shard allocation settingsShard allocation awareness and Forced awarenessCluster-level shard allocation filtering四个设置方式,对分片的规则进行控制和处理,不过还有个miscellaneous cluster-level settings(杂项设置)
  7. 2022-02-25 - Elasticsearch Guide [8.0] » Set up Elasticsearch » Configuring Elasticsearch » Cross-cluster replication settings (未实践)

    • 目的解析: 集群自我恢复的数据传输限速设置
    • 特别说明: 由于多节点,所以限制参数可能会有倍乘效应,致使网络压力高于预期,不可不察
  8. 2022-02-24 - Elasticsearch Guide [8.0] » Set up Elasticsearch » Configuring Elasticsearch » Discovery and cluster formation settings

    • 目的解析 : 集群编排设置,用于控制像seed_providersdiscovery.type的基本设置,以及find_peers_intervalhandshake_timeoutseed_resolver和集群网络连接管理与选举相关的一些高级控制参数
    • 特别说明: 有一些是可以动态生效的,但有一些是静态设置,需要注意
  9. 2022-02-25 - Elasticsearch Guide [8.0] » Set up Elasticsearch » Configuring Elasticsearch » Discovery and cluster formation settings (未实践)

  10. 2022-02-25 - Elasticsearch Guide [8.0] » Set up Elasticsearch » Configuring Elasticsearch » Secure settings

  11. 2022-02-25 - Elasticsearch Guide [8.0] » Set up Elasticsearch » Configuring Elasticsearch » Cross-cluster replication settings

    • 目的解析: 控制集群内部节点之间的数据复制过程的速率、大小、并行性等程度
  12. 2022-02-25 - Elasticsearch Guide [8.0] » Set up Elasticsearch » Starting Elasticsearch (已实践)

    • 目的解析 :配置启动一个集群,并加入新的节点的方式
    • 特别说明: 加入一个新的节点,要验证密钥(如果有),并且需要enrollingment token,以及不同的安装方式,对应的启动设置项以及预置参数方式有所不同
    • ./bin/elasticsearch-create-enrollment-token -s node 报错 ERROR: [xpack.security.enrollment.enabled] must be set to true to create an enrollment token
  13. 2022-02-25 - Elasticsearch Guide [8.0] » Command line tools » elasticsearch-keystore (部分实践)

    • 目的解析: 通过一个脚本命令,方便快捷管理ES安全认证所需要的密钥或者文件
  14. 2023-03-17 绑定和发布网络地址

    • 目的解析:通过http和tcp不同的层次,可以做到绑定不同的网络接口地址,通过操作系统达到不同的传输通道接收流量;而发布地址
    • 特别说明: 绑定地址,必须是操作系统网络接口里存在的地址;
  15. 2023-03-17 跨集群嗅探、复制、搜索

  16. 第一次启动集群节点的安全配置说明,

    • ES第一次自动配置安全配置项,如下:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24

      #----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
      #
      # The following settings, TLS certificates, and keys have been automatically
      # generated to configure Elasticsearch security features on 17-03-2023 03:06:34
      #
      # --------------------------------------------------------------------------------

      # Enable security features
      xpack.security.enabled: true
      xpack.security.enrollment.enabled: true

      # Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
      xpack.security.http.ssl:
      enabled: true
      keystore.path: certs/http.p12

      # Enable encryption and mutual authentication between cluster nodes
      xpack.security.transport.ssl:
      enabled: true
      verification_mode: certificate
      keystore.path: certs/transport.p12
      truststore.path: certs/transport.p12
      #----------------------- END SECURITY AUTO CONFIGURATION -------------------------
    • 后续节点加入,需要指定enroll token,但是不用显示配置地址列表等信息

    • 启动后忘记记录启动的临时密码怎么办?可以通过./node1/elasticsearch-8.1.0/bin/elasticsearch-keystore add "bootstrap.password" 进行重新设置,并重启服务

ES 设置实践

  1. 2022-02-24 - Elasticsearch Guide [8.0] » How to » Fix common cluster issues
  2. 安装单节点(默认方式)
  3. 安装单主机集群
  4. 安装多主机集群
  5. 安全配置项

backlogs

集群管理和监控

1
2
3
GET /_cluster/health?filter_path=status,*_shards
GET /_cat/shards?v=true&&h=index,shard,prirep,state,node,unassigned.reason&s=state:asc
GET /_cluster/state

TODO

  1. https://zhuanlan.zhihu.com/p/24832190 >> 对比match_field 的多字段查询不同的设置之间的区别,需要定义分词器
  2. Elasticsearch Guide [8.1] » REST APIs » Index APIs » Create or update index template API
  3. 拼音分词器

ES 文档阅读集合

部署问题备忘

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
[2022-02-22T10:45:01,248][INFO ][o.e.n.Node               ] [node1] node name [node1], node ID [OSC-vFuhQ9m7a-QmNKdJwA], cluster name [elasticsearch], roles [transform, data_content, data_warm, master, remote_cluster_client, data, data_cold, ingest, data_frozen, ml, data_hot]

[2022-02-22T10:45:12,825][INFO ][o.e.x.s.Security ] [node1] Security is enabled

[2022-02-22T10:45:13,336][INFO ][o.e.x.s.a.Realms ] [node1] license mode is [trial], currently licensed security realms are [reserved/reserved,file/default_file,native/default_native]

[2022-02-22T10:45:13,355][INFO ][o.e.x.s.a.s.FileRolesStore] [node1] parsed [0] roles from file [/home/es/elasticsearch-8.0.0/config/roles.yml]


[2022-02-22T10:45:28,934][INFO ][o.e.x.s.InitialNodeSecurityAutoConfiguration] [node1] HTTPS has been configured with automatically generated certificates, and the CA's hex-encoded SHA-256 fingerprint is [f14df1e36f05cf081a14f1db10dcf6d9bea63adb643624405be5798796a731dd]
[2022-02-22T10:45:28,935][INFO ][o.e.x.s.s.SecurityIndexManager] [node1] security index does not exist, creating [.security-7] with alias [.security]
[2022-02-22T10:45:29,164][INFO ][o.e.c.m.MetadataCreateIndexService] [node1] [.security-7] creating index, cause [api], templates [], shards [1]/[0]
[2022-02-22T10:45:29,244][INFO ][o.e.x.s.s.SecurityIndexManager] [node1] security index does not exist, creating [.security-7] with alias [.security]
[2022-02-22T10:45:29,280][INFO ][o.e.x.s.s.SecurityIndexManager] [node1] security index does not exist, creating [.security-7] with alias [.security]
[2022-02-22T10:45:29,638][INFO ][o.e.c.r.a.AllocationService] [node1] current.health="GREEN" message="Cluster health status changed from [YELLOW] to [GREEN] (reason: [shards started [[.security-7][0]]])." previous.health="YELLOW" reason="shards started [[.security-7][0]]"


Step 2 -

使用默认配置,会在终端生成以下自动安全配置项数据:
使用 openssl x509 -noout -fingerprint -sha256 -inform pem -in [certificate-file.crt] 手动输出指纹


━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ Elasticsearch security features have been automatically configured!
✅ Authentication is enabled and cluster connections are encrypted.

ℹ️ Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
kksL0F6KWO9PFu12DdNv

ℹ️ HTTP CA certificate SHA-256 fingerprint:
00f90d3259929dcafd7fb53bfe8ccb696d1b2a936fc8cd2270475ed49d6b4b12

ℹ️ Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjAuMCIsImFkciI6WyIxNzIuMTYuMTAuMTMxOjkyMDAiXSwiZmdyIjoiMDBmOTBkMzI1OTkyOWRjYWZkN2ZiNTNiZmU4Y2NiNjk2ZDFiMmE5MzZmYzhjZDIyNzA0NzVlZDQ5ZDZiNGIxMiIsImtleSI6IlRyRXhKbjhCNFZqS2tlRFlkcktaOlRxelBuaEVTUmppZllBYnhHYW1VeVEifQ==

ℹ️ Configure other nodes to join this cluster:
• Copy the following enrollment token and start new Elasticsearch nodes with `bin/elasticsearch --enrollment-token <token>` (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjAuMCIsImFkciI6WyIxNzIuMTYuMTAuMTMxOjkyMDAiXSwiZmdyIjoiMDBmOTBkMzI1OTkyOWRjYWZkN2ZiNTNiZmU4Y2NiNjk2ZDFiMmE5MzZmYzhjZDIyNzA0NzVlZDQ5ZDZiNGIxMiIsImtleSI6IlRMRXhKbjhCNFZqS2tlRFlkcktXOkN2ZThOMEpKUlZPU0NuVUswMGtSRWcifQ==

If you're running in Docker, copy the enrollment token and run:
`docker run -e "ENROLLMENT_TOKEN=<token>" docker.elastic.co/elasticsearch/elasticsearch:8.0.0`
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━


Step 3 - 启动kibana连接es

curl --cacert config/certs/http_ca.crt -u elastic https://localhost:9200 ====>>>
curl --cacert config/certs/http_ca.crt -u elastic https://node1.daqiang.me:9200 ====>>>

bin/elasticsearch-create-enrollment-token -s kibana --url "https://172.16.10.131:9200"


问题1 :elasticsearch 安装后,不要手动添加安全配置项,而是修改一下必要配置(节点名称等) ,直接启动即可,否则http证书不会自动生成(后续需要演练完全手动生成的过程)
问题2 :elasticsearch启动后,并不会自动生成certs,严格按照官方步骤,小心翼翼,白等半天,需要使用“curl --cacert config/certs/http_ca.crt -u elastic https://localhost:9200”,
问题3 :kibana 官方文档说是可以和es不在同一个主机,但是启动kibana,在同一主机上有“http://172.16.10.131:5601/?code=319176”这样的初始化链接生成,不在同一个主机上,则没有,这个问题还没发现是怎么导致的?

eyJ2ZXIiOiI4LjAuMCIsImFkciI6WyIxNzIuMTYuMTAuMTMxOjkyMDAiXSwiZmdyIjoiMDBmOTBkMzI1OTkyOWRjYWZkN2ZiNTNiZmU4Y2NiNjk2ZDFiMmE5MzZmYzhjZDIyNzA0NzVlZDQ5ZDZiNGIxMiIsImtleSI6IktpYWFMMzhCMXZ2ckVGbnpsYmd4OlJWLUNqMy0wVHNPVURHRno2TkkxVWcifQ==

https://www.elastic.co/guide/en/elasticsearch/reference/current/starting-elasticsearch.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/elasticsearch-keystore.html

// 加入新节点报错
ERROR: Skipping security auto configuration because this node is configured to bootstrap or to join a multi-node cluster, which is not supported.



https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-routing-field.html
- 对路由文档的路径计算公式,有疑问 ? 路由因子由路由分片数和主分片数的商决定; 然后由文档的路由哈希值对路由范围取模后,再取与路由因子的商值作为分片点,形象地说是:一个文档,经路由关键字化为哈希值后,对路由范围取模后,就是文档要选择的路由路径,但是要到分片还需要经过一次选择,那就是路径集要和分片集建立平均分组联系,即要取商值,用这个分好的“组因子”,还原出分片数,简图:
DOC_CODE_SET >(取模+取商是均分效应)> ?ROUTING_SHARED? <放大效应(一般倍数放大)< PRIMARY_SHARED_SET,如果把实际分片看成一种资源,那么耗费资源的量,用一个与之无关的量“路由分片数”进行缩放调节,让文档

三个公主,一百个媒婆,一万个慕名求亲者,均匀分配给公主进行选择?

定性分析和实践: 分片功能的本质是为了均衡容错高效的存取数据,重点在于怎么“分存”和“分取”,那如果加一个路由功能,让数据有目的的“分存”和“分取”是不是会有定向优化的高效效果产生?
定量分析和实践:

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-split-index.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-fields.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#script-fields