elasticsearch 經常使用命令 一直紅色 重啓不穩定 不停的宕機

 

persistent (重啓後設置也會存在) or transient (整個集羣重啓後會消失的設置).html


 

查看集羣狀態和每一個indices狀態。搜索到red的,沒用就刪除node

GET /_cluster/health?level=indicesspring

DELETE /.monitoring-kibana-6-2019.07.11/bootstrap


查看全部未重分配的的分片,分片要平均到各個節點api

GET /_cat/shards?h=index,shard,prirep,state,unassigned.reason | grep UNASSIGNED 安全

查看分片分配失敗緣由:服務器

GET /_cluster/allocation/explain?pretty併發

設置延遲分片從新分配,減輕重啓集羣一臺是立刻reblance帶來的壓力。因此通常重啓時關閉重分配:less


PUT _cluster/settings
{
"persistent": {
"cluster.routing.allocation.enable": "primaries",
"cluster.routing.rebalance.enable" : "none"
}
}curl

 

PUT /_all/_settings
{
"settings": {
"index.unassigned.node_left.delayed_timeout": "15m"
}
}

#動態設置es索引副本數量  
curl -XPUT 'http://168.7.1.67:9200/log4j-emobilelog/_settings' -d '{  
   "number_of_replicas" : 2  
}'  
  
#設置es不自動分配分片  
curl -XPUT 'http://168.7.1.67:9200/log4j-emobilelog/_settings' -d '{  
   "cluster.routing.allocation.disable_allocation" : true  
}'  
  
#手動移動分片  
curl -XPOST "http://168.7.1.67:9200/_cluster/reroute' -d  '{  
   "commands" : [{  
        "move" : {  
            "index" : "log4j-emobilelog",  
            "shard" : 0,  
            "from_node" : "es-0",  
            "to_node" : "es-3"  
        }  
    }]  
}'  
  
#手動分配分片  
curl -XPOST "http://168.7.1.67:9200/_cluster/reroute' -d  '{  
   "commands" : [{  
        "allocate" : {  
            "index" : ".kibana",  
            "shard" : 0,  
            "node" : "es-2",  
        }  
    }]  
}'  

設置恢復併發和每秒的大小:
"cluster.routing.allocation.node_concurrent_recoveries": 100, "indices.recovery.max_bytes_per_sec": "40mb"

開啓瘋狂寫入模式能夠先禁用refresh
curl -XPUT  localhost:9200/my_index/_settings -d '{"index":{"refresh_interval":-1}}'

暫時關閉副本:

curl -XPUT 'localhost:9200/my_index/_settings' -d '
{
    "index" : {
        "number_of_replicas" : 1
    }
}'


 

查看當前線程池、查看當前節點信息
curl -XGET 'http://localhost:9200/_nodes/stats?pretty'

curl -XGET 'localhost:9200/_cat/nodes?h=name,ram.current,ram.percent,ram.max,fielddata.memory_size,query_cache.memory_size,request_cache.memory_size,percolate.memory_size,segments.memory,segments.index_writer_memory,segments.index_writer_max_memory,segments.version_map_memory,segments.fixed_bitset_memory,heap.current,heap.percent,heap.max,\&v'

curl -XPOST "localhost:9200/_cache/clear"


 

es節點重啓注意點:

##第一步:先暫停集羣的shard自動均衡。##
curl -XPUT http://192.168.1.2:9200/_cluster/settings -d’
{
「transient」 : {
「cluster.routing.allocation.enable」 : 「none」
}
}’

##第二步:shutdown你要升級的節點##
curl -XPOST http://192.168.1.8:9200/_cluster/nodes/_local/_shutdown

##第三步:升級重啓該節點,並確認該節點從新加入到了集羣中##

##第四步:重複2-3步,升級重啓其它要升級的節點。##

##第五步:重啓啓動集羣的shard均衡##
curl -XPUT http://192.168.1.2/_cluster/settings -d’
{
「transient」 : {
「cluster.routing.allocation.enable」 : 「all」
}
}’
————————————————
版權聲明:本文爲CSDN博主「馬立弘」的原創文章,遵循CC 4.0 by-sa版權協議,轉載請附上原文出處連接及本聲明。
原文連接:https://blog.csdn.net/manimanihome/article/details/93883301


!!!沒有template的數據字段類型又多變 極可能拖累es

https://www.elastic.co/guide/en/elasticsearch/guide/current/indexing-performance.html#_using_and_sizing_bulk_requests
Segment merging 拖慢寫數據時會有日誌
now throttling indexing
默認是20MB  若是ssd建議100-200
PUT /_cluster/settings
{
    "persistent" : {
        "indices.store.throttle.max_bytes_per_sec" : "100mb"
    }
}
若是隻錄入數據,不作索引查詢,甚至能夠關掉這個(從新打開將其設置爲merge)
PUT /_cluster/settings
{
    "transient" : {
        "indices.store.throttle.type" : "none"
    }
}

