【ELK】ElasticSearch 集群常用管理API利用

[复制链接]
发表于 2025-10-16 04:19:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
目次
常用_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 概览

  1. 介绍几个数据展示参数选项,基本上每个GET /_cat 接口都支持:
  2. //& 多个参数连接符
  3.         GET /_cat/indices?v&s=uuid
  4.         GET /_cat/indices?h=health
  5. //v  or  v=true  打印包含列标题
  6.     GET /_cat/indices?v
  7.     GET /_cat/indices
  8. //help   打印可以显示的列  
  9.         GET /_cat/indices?help
  10.         GET /_cat/shards?help
  11. //h  指定显示列
  12.         GET /_cat/indices?h=health,status,index,uuid,docs.count
  13. //s  排序  正序与倒序
  14.         GET /_cat/indices?v&s=uuid
  15.         GET /_cat/indices?v&s=uuid:desc
  16. //format  指定格式 txt json  csv
  17.         GET /_cat/indices?v&format=json
  18. //GET /_cat/  包含了集群基本信息查询
  19. GET /_cat/allocation
  20. GET /_cat/shards
  21. GET /_cat/shards/{index}
  22. GET /_cat/master
  23. GET /_cat/nodes
  24. GET /_cat/indices
  25. GET /_cat/indices/{index}
  26. GET /_cat/segments
  27. GET /_cat/segments/{index}
  28. GET /_cat/count
  29. GET /_cat/count/{index}
  30. GET /_cat/recovery
  31. GET /_cat/recovery/{index}
  32. GET /_cat/health
  33. GET /_cat/pending_tasks
  34. GET /_cat/aliases
  35. GET /_cat/aliases/{alias}
  36. GET /_cat/thread_pool
  37. GET /_cat/plugins
  38. GET /_cat/fielddata
  39. GET /_cat/fielddata/{fields}
  40. GET /_cat/nodeattrs
  41. GET /_cat/repositories
  42. GET /_cat/snapshots/{repository}
复制代码
集群状态 

  1. GET /_cat/health                                          #集群健康
  2. GET /_cluster/health                                   #集群健康 (json格式比较常用)
  3. GET /_cluster/health?level=shards   #shards健康情况
  4. GET /_cat/master?v&format=json                #master节点信息
  5. GET _cluster/stats                                        #集群状态 包含index 与node 的信息
  6. #集群部署时配置检查
  7. GET /_nodes?filter_path=**.mlockall                             #检查禁用交换分区
  8. GET /_nodes/stats/process?filter_path=**.max_file_descriptors   #检查文件描述符
  9. GET /_nodes/_all/jvm?filter_path=**.input_arguments                                #jvm 参数
  10. GET /_cluster/state?filter_path=metadata.cluster_coordination.last_committed_config  #当前投票节点
复制代码
集群设置

  1. GET /_cluster/settings
  2. GET /_cluster/settings?flat_settings=true                          #查看集群配置(flat_settings json平面格式返回)
  3. GET /_cluster/settings?flat_settings=true&filter_path=transient&pretty   # transient 查看临时配置
  4. GET /_cluster/settings?flat_settings=true&include_defaults&pretty        #查看包含默认配置
  5. PUT /_cluster/settings                                #添加参数数据迁移,用来重启该节点或者该节点下架
  6. {
  7.   "transient": {
  8.     "cluster.routing.allocation.exclude._ip": "192.168.246.48,192.168.246.55"   #参数 为json平面格式返回格式 自动适配
  9.   }
  10. }
  11. PUT /_cluster/settings                                #重平衡并发数
  12. {
  13.   "persistent": {
  14.     "cluster.routing.allocation.cluster_concurrent_rebalance" : "2"
  15.   }
  16. }
复制代码
集群磁盘利用

  1. GET /_cat/allocation?v                                                 #数据节点的分片数量及其磁盘空间                                       
  2. GET _cat/allocation/10.84.246.161           #指定查看节点
  3. GET /_cluster/allocation/explain?pretty     #均衡失败原因
