版本配置:html
ES版本:6.2.4bootstrap
OS内存64G。缓存
1、安装部署:架构
1.ES jvm内存31G,预留一半的物理内存给文件系统缓存(file system cache)。app
2.禁止内存交换:异步
修改/etc/sysctl.conf 中 vm.swappiness = 1jvm
elasticsearch.yml中,设置这个:bootstrap.mlockall:trueasync
3.修改ES启动用户可以使用的系统文件句柄数等。elasticsearch
4.有条件使用更好的硬盘如ssd。ide
5.若是有多块盘:
1)作RAID0或者RAID5,RAID能够提升磁盘IO,可是风险就是一块硬盘故障整个就故障。
2)每一个盘mount到一个目录,data path配置多个。
6.节点分开部署:master、data、coordinate
7.冷热分离架构:热数据SSD存储,冷数据普通硬盘存储。
2、合理的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": "512mb", (默认512M,不建议修改)
"sync_interval": "30s", (默认5s,可适当增大)
"durability": "async" (默认request,每次更新都会写trans log,修改成异步)
}
}
5.建立新索引时,能够配置每一个分片中的Segment的排序方式,index sorting是优化检索性能的很是重要的方式之一:
{
"settings" : {
"index" : {
"sort.field" : "date",
"sort.order" : "desc"
}
},
"mappings": {
"properties": {
"date": {
"type": "date"
}
}
}
}
3、ES参数调整:
针对data节点,设置elasticsearch.yml中:
thread_pool.bulk.queue_size: 1024 (增大)
indices.fielddata.cache.size: 1gb (默认10%,可适当调小)
indices.queries.cache.size: 1gb(默认10%,可适当调小)
indices.memory.index_buffer_size: 15% (默认10%,会影响写入性能,写入的分片数更多,则须要更多的buffer)
cluster.routing.allocation.disk.include_relocations: false (加快shard分配,在建索引的时候,不考虑迁移的任务)
熔断circuit-breaker调整(调低,减少OOM风险):
indices.breaker.total.limit: 50%
indices.breaker.request.limit: 10%
indices.breaker.fielddata.limit: 10%
cluster.routing.allocation.same_shard.host:true
若是机器具备128 GB的RAM,能够运行两个节点,每一个节点配置31GB内存,Lucene将使用剩余64GB内存。若是这样搭建data节点,在配置中设置cluster.routing.allocation.same_shard.host为true。这将阻止主副本分片被分配到同一台物理机,提升可用性。
4、设置合理的分片数和副本数:
1.对于数据量较小(100GB如下)的index:通常设置3~5个shard
2.对于数据量较大(100GB以上)的index:通常把单个shard的数据量控制在20GB~40GB
3.对于30G内存的节点,shard数量最好控制在600个(即每1GB内存的shard数在20之内)
4.副本数:通常副本数为1,对数据可用性有高要求的,能够设置为2
5、索引合并、段合并(Segment Merge)
1.经过_forcemerge API进行合并,减小segments数量,同时提升查询效率:
2.max_num_segments取值为:max_num_segments =(单个索引的大小G/分片数/2G)
3.经过_reindex API将历史小索引合并成大索引,减小索引数和分片数。
6、时序数据:
1.合理按天、周、月、年去建立、关闭、删除索引。
2.索引太多时,索引预建立:天天定时任务把明天须要的索引先建立好。
3.从6.7版本开始kibana自带索引生命周期管理ILM(Indice Life Management)
7、写入:
1.使用批量请求bulk request。
2.尽可能使用自动生成的ID。Elasticsearch自动生成的ID能够确保是惟一的,以免版本查询。
3.避免索引大的document数据,如超过100M的一条document。
4.减小副本数,字段不分词,可增长写入性能。
8、查询:
1.尽可能使用filter而不是query。使用filter不会计算评分score,只计算匹配。
2.若是不关心文档返回的顺序,则按_doc排序。
3.避免通配符查询。
4.不要获取太大的结果数据集,若是须要大量数据使用scroll API。
分页查询使用:from+size
遍历使用:scroll
并行遍历使用:scroll+slice
5.合理设置聚合的size:聚合结果是不精确的,聚合的结果是取每一个分片的Top size元素后综合排序后的值。尽可能不要获取全量聚合结果,从业务层面取TopN聚合结果值是合理的。
参考:
https://cloud.tencent.com/developer/article/1357698
https://www.elastic.co/blog/how-many-shards-should-i-have-in-my-elasticsearch-cluster
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/general-recommendations.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-for-search-speed.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-for-indexing-speed.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-for-disk-usage.html