zoukankan      html  css  js  c++  java
  • 第九章:Elasticsearch集群优化及相关节点配置说明

    Linux系统调优:

      1. Linux调整打开文件数(重新启动生效)

    在/etc/security/limits.conf在文件中增加:

    * soft nofile 8192

    * hard nofile 20480

    * - memlock unlimited

    索引优化:

      1. 设置集群副本不要过多,不是越多越好,起初设置成"index.number_of_replicas": 0,后期可使用_settings方法对副本进行调整优化效率。方法:wf_mds_chn_claw/_settings、PUT、{"index.number_of_replicas":"1"}。
      2. 检索建立索引时配置:

    "index.refresh_interval": "-1",

    "index.translog.flush_threshold_ops": "100000"

    第一个参数表示: 数据达到多少条进行平衡,默认为5000,而这个过程相对而言是比较浪费时间和资源的。所以我们可以将这个值调大一些还是设为-1关闭,进而手动进行tranlog平衡。

    第二个参数表示: 刷新频率,默认为120s是指索引在生命周期内定时刷新可以将其关闭,在最初索引完后手动refresh,后期按需求进行修改,从而可以提高索引过程效率。

    ES集群文件配置:

      1. 分配一台服务器做负载均衡,将配置修改为:

    a)   node.master: false

    b)   node.data: false

      2. 锁定内存,因为当jvm开始swapping时es的效率会降低,所以要保证它不swap,可以把ES_MIN_MEM和ES_MAX_MEM两个环境变量设置成同一个值,并且保证机器有足够的内存分配给es。同时也要允许elasticsearch的进程可以锁住内存,linux下可以通过`ulimit-l unlimited`命令,将配置修改为:

        a)   bootstrap.mlockall:true

      3. 因为gc时会使jvm停止工作,如果某个节点gc时间过长,master ping3次(zen discovery默认ping失败重试3次)不通后就会把该节点剔除出集群,从而导致索引进行重新分配。所以优化gc,减少gc时间并调大zen discovery的重试次数,将配置修改为:

    a)   discovery.zen.ping.timeout: 60s

    b)   monitor.jvm.gc.ParNew.warn: 1000ms

    c)   monitor.jvm.gc.ConcurrentMarkSweep.warn: 10s

      4. 依据系统设置文件存储类型。mmapfs是使用在windows的64bit系统上,simplefs是使用在windows的32bit上,在2.X版本中默认使用default_fs适用系统Linux一般默认使用的是hybrid niofs和mmapfs,将配置修改为:

      a)   index.store.type: mmapfs

      5. 设置约定的内存大小时会自动清理多久没有访问到的数据会被驱逐设置:

      a)   index.fielddata.cache.size: 50%

      b)   index.fielddata.cache.expire: 5m

    第一个参数:配置fieldData的Cache大小,可以配百分比也可以配一个准确的数值。cache到达约定的内存大小时会自动清理,驱逐一部分FieldData数据以便容纳新数据。默认值为unbounded无限。

    第二个参数:用于约定多久没有访问到的数据会被驱逐,默认值为-1,即无限。expire配置不推荐使用,按时间驱逐数据会大量消耗性能。而且这个设置在不久之后的版本中将会废弃。

      6. 多磁盘存储数据或日志以都好分隔,将配置修改为:

    a)   path.data: /data/elasticsearch/data,/data1/elasticsearch/data

    b)   path.logs: /data/elasticsearch/log, /data1/elasticsearch/log

      7. 设置集群中N个节点启动时进行数据恢复默认为1,此处依据集群数量进行相关配置,将配置修改为:

    a)    gateway.recover_after_nodes:2

      8. 针对大数量集群可以设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4),将配置修改为:

    a)   discovery.zen.minimum_master_nodes: 1

      9. 将多播发现节点设置为False, 设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点,将配置修改为:

    a)   discovery.zen.ping.multicast.enabled: false

    b)   discovery.zen.ping.unicast.hosts: ["168.162.100.6", "168.162.101.7", "168.162.102.8"]

    elasticsearch.yml参数说明

      1. cluster.name: elasticsearch

        集群名称,同一网段设置统一名称会自动识别。

      2. node.name: "Test"

        集群节点名。

      3. node.master: true

        设置master节点,默认是true。

      4. node.data: true

        该节点是否存储索引数据,默认为true。

      5. index.number_of_shards: 5

        索引默认分片数,默认为5片。

      6. index.number_of_replicas: 1

        索引默认副本数,默认为1个副本。

      7. path.conf: /path/to/conf

        配置文件存储路径,默认是es根目录下的config文件夹。

      8. path.data: /path/to/data

        索引存储路径,默认是es根目录下的data文件夹。

      9. path.work: /path/to/work

        临时文件存储路径,默认是es根目录下的work文件夹。

      10. path.logs: /path/to/logs

        日志文件存储路径,默认是es根目录下的logs文件夹。

      11. path.plugins: /path/to/plugins

        插件存储路径,默认是es根目录下的plugins文件夹

      12. network.bind_host: 192.168.0.1

        设置绑定的ip地址,默认为0.0.0.0。

      13. network.publish_host: 192.168.0.1

        设置与该节点交互的ip地址。

      14. network.host: 192.168.0.1

        同时设置bind_host和publish_host两个参数。

      15. transport.tcp.port: 9300

        节点间交互的tcp端口,默认是9300。

      16. transport.tcp.compress: true

        设置是否压缩tcp传输时的数据,默认为false,不压缩。

      17. http.port: 9200

        设置对外服务的http端口,默认为9200。

      18. http.max_content_length: 100mb

        设置内容的最大容量,默认100mb。

      19. http.enabled: false

        是否使用http协议对外提供服务,默认为true,开启。

      20. gateway.recover_after_nodes: 1

        设置集群中N个节点启动时进行数据恢复,默认为1。

      21. gateway.recover_after_time: 5m

        设置初始化数据恢复进程的超时时间,默认是5分钟。

      22. gateway.expected_nodes: 2

        设置这个集群中节点的数量,默认为2,一旦这N个节点启动,就会立即进行数据恢复。

      23. cluster.routing.allocation.node_initial_primaries_recoveries: 4

        初始化数据恢复时,并发恢复线程的个数,默认为4。

      24. cluster.routing.allocation.node_concurrent_recoveries: 2

        添加删除节点或负载均衡时并发恢复线程的个数,默认为4。

      25. indices.recovery.max_size_per_sec: 0

        设置数据恢复时限制的带宽,如入100mb,默认为0,即无限制。

      26. indices.recovery.concurrent_streams: 5

        设置这个参数来限制从其它分片恢复数据时最大同时打开并发流的个数,默认为5。

      27. discovery.zen.minimum_master_nodes: 1

        设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4)

      28. discovery.zen.ping.timeout: 3s

        设置集群中自动发现其它节点时ping连接超时时间,默认为3秒,对于比较差的网络环境可以高点的值来防止自动发现时出错。

      29. discovery.zen.ping.multicast.enabled: false

        设置是否打开多播发现节点,默认是true。

      30. discovery.zen.ping.unicast.hosts: ["host1", "host2:port", "host3[portX-portY]"]

        设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点。

    下面是一些查询时的慢日志参数设置

    index.search.slowlog.level: TRACE

    index.search.slowlog.threshold.query.warn: 10s

    index.search.slowlog.threshold.query.info: 5s

    index.search.slowlog.threshold.query.debug: 2s

    index.search.slowlog.threshold.query.trace: 500ms

    index.search.slowlog.threshold.fetch.warn: 1s

    index.search.slowlog.threshold.fetch.info: 800ms

    index.search.slowlog.threshold.fetch.debug:500ms

    index.search.slowlog.threshold.fetch.trace: 200ms

  • 相关阅读:
    Class constructor FileManager cannot be invoked without 'new' in undefined (line undefined, column undefined)
    vscode插件
    面试题
    使用NPOI读取word表格里面的图片
    Postgresql安装过程记录
    .net Core 新增Area的步骤
    kendo grid上的模版示例
    unicode与string之间的转换
    使用yarn安装puppeteer失败的解决方案
    abp第一篇《框架的下载与mysql数据库的切换》
  • 原文地址:https://www.cnblogs.com/hynet/p/6903291.html
Copyright © 2011-2022 走看看