复制代码
索引信息与设置

  1. GET /_dangling         #获取悬空索引 重建集群节点调整容易发生
  2. GET /_cat/indices                                                #查看索引信息
  3. GET /_cat/indices?v&s=store.size:desc   #查看索引信息 按 store.size 排序 (health status index uuid ···)
  4. GET /_cat/indices/?s=segmentsCount:desc&v&h=index,segmentsCount,segmentsMemory,memoryTotal,\
  5.                         mergesCurrent,mergesCurrentDocs,storeSize,p,r     #forcemerge信息
  6.                                 #segamentsCount: segament文件数量,正常情况越少查询效率越高      
  7.                                 #p:当前index有几个分片     r:几份副本
  8.                     
  9. GET /_cat/indices/appindex?v&format=json  #json格式
  10.    
  11. #指定索引信息查看  
  12. GET appindex/                            #查看 appindex  索引信息
  13. GET appindex/_mapping                        #查看 appindex  索引mapping信息
  14. GET appindex/_settings                        #查看 appindex  索引配置信息
  15. GET appindex/_settings?pretty&include_defaults&flat_settings=true        # #查看 appindex  索引配置信息 包含默认配置
  16. PUT appindex/_settings                                #迁移索引
  17. {
  18.   "index.routing.allocation.exclude._name": "oa-cold-60-04"
  19. }
  20. PUT appindex/_settings              #配置单个节点的最大分片数(副本和主分片)
  21. {
  22.   "index.routing.allocation.total_shards_per_node": "8"
  23. }
  24. POST /_cluster/reroute?metric=none                     #迁移分片
  25. {
  26.   "commands": [
  27.     {
  28.       "move": {
  29.         "index": "test", "shard": 0,
  30.         "from_node": "oa-cold-173-02", "to_node": "oa-cold-60-04"
  31.       }
  32.     }
  33.   ]
  34. }
