【ELK】ElasticSearch 集群常用管理API操作

目录

[常用_cat 概览](#常用_cat 概览)

集群状态

集群配置

集群磁盘使用

索引信息与配置

[shard - 分片](#shard - 分片)

查看段信息

[nodes -节点](#nodes -节点)

用户与权限

[tasks 和 pending_tasks](#tasks 和 pending_tasks)

[allocation - 均衡](#allocation - 均衡)

[thread_pool -线程](#thread_pool -线程)

[templete 模版](#templete 模版)

[ILM 生命周期](#ILM 生命周期)

其他


集群版本: 7.17.6

API地址:https://www.elastic.co/guide/en/elasticsearch/reference/7.17/rest-apis.html

ES的API的查询已经非常全面了,数据的定制化展示也很好,具体API使用 以官方文档为准。

某些接口返回的数据量比较大需要注意一下,可以指定类别或则是配置某个字段

比如 GET /_cluster/state?

常用_cat 概览
Go 复制代码
介绍几个数据展示参数选项,基本上每个GET /_cat 接口都支持:
//& 多个参数连接符
	GET /_cat/indices?v&s=uuid
	GET /_cat/indices?h=health

//v  or  v=true  打印包含列标题
    GET /_cat/indices?v
    GET /_cat/indices

//help   打印可以显示的列  
	GET /_cat/indices?help
	GET /_cat/shards?help

//h  指定显示列 
	GET /_cat/indices?h=health,status,index,uuid,docs.count

//s  排序  正序与倒序
	GET /_cat/indices?v&s=uuid
	GET /_cat/indices?v&s=uuid:desc

//format  指定格式 txt json  csv
	GET /_cat/indices?v&format=json


//GET /_cat/  包含了集群基本信息查询
GET /_cat/allocation
GET /_cat/shards
GET /_cat/shards/{index}
GET /_cat/master
GET /_cat/nodes
GET /_cat/indices
GET /_cat/indices/{index}
GET /_cat/segments
GET /_cat/segments/{index}
GET /_cat/count
GET /_cat/count/{index}
GET /_cat/recovery
GET /_cat/recovery/{index}
GET /_cat/health
GET /_cat/pending_tasks
GET /_cat/aliases
GET /_cat/aliases/{alias}
GET /_cat/thread_pool
GET /_cat/plugins
GET /_cat/fielddata
GET /_cat/fielddata/{fields}
GET /_cat/nodeattrs
GET /_cat/repositories
GET /_cat/snapshots/{repository}
集群状态
bash 复制代码
GET /_cat/health  					#集群健康
GET /_cluster/health   				#集群健康 (json格式比较常用)
GET /_cluster/health?level=shards   #shards健康情况
GET /_cat/master?v&format=json		#master节点信息
GET _cluster/stats					#集群状态 包含index 与node 的信息

#集群部署时配置检查
GET /_nodes?filter_path=**.mlockall                             #检查禁用交换分区
GET /_nodes/stats/process?filter_path=**.max_file_descriptors   #检查文件描述符
GET /_nodes/_all/jvm?filter_path=**.input_arguments				#jvm 参数
GET /_cluster/state?filter_path=metadata.cluster_coordination.last_committed_config  #当前投票节点
集群配置
bash 复制代码
GET /_cluster/settings
GET /_cluster/settings?flat_settings=true  			#查看集群配置(flat_settings json平面格式返回)
GET /_cluster/settings?flat_settings=true&filter_path=transient&pretty   # transient 查看临时配置
GET /_cluster/settings?flat_settings=true&include_defaults&pretty        #查看包含默认配置

PUT /_cluster/settings				#添加参数数据迁移,用来重启该节点或者该节点下架
{
  "transient": {
    "cluster.routing.allocation.exclude._ip": "192.168.246.48,192.168.246.55"   #参数 为json平面格式返回格式 自动适配
  }
}

PUT /_cluster/settings				#重平衡并发数
{
  "persistent": {
    "cluster.routing.allocation.cluster_concurrent_rebalance" : "2"
  }
}
集群磁盘使用
bash 复制代码
GET /_cat/allocation?v 						#数据节点的分片数量及其磁盘空间					
GET _cat/allocation/10.84.246.161           #指定查看节点 
GET /_cluster/allocation/explain?pretty     #均衡失败原因
索引信息与配置
bash 复制代码
GET /_dangling         #获取悬空索引 重建集群节点调整容易发生

GET /_cat/indices						#查看索引信息
GET /_cat/indices?v&s=store.size:desc   #查看索引信息 按 store.size 排序 (health status index uuid ···)
GET /_cat/indices/?s=segmentsCount:desc&v&h=index,segmentsCount,segmentsMemory,memoryTotal,\
			mergesCurrent,mergesCurrentDocs,storeSize,p,r     #forcemerge信息
        			#segamentsCount: segament文件数量,正常情况越少查询效率越高       
        			#p:当前index有几个分片     r:几份副本
                    
GET /_cat/indices/appindex?v&format=json  #json格式 
   
#指定索引信息查看  
GET appindex/            		#查看 appindex  索引信息
GET appindex/_mapping			#查看 appindex  索引mapping信息
GET appindex/_settings			#查看 appindex  索引配置信息
GET appindex/_settings?pretty&include_defaults&flat_settings=true	# #查看 appindex  索引配置信息 包含默认配置

PUT appindex/_settings				#迁移索引 
{
  "index.routing.allocation.exclude._name": "oa-cold-60-04"
}

PUT appindex/_settings              #配置单个节点的最大分片数(副本和主分片)
{
  "index.routing.allocation.total_shards_per_node": "8"
}

POST /_cluster/reroute?metric=none     		#迁移分片 
{
  "commands": [
    {
      "move": {
        "index": "test", "shard": 0,
        "from_node": "oa-cold-173-02", "to_node": "oa-cold-60-04"
      }
    }
  ]
}
shard - 分片
bash 复制代码
GET /_cat/shards?v       #(index shard  prirep state docs store ip node)
GET /_cat/shards/*2022.09.05*   #模糊匹配
#https://www.elastic.co/guide/en/elasticsearch/reference/current/diagnose-unassigned-shards.html
GET _cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state  #查看未分配原因
查看段信息
bash 复制代码
GET _cat/segments?v
GET _cat/segments/*-2025.02.06/?v
nodes -节点
bash 复制代码
GET /_cat/nodes?v    #各个节点信息    (ip, cpu load node.role master)
GET /_cat/master?v   #查看master
GET /_cat/nodeattrs?v&format=csv   #查看节点自定义属性(attributes属性、 xpack。mem、jvm。等信息)

GET /                    		#查本地节点
GET /_nodes/					#查本地节点  偏向于启动配置属性
GET /_nodes/stats		 		#查看各个节点详细信息  偏向于运行中各个配置信息
GET /_nodes/_local/stats  		#查本地节点详细信息
GET /_nodes/{node}/stats  		#查看指定节点详细信息  #GET /_nodes/{nodeid}/stats/
GET /_nodes/{node}/name			#查看指定节点简单信息

GET /_nodes/_all/jvm   			#查看节点jvm配置
GET /_nodes/_all/hot_threads    #查看节点热点线程

GET /_stats/request_cache?human                #监控index缓存使用情况
GET /_nodes/stats/indices/request_cache?human  #监控节点缓存使用情况
GET /_nodes/_all/hot_threads
GET /_nodes/stats/indices/search				#节点搜索操作的统计信息
GET /_nodes?filter_path=**.mlockall   							#检查禁用交换分区
GET /_nodes/stats/process?filter_path=**.max_file_descriptors   #检查文件描述符
GET /_nodes/stats?metric=adaptive_selection,breaker,discovery,fs,http,indices,jvm,os,process,thread_pool,transport&filter_path=nodes.*.adaptive_selection*,nodes.*.breaker*,nodes.*.fs*,nodes.*.os*,nodes.*.jvm*,nodes.*.process*,nodes.*.thread_pool*,nodes.*.discovery.cluster_state_queue,nodes.*.discovery.published_cluster_states,nodes.process.*.*,nodes.*.indices*,nodes.*.http.current_open,nodes.*.http.total_opened,_nodes,cluster_name,nodes.*.attributes,nodes.*.timestamp,nodes.*.transport*,nodes.*.transport_address,nodes.*.transport_address,nodes.*.host,nodes.*.ip,,nodes.*.roles,nodes.*.name&pretty
用户与权限
bash 复制代码
GET /_security/user/										#查看用户
GET /_security/user/logstash_transfe						#查看指定用户
GET /_security/role/										#查看授权规则
GET /_security/role/estools_manager							#查看指定授权规则

GET /_security/privilege/_builtin							#内置权限
GET /_security/user/_privileges								#登录用户权限
GET /_security/service										#获得服务帐号
tasks 和 pending_tasks
bash 复制代码
GET /_cat/tasks   #进行的任务
GET /_cat/pending_tasks?v=true   			#等待的任务 通常为0 均衡时可能增加,
    
POST /_tasks/{taksId}/_cancel  				#根据任务ID取消任务
POST /_tasks/_cancel?nodes=nodeId1,nodeId2&actions=*reindex  #根据node批量取消

GET /_tasks?actions=*search&detailed        	#查看search任务详细情况
GET /_tasks?actions=*start_recovery

GET /_tasks?detailed=true&actions=*forcemerge   #查看forceMerge任务详情
GET /_cat/segments/test-000032?v&s=prirep,shard  #查看某个index的forceMerge情况
allocation - 均衡
bash 复制代码
GET /_cat/allocation?v                   #集群节点磁盘使用  
GET /_cluster/allocation/explain?pretty  #均衡失败原因
thread_pool -线程
bash 复制代码
GET /_cat/thread_pool?v    
GET /_cat/thread_pool/force_merge?v&s=name    			#节点forceMerge的线程数	
GET /_cat/thread_pool/analyze?v&h=name,core,host,port   #线程池和节点端口
GET /_cat/thread_pool?v&h=node_name,host,name,type,size,active,largest,rejected,completed,queue,queue_size
templete 模版
bash 复制代码
GET /_template/*                #旧版
GET /_index_template/           #新版
GET _cat/templates/*
GET /_index_template/template-appindex  #查询单个

PUT /_index_template/template-appindex	#创建模版
{
  "index_patterns" : "doris-*",
  "template" : {
  	"settings" : {.....}
  "composed_of" : [ ],
  "priority" : 600,
  "version" : 1
}
#=====添加字段=====================================
PUT template-appindext/_mapping
{
  "properties": {
    "fetch_time" : {
        "type" : "long"
      }
  }
}
ILM 生命周期
bash 复制代码
GET /_ilm/status					#ilm 状态
GET _ilm/policy/lifecycle-appindex	#查看单个配置
GET appindex/_ilm/explain			#索引的ilm 进度


POST /appindex/_ilm/retry			#重试
POST appindex/_ilm/remove			#删除
GET  appindex						#删除后会导致索引关闭
POST appindex/_open  				#索引需要重新打开

PUT _ilm/policy/lifecycle-appindex   #创建ilm 的时候一般是关联的模版
{
    "policy" : {
     "phases" : {...}
    }
}

PUT appindex-*/_settings			#记得修改已创建的index配置
{
  "index": {
    "lifecycle": {
      "name": "lifecycle-appindex"
   }
  }
}
其他
bash 复制代码
GET /_cluster/state/metadata  	#查看元数据 不要使用
GET /_cat/plugins				#查看插件
GET /_alias?pretty				#查看别名
GET /itcast/_mapping 			#查看映射

GET _nodes/stats/breaker			#breaker
GET /_template/template-bro_notice  #查看template
GET /_template						#查看template

GET /_cat/recovery/{index}?v  #监视剩余恢复的进度
GET _cat/recovery/{index}?v=true&h=i,s,t,ty,st,shost,thost,f,fp,b,bp

#熔断器
GET /_cluster/settings?include_defaults=true&flat_settings=true
GET _nodes/stats/breaker

#当前投票节点
GET /_cluster/state?filter_path=metadata.cluster_coordination.last_committed_config
#投票排除配置
POST /_cluster/voting_config_exclusions?node_names=nodeName1,nodeName2
DELETE /_cluster/voting_config_exclusions #删除

#只读排查
GET _all/_stats/?filter_path=indices.*.total.merges
GET _all/_settings/?filter_path=**.blocks

PUT /appindex/_settings				#修改只读
{
  "index": {
    "blocks.read_only_allow_delete": false
  }
}
相关推荐
A小辣椒1 小时前
TShark:基础知识
linux
AlfredZhao3 小时前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
AlfredZhao18 小时前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户9718356334661 天前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux
猪脚踏浪1 天前
linux 拷贝文件或目录到指定的位置
linux
摇滚侠2 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
大志哥1232 天前
ES和Logstash日志链路系统上线后遭遇切片爆炸(解决)
大数据·elasticsearch
bush42 天前
嵌入式linux学习记录十四、术语
linux·嵌入式
载数而行5202 天前
Linux 11 动态监控指令top
linux
不会C语言的男孩2 天前
Linux 系统编程 · 第 8 章:进程基础
linux·c语言