弹性设计

小集群中的弹性

1:单节点和双节点,不能保证高可用,且当双节点时,两个节点都设置成master,当其中一个异常,另一个选举master时也会出现异常,所有双节点时,需要将一个设置成master,另一个设置成非master。
2:三节点时,为防止脑裂,discovery.zen.minimum_master_nodes设置成(master/2)+1,取整。此值默认为1
3:只要满足以下条件,集群就可以抵抗任何节点的丢失:

  • 集群运行状况为绿色。
  • 至少有两个数据节点。
  • 除主分片外,每个索引还具有每个分片的至少一个副本。
  • 该集群至少具有三个符合主机要求的节点,只要这些节点中的至少两个不是仅投票的符合主机要求的节点即可。
  • 客户端被配置为将其请求发送到多个节点,或者被配置为使用负载均衡器,以在一组适当的节点之间平衡请求。 Elastic Cloud 服务提供了这样的负载均衡器。

    较大组中的弹性

    跨集群搜索

    集群备份

    备份数据

    设置备份文件地址

  • 在elasticsearch.yml 新增

    1. path.repo: ["/home/es/snapshot"]

    注册快照存储库

    1. PUT _snapshot/ecopherebbs
    2. {
    3. "type": "fs",
    4. "settings": {
    5. "location": "/home/es/snapshot"
    6. }
    7. }

查看快照存储库保存结果

  1. GET _snapshot

创建快照

异步创建

  • 创建

    1. PUT _snapshot/ecopherebbs/snapshot_20210631
    2. {
    3. "ignore_unavailable": true,
    4. "include_global_state": true
    5. }
  • 查看状态

    1. GET _snapshot/ecopherebbs/snapshot_20210631
    2. #返回值
    3. #"state" : "IN_PROGRESS" 进行中
    4. #"state" : "SUCCESS" 完成

    指定索引进行快照

    1. PUT _snapshot/ecopherebbs/snapshot_20210630?wait_for_completion=true
    2. {
    3. "indices": "index1,index2",
    4. "ignore_unavailable": true,
    5. "include_global_state": true
    6. }
    1. wait_for_completion=true时会一直阻塞直到快照完成,kibana执行时超时为30秒,超时后快照依然会在后台执行
    2. snapshot_20200729 就是指定的备份快照命中
    3. 请求体重indices指定需要备份的索引(多个用逗号隔开),也可以不指定,这样会备份所有的es索引库数据

      在服务器查看备份的数据

      1. [es@test12 snapshot]$ ls -lrt
      2. 总用量 1404
      3. drwxrwxr-x. 62 es es 4096 6 30 13:23 indices
      4. -rw-rw-r--. 1 es es 460329 6 30 13:24 meta--WCM58RpQNm5bEywCjO_cg.dat
      5. -rw-rw-r--. 1 es es 1596 6 30 13:24 snap--WCM58RpQNm5bEywCjO_cg.dat
      6. -rw-rw-r--. 1 es es 1596 6 30 13:26 snap-PTBkWV-pQ8CQ7l4RNxISfA.dat
      7. -rw-rw-r--. 1 es es 460329 6 30 13:26 meta-PTBkWV-pQ8CQ7l4RNxISfA.dat
      8. -rw-rw-r--. 1 es es 302 6 30 13:52 snap-N3zRMDnDTEqoiShEwjKosA.dat
      9. -rw-rw-r--. 1 es es 460329 6 30 13:52 meta-N3zRMDnDTEqoiShEwjKosA.dat
      10. -rw-rw-r--. 1 es es 24990 6 30 13:52 index-2
      11. -rw-rw-r--. 1 es es 8 6 30 13:52 index.latest

      恢复数据

      本机恢复

      1. POST _snapshot/ecopherebbs/snapshot_20210631_02/_restore
      执行恢复要将之前的索引删除,否则会报错
  • 或者在恢复时执行新索引名称 官网描述

    1. POST /_snapshot/my_backup/snapshot_1/_restore
    2. {
    3. "indices": "index_1",
    4. "rename_pattern": "index_(.+)",
    5. "rename_replacement": "restored_index_$1"
    6. }

    其他服务器恢复

  1. 配置第一步设置的目录
    path.repo: [“/home/es/snapshot”]
  2. 创建仓库

    1. PUT _snapshot/ecopherebbs
    2. {
    3. "type": "fs",
    4. "settings": {
    5. "location": "/home/es/snapshot-test"
    6. }
    7. }
  3. 执行恢复索引

    1. POST _snapshot/ecopherebbs/snapshot_20210631_02/_restore

    常见问题

    报错 doesn’t match any of the locations specified by path.repo because this setting is empty

    1. {
    2. "error" : {
    3. "root_cause" : [
    4. {
    5. "type" : "repository_exception",
    6. "reason" : "[ecopherebbs] location [/home/es/snapshot] doesn't match any of the locations specified by path.repo because this setting is empty"
    7. }
    8. ],
    9. "type" : "repository_exception",
    10. "reason" : "[ecopherebbs] failed to create repository",
    11. "caused_by" : {
    12. "type" : "repository_exception",
    13. "reason" : "[ecopherebbs] location [/home/es/snapshot] doesn't match any of the locations specified by path.repo because this setting is empty"
    14. }
    15. },
    16. "status" : 500
    17. }
  • 解决方法:

在为es集群环境做灾备和恢复时候,首先需要创建创建一个仓库,并往仓库中存放快照(每个快照中会区分不同的索引)。但是在创建仓库的时候,要求仓库的地址必须在每个集群环境中的elasticsearch.yml中进行配置

备份集群配置

这个一般备份 ES_PATH_CONF目录中的一些配置即可。

备份安全配置

安全配置信息位于两个位置:文件和索引。
备份基于文件的安全配置编辑
Elasticsearch安全功能是使用Elasticsearch.yml和Elasticsearch.keystore文件中的xpack.security命名空间配置的。此外,在相同的ES_PATH_CONF目录中还有其他几个额外的配置文件。这些文件定义角色和角色映射,并配置文件域。某些设置指定安全敏感数据的文件路径,例如HTTP客户端和节点间通信的TLS密钥和证书,以及SAML、OIDC和Kerberos领域的私钥文件。所有这些都存储在ES_PATH_CONF中;路径设置是相对的。

跨集群复制

<转载>ES跨集群复制CCR

参考:
1:https://blog.csdn.net/wang7075202/category_10645690.html?spm=1001.2014.3001.5482
2:https://www.cnblogs.com/sh-jast/p/14956547.html
3:https://www.elastic.co/guide/en/elasticsearch/reference/7.x/high-availability-cluster-design-large-clusters.html