persistent (重啟后設置也會存在) or transient (整個集群重啟后會消失的設置).
查看集群狀態和每個indices狀態。搜索到red的,沒用就刪除
GET /_cluster/health?level=indices
DELETE /.monitoring-kibana-6-2019.07.11/
查看所有未重分配的的分片,分片要平均到各個節點
GET /_cat/shards?h=index,shard,prirep,state,unassigned.reason | grep UNASSIGNED
查看分片分配失敗原因:
GET /_cluster/allocation/explain?pretty
設置延遲分片重新分配,減輕重啟集群一台是馬上reblance帶來的壓力。所以一般重啟時關閉重分配:
PUT _cluster/settings
{
"persistent": {
"cluster.routing.allocation.enable": "primaries",
"cluster.routing.rebalance.enable" : "none"
}
}
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更改集群屬性,還是建議你把整個集群關閉,重啟整個集群。
重啟步驟如下:
1、關閉整個集群
curl -XPOST ‘http://IP:9200/_cluster/nodes/_shutdown’
2、修改你要修改的配置項,或者是升級elasticsearch版本。
3、修改每個節點配置文件:
配置:
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
4、線啟動master節點,再依次啟動所有的其它節點。
5、查看集群狀態,直到所有節點加入集群,變為green狀態
curl ‘http://ip:9200/_cluster/health?pretty=true’
這
因為第三步的配置,這個過程會很快,即便數據量大,頂多幾分鍾的事情。