Elasticsearch - es接口查询操作调用测试记录

elasticsearch:

常用的es接口查询操作命令:

  curl http://elasticsearch:9200/
  ##这三条shell命令都可以监控到Elasticsearch健康状态
  curl http://elasticsearch:9200/_cat/health
  curl http://elasticsearch:9200/_cluster/health
  curl http://elasticsearch:9200/_cluster/health?pretty
  ##查看Elasticsearch健康状态  (*表示ES集群的master主节点)
  curl http://elasticsearch:9200/_cat/nodes?v
  curl http://elasticsearch:9200/_cat/health?v
  ##查看Elasticsearch 索引状态  (*表示ES集群的master主节点)
  curl http://elasticsearch:9200/_cat/indices?v
  curl http://elasticsearch:9200/_cluster/health?level=indices
  ##单节点 删除那些指定不明确的副本分片 集群的状态状态变成了green
  curl -XPUT -H 'Content-Type: application/json' "http://elasticsearch:9200/_settings" -d '{ "number_of_replicas" : 0 }'  
  ##查看集群中不同节点、不同索引的状态
  curl http://elasticsearch:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason
  ##这个分片数据已经不可用,直接删除该分片 (即删除索引)--极端情况
  curl -X DELETE http://elasticsearch:9200/索引名
  ##使用curl命令模拟访问任意一个elasticsearch集群
  curl http://elasticsearch:9200/_cluster/stats?human&pretty
  ##查看出问题的索引以及原因
  curl http://elasticsearch:9200/_cluster/allocation/explain?pretty
  ##尝试重新恢复失败的分片
  curl -XPOST -H 'Content-Type: application/json' http://elasticsearch:9200/_cluster/reroute?retry_failed=true

  正常情况下,Elasticsearch 集群健康状态分为三种:
  green      最健康得状态,说明所有的分片包括备份都可用; 这种情况Elasticsearch集群所有的主分片和副本分片都已分配, Elasticsearch集群是 100% 可用的。
  yellow     基本的分片可用,但是备份不可用(或者是没有备份);  这种情况Elasticsearch集群所有的主分片已经分片了,但至少还有一个副本是缺失的。不会有数据丢失,所以搜索结果依然是完整的。不过,你的高可用性在某种程度上被弱化。如果 更多的 分片消失,你就会丢数据了。把 yellow 想象成一个需要及时调查的警告。
  red    部分的分片可用,表明分片有一部分损坏。此时执行查询部分数据仍然可以查到,遇到这种情况,还是赶快解决比较好; 这种情况Elasticsearch集群至少一个主分片(以及它的全部副本)都在缺失中。这意味着你在缺少数据:搜索只能返回部分数据,而分配到这个分片上的写入请求会返回一个异常。
  
  单点单节点部署Elasticsearch, 集群状态可能为yellow, 因为单点部署Elasticsearch, 默认的分片副本数目配置为1,而相同的分片不能在一个节点上,所以就存在副本分片指定不明确的问题,所以显示为yellow

  unassigned 分片问题可能的原因?
    INDEX_CREATED:  由于创建索引的API导致未分配。
    CLUSTER_RECOVERED:  由于完全集群恢复导致未分配。
    INDEX_REOPENED:  由于打开open或关闭close一个索引导致未分配。
    DANGLING_INDEX_IMPORTED:  由于导入dangling索引的结果导致未分配。
    NEW_INDEX_RESTORED:  由于恢复到新索引导致未分配。
    EXISTING_INDEX_RESTORED:  由于恢复到已关闭的索引导致未分配。
    REPLICA_ADDED:  由于显式添加副本分片导致未分配。
    ALLOCATION_FAILED:  由于分片分配失败导致未分配。
    NODE_LEFT:  由于承载该分片的节点离开集群导致未分配。
    REINITIALIZED:  由于当分片从开始移动到初始化时导致未分配(例如,使用影子shadow副本分片)。
    REROUTE_CANCELLED:  作为显式取消重新路由命令的结果取消分配。
    REALLOCATED_REPLICA:  确定更好的副本位置被标定使用,导致现有的副本分配被取消,出现未分配。
  
kibana:

    https://artifacts.elastic.co/downloads/kibana/kibana-oss-7.0.1-windows-x86_64.zip

    ##下载oos版本的kibana(应与es的版本保持一致,防止出现意外情况)
    https://www.docker.elastic.co/r/kibana/kibana-oss

  docker 方式:

    docker pull docker.elastic.co/kibana/kibana-oss:7.0.1

    docker run -d -p 5601:5601 --name kb 2c45a33188a0

    find / -name kibana.yml ##找到容器对应的日志文件,将连接elasticsearch的url改成es的ip;

    docker restart kb   ## 修改完配置文件后需要重启一下kibana容器,使配置生效;

    /app/kibana ##7.x默认访问路径

 

posted @ 2022-01-27 18:35  zhangdaopin  阅读(1023)  评论(0编辑  收藏  举报