美文网首页
Elasticsearch实战 第十一章 管理集群

Elasticsearch实战 第十一章 管理集群

作者: kaiker | 来源:发表于2021-12-13 11:54 被阅读0次

1、改善默认配置

索引模板

  • _template节点
curl -XPUT localhost:9200/_template/logging_index -d '{
    "template":"logstash-*",
    "settings":{
        "number_of_shards":2,
        "number_of_replicas":1
    }
    }'
  • 多个模板可设置order进行合并

默认映射

  • 动态映射,如果之前已经存在映射了,而且结构和新设置的不一样就会报错
  • 动态映射可和动态模板配合使用
curl -XPUT 'http://localhost:9200/myindex' -d '{
    "mappings":{
        "my_type":{
            "dynamic_teplates":[{
                "UUID": {
                    "match": "*_guid",
                    "match_mapping_type":"string",
                    "mapping":{
                        "type":"string",
                        "index":"not_analyzed"
                    }
                }
            }]
        }
    }
}'

2、分配感知

  • 指定分片的分组,可以让分片的备份存在与不同的机架、机房

3、监控瓶颈

健康状态

  • relocating_shards 大于0表示Elasticsearch正在集群内移动数据分片;initializing_shards 大于0表示刚刚创建一个新的索引或重启一个节点;unassinged_shards 大于0表示由尚未分配的副本分片(没有多余节点)
  • 黄色,通常是副本分片丢失;红色,无法找到集群中的主分片

慢日志、热线程和线程池

  • 慢日志包含慢查询和慢索引日志
  • CPU使用率居高不下,则将发现热线程,查看具体用在哪个地方,search merge index
  • 线程池根据操作类型划分,并根据操作类型配置默认值。
  • 有两种线程池,fixed和cache,fixed保持固定数量的线程来处理请求,使用后援队列来处理等待执行的请求;cache则只要有等待执行的请求,系统就会创建一个新的线程

内存

  • 堆的大小,最多50%可用系统内存,剩下的需要给底层文件系统;最大32GB内存
  • 过滤器和字段缓存,节点级别的过滤器缓存,LRU
  • 字段缓存如果不断增加可能OOM,断路器可以判断这个字段加入缓存后会不会出问题

操作系统缓存

  • Lucene将热门数据分段保留在内存中以便快速读取

4、备份数据

将数据备份到共享的文件系统

  • 定义一个资料库
curl -XPUT 'localhost:9200/_snapshot/my_repository' -d '
    {
        "type":"fs",
        "settings":{
            "location":"",
            "max_snapshot_bytes_per_sec":""
        }
    }
'

curl -XPUT 'localhost:9200/_snapshot/my_repository/first_snapshot'

从备份中恢复

  • _restore节点
    curl -XPOST 'localhost:9200/_snapshot/my_repository/first_snapshot_restore'

使用资料库插件

  • 可以用s3 hdfs作为备份载体

相关文章

网友评论

      本文标题:Elasticsearch实战 第十一章 管理集群

      本文链接:https://www.haomeiwen.com/subject/mfurfrtx.html