复制代码
shard - 分片

  1. GET /_cat/shards?v       #(index shard  prirep state docs store ip node)
  2. GET /_cat/shards/*2022.09.05*   #模糊匹配
  3. #https://www.elastic.co/guide/en/elasticsearch/reference/current/diagnose-unassigned-shards.html
  4. GET _cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state  #查看未分配原因
复制代码
检察段信息

  1. GET _cat/segments?v
  2. GET _cat/segments/*-2025.02.06/?v
复制代码
nodes -节点

  1. GET /_cat/nodes?v    #各个节点信息    (ip, cpu load node.role master)
  2. GET /_cat/master?v   #查看master
  3. GET /_cat/nodeattrs?v&format=csv   #查看节点自定义属性(attributes属性、 xpack。mem、jvm。等信息)
  4. GET /                                    #查本地节点
  5. GET /_nodes/                                        #查本地节点  偏向于启动配置属性
  6. GET /_nodes/stats                                 #查看各个节点详细信息  偏向于运行中各个配置信息
  7. GET /_nodes/_local/stats                  #查本地节点详细信息
  8. GET /_nodes/{node}/stats                  #查看指定节点详细信息  #GET /_nodes/{nodeid}/stats/
  9. GET /_nodes/{node}/name                        #查看指定节点简单信息
  10. GET /_nodes/_all/jvm                           #查看节点jvm配置
  11. GET /_nodes/_all/hot_threads    #查看节点热点线程
  12. GET /_stats/request_cache?human                #监控监控index缓存使用情况
  13. GET /_nodes/stats/indices/request_cache?human  #监控监控节点缓存使用情况
  14. GET /_nodes/_all/hot_threads
  15. GET /_nodes/stats/indices/search                                #节点搜索操作的统计信息
  16. GET /_nodes?filter_path=**.mlockall                                                           #检查禁用交换分区
  17. GET /_nodes/stats/process?filter_path=**.max_file_descriptors   #检查文件描述符
  18. 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
复制代码
用户与权限

  1. GET /_security/user/                                                                                #查看用户
  2. GET /_security/user/logstash_transfe                                                #查看指定用户
  3. GET /_security/role/                                                                                #查看授权规则
  4. GET /_security/role/estools_manager                                                        #查看指定授权规则
  5. GET /_security/privilege/_builtin                                                        #内置权限
  6. GET /_security/user/_privileges                                                                #登录用户权限
  7. GET /_security/service                                                                                #获得服务帐号
复制代码
tasks 和 pending_tasks

  1. GET /_cat/tasks   #进行的任务
  2. GET /_cat/pending_tasks?v=true                           #等待的任务 通常为0 均衡时可能增加,
  3.    
  4. POST /_tasks/{taksId}/_cancel                                  #根据任务ID取消任务
  5. POST /_tasks/_cancel?nodes=nodeId1,nodeId2&actions=*reindex  #根据node批量取消
  6. GET /_tasks?actions=*search&detailed                #查看search任务详细情况
  7. GET /_tasks?actions=*start_recovery
  8. GET /_tasks?detailed=true&actions=*forcemerge   #查看forceMerge任务详情
  9. GET /_cat/segments/test-000032?v&s=prirep,shard  #查看某个index的forceMerge情况
复制代码
allocation  - 均衡

  1. GET /_cat/allocation?v                   #集群节点磁盘使用  
  2. GET /_cluster/allocation/explain?pretty  #均衡失败原因
复制代码
thread_pool -线程

  1. GET /_cat/thread_pool?v   
  2. GET /_cat/thread_pool/force_merge?v&s=name                            #节点forceMerge的线程数       
  3. GET /_cat/thread_pool/analyze?v&h=name,core,host,port   #线程池和节点端口
  4. GET /_cat/thread_pool?v&h=node_name,host,name,type,size,active,largest,rejected,completed,queue,queue_size
复制代码
templete 模版

  1. GET /_template/*                #旧版
  2. GET /_index_template/           #新版
  3. GET _cat/templates/*
  4. GET /_index_template/template-appindex  #查询单个
  5. PUT /_index_template/template-appindex        #创建模版
  6. {
  7.   "index_patterns" : "doris-*",
  8.   "template" : {
  9.           "settings" : {.....}
  10.   "composed_of" : [ ],
  11.   "priority" : 600,
  12.   "version" : 1
  13. }
  14. #=====添加字段=====================================
  15. PUT template-appindext/_mapping
  16. {
  17.   "properties": {
  18.     "fetch_time" : {
  19.         "type" : "long"
  20.       }
  21.   }
  22. }
复制代码
ILM 生命周期

  1. GET /_ilm/status                                        #ilm 状态
  2. GET _ilm/policy/lifecycle-appindex        #查看单个配置
  3. GET appindex/_ilm/explain                        #索引的ilm 进度
  4. POST /appindex/_ilm/retry                        #重试
  5. POST appindex/_ilm/remove                        #删除
  6. GET  appindex                                                #删除后会导致索引关闭
  7. POST appindex/_open                                  #索引需要重新打开
  8. PUT _ilm/policy/lifecycle-appindex   #创建ilm 的时候一般是关联的模版
  9. {
  10.     "policy" : {
  11.      "phases" : {...}
  12.     }
  13. }
  14. PUT appindex-*/_settings                        #记得修改已创建的index配置
  15. {
  16.   "index": {
  17.     "lifecycle": {
  18.       "name": "lifecycle-appindex"
  19.    }
  20.   }
  21. }
复制代码
其他

  1. GET /_cluster/state/metadata          #查看元数据 不要使用
  2. GET /_cat/plugins                                #查看插件
  3. GET /_alias?pretty                                #查看别名
  4. GET /itcast/_mapping                         #查看映射
  5. GET _nodes/stats/breaker                        #breaker
  6. GET /_template/template-bro_notice  #查看template
  7. GET /_template                                                #查看template
  8. GET /_cat/recovery/{index}?v  #监视剩余恢复的进度
  9. GET _cat/recovery/{index}?v=true&h=i,s,t,ty,st,shost,thost,f,fp,b,bp
  10. #熔断器
  11. GET /_cluster/settings?include_defaults=true&flat_settings=true
  12. GET _nodes/stats/breaker
  13. #当前投票节点
  14. GET /_cluster/state?filter_path=metadata.cluster_coordination.last_committed_config
  15. #投票排除配置
  16. POST /_cluster/voting_config_exclusions?node_names=nodeName1,nodeName2
  17. DELETE /_cluster/voting_config_exclusions #删除
  18. #只读排查
  19. GET _all/_stats/?filter_path=indices.*.total.merges
  20. GET _all/_settings/?filter_path=**.blocks
  21. PUT /appindex/_settings                                #修改只读
  22. {
  23.   "index": {
  24.     "blocks.read_only_allow_delete": false
  25.   }
  26. }
复制代码

回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表