当前位置: 首页 > article >正文

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

目录

常用_cat 概览

集群状态 

集群配置

集群磁盘使用

索引信息与配置

shard - 分片

查看段信息

nodes -节点

用户与权限

tasks 和 pending_tasks

allocation  - 均衡

thread_pool -线程

templete 模版

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 概览
介绍几个数据展示参数选项,基本上每个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}
集群状态 
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  #当前投票节点
集群配置
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"
  }
}
集群磁盘使用
GET /_cat/allocation?v 						#数据节点的分片数量及其磁盘空间					
GET _cat/allocation/10.84.246.161           #指定查看节点 
GET /_cluster/allocation/explain?pretty     #均衡失败原因
索引信息与配置
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 - 分片
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  #查看未分配原因
查看段信息
GET _cat/segments?v
GET _cat/segments/*-2025.02.06/?v
nodes -节点
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
用户与权限
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
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  - 均衡
GET /_cat/allocation?v                   #集群节点磁盘使用  
GET /_cluster/allocation/explain?pretty  #均衡失败原因
thread_pool -线程
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 模版
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 生命周期
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"
   }
  }
}
其他
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
  }
}


http://www.kler.cn/a/582555.html

相关文章:

  • ChebyKAN0、ChebyKAN1 网络阅读
  • 常用Kotlin方法
  • jmeter接口测试(三)
  • 前端 - uniapp - - 滚动容器scroll-view实现横向滚动
  • BFS最短路径(十六)127. 单词接龙 困难
  • zabbix报警结合AI进行智能分析
  • 某快餐店用户市场数据挖掘与可视化
  • c++ enum使用笔记
  • RocketMQ 集群架构与部署实践(一)
  • Flutter_学习记录_device_info_plus 插件获取设备信息
  • Java糊涂包(Hutool)的安装教程并进行网络爬虫
  • FreeBSD下安装npm Node.js的22版本 并简单测试js服务器
  • 【Golang】第三弹----运算符
  • Python多版本环境管理UV
  • Linux上位机开发实战(qt编译之谜)
  • Spring 框架面试题集:常见问题解析
  • mysql安装与使用
  • 2024年广州市智能网联汽车创新实践年度报告
  • 文件上传漏洞 upload-labs靶场
  • upload-labs-靶场(1-19关)通关攻略