機械硬盤減小磁盤io壓力方法
(This setting will allow max_thread_count + 2 threads to operate on the disk at one time, so a setting of 1 will allow three threads.)
For SSDs, you can ignore this setting. The default is Math.min(3, Runtime.getRuntime().availableProcessors() / 2), which works well for SSD.

這個是寫在配置文件elasticsearch.yml配置文件的
         index.merge.scheduler.max_thread_count: 1

Finally, you can increase index.translog.flush_threshold_size from the default 512 MB to something larger, such as 1 GB.
!!!這樣能減輕磁盤壓力,但會加劇內存壓力
This allows larger segments to accumulate in the translog before a flush occurs.
By letting larger segments build, you flush less often, and the larger segments merge less often.
All of this adds up to less disk I/O overhead and better indexing rates

 


 

知道哪一個索引的哪一個分片就開始手動修復,經過reroute的allocate分配

curl -XPOST '{ESIP}:9200/_cluster/reroute' -d '{
    "commands" : [ {
          "allocate" : {
              "index" : "eslog1",
              "shard" : 4,
              "node" : "es1",
              "allow_primary" : true
          }
        }
    ]
}'

https://www.cnblogs.com/seaspring/p/9322582.html

ELK的內外網配置:
network.bind_host: 多個地址,能夠是內網,外網同時能夠訪問
network.publish_host: es集羣間交互通訊地址。若是同時有內網,外網,咱們將他設定爲這臺服務器的內網地址。分片複製會更快。
network.host: 0.0.0.0 指綁到全部的網卡IP上,若是一臺服務器有多個地址,外網,內網 (若是沒有設置上面兩個選項,上面兩個選項的默認值就是它。)


  • 永久配置,至少多少個節點才集羣纔可用。防止腦裂。

個數爲(master候選節點個數/2)+1. 這裏有幾個例子:
*若是你有10個節點(能保存數據,同時能成爲master) 法定數就是6
*若是你有3個候選master,和100個數據節點,法定數就是2,你只要數數那些能夠作master的節點數就能夠了。

PUT /_cluster/settings
{
「persistent」 : {
「discovery.zen.minimum_master_nodes」 : 2
}
}
  • 集羣恢復config/elasticsearch.yml:

在發現8個節點(數據節點或者master節點)才啓動平衡恢復:

gateway.recover_after_nodes: 8

應該有多少個節點,而且咱們但願集羣須要多久等待全部節點:

gateway.expected_nodes: 10
gateway.recover_after_time: 5m

綜合上面三個條件,這意味着Elasticsearch會採起以下操做:
*至少等待8個節點上線
*等待5分鐘,或者10個節點上線後,才進行數據恢復,這取決於哪一個條件先達到。

  • 最好使用單播代替組播

不須要包含你的集羣中的全部節點,它只須要包含足夠一個新節點聯繫上其中一個而且說上話就ok了。若是你使用master候選節點做爲單播列表,你只要列出三個就能夠了。這個配置在elasticsearch.yml文件中:
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: [「host1」, 「host2:port」]

備註:請確認你已經關閉了組播(discovery.zen.ping.multicast.enabled: false),不然它會和單播同時存在。

監控節點(index)

GET _nodes/stats

elasticsearch如何安全重啓節點(續)

以前分享的一篇文章介紹瞭如何滾動rolling重啓elasticsearch集羣。可是當數據量很大的時候,可能那種方式並不適合修改整個集羣的配置。
若是你沒法經過api更改集羣屬性,仍是建議你把整個集羣關閉,重啓整個集羣。

重啓步驟以下:

一、關閉整個集羣
curl -XPOST ‘http://IP:9200/_cluster/nodes/_shutdown’

二、修改你要修改的配置項,或者是升級elasticsearch版本。

三、修改每一個節點配置文件:

配置:
gateway.expected_nodes: 10
gateway.recover_after_time: 5m
gateway.recover_after_nodes: 8
minimum_master_nodes: 2
以上參考:http://zhaoyanblog.com/archives/745.html

配置:bootstrap.mlockall: true
以上參考:http://zhaoyanblog.com/archives/826.html

四、線啓動master節點,再依次啓動全部的其它節點。

五、查看集羣狀態,直到全部節點加入集羣,變爲green狀態curl ‘http://ip:9200/_cluster/health?pretty=true’這由於第三步的配置,這個過程會很快,即使數據量大,頂多幾分鐘的事情。

相關文章
相關標籤/搜索