您好,登錄后才能下訂單哦!
Elasticsearch 集群集群自我保護(hù)配置
配置調(diào)試原因主要是為了保護(hù)ES 集群能夠自我保護(hù),避免業(yè)務(wù)人員寫暴力查詢語句,大量的占用內(nèi)存或者CPU最終將es集群直接查掛。文檔所有值均為參考值,具體設(shè)置多少合適需要根據(jù)集群規(guī)模、index分片數(shù)量、節(jié)點配置等等。。因素進(jìn)行考量,設(shè)置合理閾值。
ES 版本 :elasticsearch-6.2.4-1.noarch
OS:centos7.X
除了在每個請求中設(shè)置超時之外,ES還支持全局性的搜索超時search.default_search_timeout,此設(shè)置沒有默認(rèn)值,設(shè)置為-1可以取消先前設(shè)置的值。
persistent :重啟后依然有效
transient :重啟后無效
PUT /_cluster/settings
{
"persistent" : {
"search.default_search_timeout" : "35s"
}
}
搜索可以通過標(biāo)準(zhǔn)的任務(wù)取消機(jī)制來取消。默認(rèn)情況下ES僅僅在段邊界(segment boundaries)來檢查請求是否已經(jīng)被取消,因此取消操作可能由于大段而延遲。要降低取消操作的響應(yīng)時間,可以設(shè)置search.low_level_cancellation=true,但是要注意此設(shè)置會導(dǎo)致更加頻繁的檢查。定期檢查自己是否被取消,如果是則退出查詢。
PUT /_cluster/settings
{
"persistent" : {
"search.low_level_cancellation" :true
}
}
#查詢正在運(yùn)行的task
GET _tasks?detailed=true&actions=*indices:data/read/search
#取消任務(wù)
POST _tasks/CdoilmnzRVyllc0PbRbB2w:7280/_cancel
這個參數(shù)主要用于限制一次操作過多的分片,防止過多的占用內(nèi)存和CPU資源。默認(rèn)情況下ES不限制搜索請求牽涉到的分片數(shù)量,你可以設(shè)置軟限制 action.search.shard_count.limit 來拒絕命中太多分片的請求。
如果看到錯誤日志如下,修改此參數(shù)可以解決問題。
"reason" : "Trying to query 1344 shards, which is over the limit of 1000. This limit exists because querying
many shards at the same time can make the job of the coordinating node very CPU and/or memory
intensive. It is usually a better idea to have a smaller number of larger shards. Update
[action.search.shard_count.limit] to a greater value if you really want to query that many shards at the same time."
PUT /_cluster/settings
{
"persistent" : {
"action.search.shard_count.limit" :"1000"
}
}
or
curl -u admin:admin -XPUT 'https://localhost:9200/_cluster/settings' -H 'Content-Type: application/json' -d'
{
"persistent" : {
"action.search.shard_count.limit" : "1000"
}
}
參數(shù)可以限制搜索請求最多同時在多少個分片上執(zhí)行,可以防止單個搜索請求消耗整個集群的資源。此參數(shù)的默認(rèn)值取決于集群中數(shù)據(jù)節(jié)點的數(shù)量,最多256。
###### 設(shè)置方法:
PUT /_cluster/settings
{
"persistent" : {
"max_concurrent_shard_requests : "80"
}
}
默認(rèn)大小:10000
就是from+size,from:決定要返回的文檔從哪里開始,size:決定返回多少條。假如from+size很大的話,將會消耗很多的內(nèi)存和時間;這個設(shè)置就是為了防止內(nèi)存不夠用的情況。
這個設(shè)置是索引層的,即便是使用_all設(shè)置了,看日志也是對逐個索引加這個配置,后續(xù)新加的索引,max_result_window默認(rèn)還是1w。
使用Elasticsearch進(jìn)行search查詢的過程中,出現(xiàn)了Result window is too large問題。一般是這個參數(shù)設(shè)置過小導(dǎo)致的。
可通過如下方式修改:
#查看單個索引設(shè)置
GET /27_hot_v1/_settings
#修改配置
PUT /27_hot_v1/_settings
{
"index.max_result_window":"10000"
}
or
PUT /27_hot_v1/_settings
{
"index.max_result_window":"10000"
}
curl -XPUT 192.168.40.31:9200/$(Index-name)/_settings -d '{ "index.max_result_window" :"1000000"}'
curl -XPUT 192.168.40.31:9200/_all/_settings -d '{ "index.max_result_window" :"1000000"}'
curl -XGET 172.20.7.22:9200/$(index-name)/_settings
默認(rèn)是:100。這個設(shè)置限制的是 返回 結(jié)果中的 結(jié)果!
index.max_inner_result_window:和index.max_result_window原理差不多,這個設(shè)置限制的是返回結(jié)果中的結(jié)果。
#查看單個索引設(shè)置
GET /27_hot_v1/_settings
#修改配置
PUT /27_hot_v1/_settings
{
"max_inner_result_window":"5000"
}
or
PUT /27_hot_v1/_settings
{
"index.max_inner_result_window":"100"
}
默認(rèn)最多請求100字段,Doc-value 字段成本很高,因為它們可能會導(dǎo)致每個字段的每個文檔搜索??梢酝ㄟ^使用index.max_docvalue_fields_search索引設(shè)定覆蓋.
PUT /27_hot_v1/_settings
{
"index.max_docvalue_fields_search":"100"
}
默認(rèn)為32。ndex.max_script_fields:查詢中允許的最大script_field數(shù)。
PUT /27_hot_v1/_settings
{
"ndex.max_script_fields":"32"
}
參考文檔:
https://www.elastic.co/guide/en/elasticsearch/reference/6.5/search.html#global-search-cancellation
https://mp.weixin.qq.com/s/mKL2PJuNUJTl71Axv4-Rcw
https://www.cnblogs.com/huangpeng1990/p/4364341.html
https://kionf.com/2019/01/22/errornote-elk/
https://www.elastic.co/guide/en/elasticsearch/reference/6.6/modules-threadpool.html#_literal_fixed_literal
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。