版本配置:
ES 版本: 6.2.4
OS 内存 64G.
一, 参数配置:
ES jvm 内存 31G.
- vi /etc/sysctl.conf
- vm.swappiness = 1
Elasticsearch.YAML 中, 设置这个: Bootstrap.mlockall:true
有条件使用更好的硬盘如 ssd.
如果有多块盘, 每个盘 mount 到一个目录, data path 配置多个.
二, 合理的 Index Mapping:
1. 特殊字段: 如 Boolean,IP, 时间等.
2. 字符串: 尽量使用 keyword, 默认的 text 会被 analyze.keyword 最大 32766 字节.
3. 调整 refresh 间隔: refresh_interval: 30s, 默认的 1 秒会导致大量 segment 产生, 影响性能.
4. 调整 translog 刷新机制为异步:
- "index": {
- "translog": {
- "flush_threshold_size": "1gb",
- "sync_interval": "30s",
- "durability": "async"
- }
- }
三, 缓存参数调整:
设置 Elasticsearch.YAML 中:
- thread_pool.bulk.queue_size: 1024
- indices.fielddata.cache.size: 1gb
- indices.queries.cache.size: 1gb
- indices.memory.index_buffer_size: 15% (默认 10%)
indices.memory.index_buffer_size 会影响写入性能, 写入的分片数更多, 则需要更多的 buffer.
熔断 circuit-breaker 调整(调低):
- indices.breaker.total.limit: 50%
- indices.breaker.request.limit: 10%
- indices.breaker.fielddata.limit: 10%
四, 设置合理的分片数和副本数:
1. 对于数据量较小 (100GB 以下) 的 index: 一般设置 3~5 个 shard
2. 对于数据量较大 (100GB 以上) 的 index: 一般把单个 shard 的数据量控制在 20GB~40GB
3. 对于 30G 内存的节点, shard 数量最好控制在 600 个(即每 1GB 内存的 shard 数在 20 以内)
4. 副本数: 一般副本数为 1, 对数据可用性有高要求的, 可以设置为 2
五, 段合并 Segment Merge
1. 通过_forcemerge API 进行合并, 减少 segments 数量, 同时提高查询效率:
2.max_num_segments 取值为: max_num_segments =(单个索引的大小 G / 分片数 / 2G)
六, 时序数据:
1. 合理按天, 周, 月, 年去创建, 关闭, 删除索引.
2. 索引太多时, 索引预创建: 每天定时任务把明天需要的索引先创建好.
3. 从 6.7 版本开始 kibana 自带索引生命周期管理 ILM(Indice Life Management)
七, 查询写入:
1. 使用批量请求 bulk request.
2. 尽量使用自动生成的 ID.Elasticsearch 自动生成的 ID 可以确保是唯一的, 以避免版本查询.
3. 尽量使用 filter 而不是 query. 使用 filter 不会计算评分 score, 只计算匹配.
4. 如果不关心文档返回的顺序, 则按_doc 排序.
5. 避免通配符查询.
6. 不要获取太大的结果数据集, 如果需要大量数据使用 scroll API.
7. 避免索引大的 document 数据, 如超过 100M 的一条 document.
参考:
- https://cloud.tencent.com/developer/article/1357698
- https://www.elastic.co/guide/en/elasticsearch/reference/6.2/general-recommendations.html
- https://www.elastic.co/guide/en/elasticsearch/reference/6.2/tune-for-indexing-speed.html
- https://www.elastic.co/guide/en/elasticsearch/reference/6.2/tune-for-disk-usage.html
- https://www.elastic.co/guide/en/elasticsearch/reference/6.2/circuit-breaker.html
- https://www.elastic.co/guide/en/elasticsearch/reference/6.2/modules-indices.html
- https://www.elastic.co/blog/how-many-shards-should-i-have-in-my-elasticsearch-cluster
来源: https://www.cnblogs.com/luxiaoxun/p/10742524.html