zoukankan      html  css  js  c++  java
  • elasticsearch优化

    9.9 elasticsearch优化

    1 分片和副本

    ElasticSearch6以后设置索引的默认分片数和副本数已经不在elasticsearch.yml文件中了,而是使用了索引模板的方式配置。

    官方文档: https://www.elastic.co/guide/en/elasticsearch/reference/7.14/size-your-shards.html

     

    2 索引优化

    官方文档: https://www.elastic.co/guide/en/elasticsearch/reference/7.14/tune-for-indexing-speed.html

    index.refresh_interval: 30s

    # 增加刷新间隔,Elasticsearch默认1s秒刷新一次您的索引,加到更大的值,例如30s,可能有助于提高索引速度。

    bootstrap.memory_lock: true

    # 锁定内存,禁用内存交换到swap,建议服务器内存的一半

    # 1) 修改"elasticsearch/config/jvm.options"文件中的如下两个参数

    # -Xms3g

    # -Xmx3g

    # 2) 修改/usr/lib/systemd/system/elasticsearch.service文件在[Service]下添加如下参数应用"bootstrap.memory_lock: true"配置

    # LimitMEMLOCK=infinity

    indices.memory.index_buffer_size: 512mb

    # 调整索引缓冲区大小

     

    3 事物日志优化

    官方文档: https://www.elastic.co/guide/en/elasticsearch/reference/7.14/index-modules-translog.html

    index.translog.sync_interval: 30s

    # translog被写入磁盘并提交的频率,默认为5s

    index.translog.durability: async

    # 在每个索引、删除、更新或批量请求之后是否同步和提交事务日志。

    # request: 默认值,同步并在每个请求后提交。如果发生硬件故障,所有已确认的写入将已经提交到磁盘。

    # async:   同步和提交在每个sync_interval时执行一次。如果发生故障,则自上次自动提交以来所有已确认的写入将被丢弃。

    index.translog.flush_threshold_size: 512mb

    # translog存储所有尚未安全持久化在Lucene中的操作,一旦达到最大大小,就会发生刷新,生成一个新的Lucene提交点。默认为512mb

     

    4 索引段合并优化

    官方文档: https://www.elastic.co/guide/en/elasticsearch/reference/7.14/index-modules-merge.html

    Elasticsearch中的一个分片是一个Lucene索引,一个Lucene索引被分解成段。段是索引中存储索引数据的内部存储元素,并且是不可变的。

    较小的段会定期合并为较大的段以保持索引大小。

    index.merge.scheduler.max_thread_count: 1

    # 单个分片上可以同时合并的最大线程数,如果您的索引位于旋转盘片驱动器上,请将其减少到1

    # 默认为Math.max(1, Math.min(4, <<node.processors, node.processors>> / 2)),适用于ssd固态硬盘。

     

    5 索引优化配置

    (1) 以上索引优化参数通过elasticsearch.yml配置的如下

    bootstrap.memory_lock: true

    indices.memory.index_buffer_size: 512mb

     

    (2) 以上索引 优化参数通过命令行方式配置的如下

    curl -u elastic:elastic -XPUT -H "Content-Type: application/json" 'http://192.168.30.47:9200/_all/_settings?preserve_existing=true' -d '{

      "index.merge.scheduler.max_thread_count" : "1",

      "index.refresh_interval" : "30s",

      "index.translog.durability" : "async",

      "index.translog.flush_threshold_size" : "512mb",

      "index.translog.sync_interval" : "30s"

    }'

     

    6 索引生命周期优化

    (1) 官方文档:

    https://www.elastic.co/guide/en/elasticsearch/reference/7.14/index-lifecycle-management.html

    https://www.elastic.co/guide/en/elasticsearch/reference/current/overview-index-lifecycle-management.html

    kibana中有索引生命周期管理。

     

    (2) 实现方式

    配置好生命周期策略后,我们需要创建一个模板,将我们现在的输入index接管过来,然后将策略应用于这个模板,这就达到了每次创建的index都能应用于这一策略。

     

    7 elasticsearch-head通过认证的方式连接elasticsearch

    (1) elasticsearch.yml中添加如下参数

    http.cors.allow-headers: Authorization,X-Requested-With,Content-Type,Content-Length

     

    (2) 访问elasticsearch-head

    http://172.16.1.120:9100/?auth_user=elastic&auth_password=elastic

  • 相关阅读:
    自学Python5.2-类和对象概念
    自学Python5.1-面向对象与面向过程
    自学Python2.1-基本数据类型-字符串str(object) 上
    自学Python2.10-跳出循环(break、continue)
    自学Python2.9-循环(while、for)
    自学Python2.8-条件(if、if...else)
    自学Python1.8-python input/print用法 格式化输出
    自学Python1.6-Centos内英文语法切换
    自学Python1.7-python变量以及类型
    自学Python1.5-Centos内python2识别中文
  • 原文地址:https://www.cnblogs.com/LiuChang-blog/p/15126029.html
Copyright © 2011-2022 走看看