curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cluster/health?pretty'
如果1.1中获取的集群的状态不是green,而是yellow或者red,则需要获取异常的索引从而进行修复
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/indices?v&health=yellow'
h= 过滤所需要需要操作的列
s= 进行聚合,排序等操作
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/indices?v&health=yellow'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/indices/?v&s=index'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/indices/?v&s=index:desc'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/indices?v&s=docs.count'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/indices?v&s=docs.count:desc'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/indices?v&s=store.size'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/indices?v&s=store.size:desc'
curl -XGET 'Content-Type: application/json' 'http://localhost:9200/_cat/indices?v&h=health,index,pri,rep,docs.count,docs.deleted,store.size,pri.store.size,tm&s=tm'
curl -XGET 'Content-Type: application/json' 'http://localhost:9200/_cat/indices?v&h=health,index,pri,rep,docs.count,docs.deleted,store.size,pri.store.size,tm&s=tm:desc'
默认输出10行doc
curl -XGET 'Content-Type: application/json' 'http://localhost:9200/index@2022-04-30/_search?pretty'
可以看到一行数据的数据格式,以便后续进行和排序和聚合
{
"_index" : "index@2022-04-30",
"_type" : "log",
"_id" : "7DtddIAB-AGo1nv-abnm",
"_score" : 1.0,
"_source" : {
"application-name" : "app-demo",
"local-ip" : "x.x.x.x",
"app-id" : "1",
"offset" : 263273337,
"instance-id" : "demo-7cf675695c-56t88",
"ns-id" : "ns-96a79v5b",
"source" : "/data/app_std/stdout/logs/sys_log.log",
"message" : "2022-04-30 16:08:38.695 DEBUG 1 --- [pool-1-thread-1] c.t.c.t.sdk.core.remoting.NettyChannel : return netty channel: NettyChannel [channel=[id: 0x53ef4f24, L:/x.x.x.x:38528 - R:/x.x.x.x:28000]], serializationId: 1",
"type" : "log",
"appgp-id" : "gp-xxx",
"timestamp_es" : "2022-04-30T16:08:40.678+08:00",
"@timestamp" : "2022-04-30T08:08:39.081Z",
"fields" : {
"pipename" : "pipeline"
},
"application-id" : "app-xxxx",
"cluster-id" : "cluster-xxxx"
}
}
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/index@2022-04-30/_search?pretty' -d '
{
"query": {
"term" : { "appgp-id" : "gp-xxx" }
}
}'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/index@2022-04-30/_search?pretty' -d '
{
"from" : 0,
"size" : 10,
"query": {
"term" : { "appgp-id" : "gp-xxx" }
}
}'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/index@2022-04-30/_search?pretty' -d '
{
"from" : 0,
"size" : 10,
"sort" : [
{ "ns-id": "desc" }
],
"query": {
"term" : { "appgp-id" : "gp-xxx" }
}
}'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/index@2022-04-30/_search?pretty' -d '
{
"from" : 0,
"size" : 10,
"sort" : [
{ "ns-id": "desc" }
],
"explain": true,
"query": {
"term" : { "appgp-id" : "gp-xxx" }
}
}'
gp_by_tags 是聚合出来的新指标,可以任意命名,功能类似myslq的gp by功能
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/index@2022-04-30/_search?pretty' -d '
{
"size" : 1,
"aggs": {
"gp_by_tags": {
"terms" : {
"field" : "appgp-id",
"order" : { "_count" : "desc" },
"size": 50
}
}
}
}'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/segments/index@2022-04-30?v&s=prirep,shard'
直接删除索引,会把整个索引对应的shard从磁盘中直接删除,磁盘的空间会直接释放
curl -XDEL -H 'Content-Type: application/json' 'http://localhost:9200/index@2022-04-30'
执行删除操作后,只是标记索引中的文档为删除状态(后缀增加.del,进行查询后,会自动被merge掉对应的数据),下次出发merge时,会重新拷贝一个seg(不包含被删除的doc),同时.del的seg会被删除,释放磁盘。
scroll_size=5000 一次batch5000
refresh&slices=5 5个切片,增加5个并发
size=1000 1次只删除1000行数据
curl -H 'Content-Type: application/json' 'http://localhost:9200/index@2022-04-30/_delete_by_query?size=138163&scroll_size=500&refresh&slices=5&pretty' -d '
{
"query": {
"term" : {
"appgp-id" : "gp-xxx"
}
}
}'
curl -XPOST -H "Content-Type: application/json" 'http://localhost:9200/index@2022-04-30/_forcemerge?only_expunge_deletes=true&max_num_segments=1&pretty'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/indices/?s=segmentsCount:desc&v&h=index,segmentsCount,segmentsMemory,memoryTotal,mergesCurrent,mergesCurrentDocs,storeSize,p,r'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_tasks?detailed=true&actions=*forcemerge'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/shards/?v&s=index'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/shards/?v&s=index:desc'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/shards?v&s=docs'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/shards?v&s=docs:desc'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/shards?v&s=store'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/shards?v&s=store:desc'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason'
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_cat/allocation?v'
curl -H 'Content-Type: application/json' -XGET 'http://localhost:9200/_cluster/settings?pretty'
如果没有单独配置,则是按照默认的值进行规则限制
3个关键磁盘使用率水位
cluster.routing.allocation.disk.watermark.low
Elasticsearch不会将分片分配给使用磁盘超过85%的节点。它也可以设置为绝对字节值(如500mb),以防止Elasticsearch在小于指定的可用空间量时分配分片。此设置不会影响新创建的索引的主分片,或者特别是之前任何从未分配过的分片。
cluster.routing.allocation.disk.watermark.high
Elasticsearch将尝试从磁盘使用率超过90%的节点重新分配分片。它也可以设置为绝对字节值,以便在节点小于指定的可用空间量时将其从节点重新分配。此设置会影响所有分片的分配,无论先前是否分配。
cluster.routing.allocation.disk.watermark.flood_stage
Elasticsearch对每个索引强制执行只读索引块(index.blocks.read_only_allow_delete)。这是防止节点耗尽磁盘空间的最后手段。一旦有足够的可用磁盘空间允许索引操作继续,就必须手动释放索引块。
curl -XPUT -H 'Content-Type: application/json' 'http://localhost:9200/_cluster/settings?pretty' -d '{
"transient" : {
"cluster.routing.allocation.disk.watermark.low": "60%",
"cluster.routing.allocation.disk.watermark.high" : "70%",
"cluster.info.update.interval" : "1m",
"cluster.routing.allocation.disk.watermark.flood_stage": "80%"
}
}'
当磁盘的使用率 洪水警戒水位线 后,es会自己将索引设置为只读,以达到自我保护。并且磁盘使用率恢复后,也不会自动恢复,需要人工进行恢复
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_all/_settings?pretty'|grep '"read_only_allow_delete" : "true"'
磁盘使用率恢复后,需要人工取消只读配置,否则es依然无法正常写入数据
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'
如果部分索引/shard异常,并且超出分配的重试次数后,系统仍然不能恢复。 则需要人工重新触发重新分配,以达到恢复的目的
curl -H 'Content-Type: application/json' -XPOST http://localhost:9200/_cluster/reroute?retry_failed=true
希望加速集群恢复速度、任务的处理能力
curl -XPUT 'http://localhost:9202/_cluster/settings' -H 'Content-Type: application/json' -d '{
"transient": {
"cluster.routing.allocation.cluster_concurrent_rebalance": "50",
"cluster.routing.allocation.node_concurrent_recoveries": "50",
"cluster.routing.allocation.node_initial_primaries_recoveries": "50",
"indices.recovery.max_bytes_per_sec": "400mb"
}
}'