【问题标题】:How to check Elasticsearch cluster health?如何检查 Elasticsearch 集群的健康状况?
【发布时间】:2020-08-09 15:02:19
【问题描述】:

我尝试通过

查看
curl -XGET 'http://localhost:9200/_cluster/health'

但什么也没发生。好像在等什么。控制台没有回来。必须用 CTRL+C 杀死它。

我还尝试通过

检查现有索引
curl -XGET 'http://localhost:9200/_cat/indices?v'

与上述相同的行为。

【问题讨论】:

  • 看起来你的集群已经死了? elasticsearch 真的在运行吗?
  • 是的,curl -XGET localhost:9200 和 curl -XGET localhost:9200/_status 工作正常。
  • 我发现在我评论#network.publish_host: localhost 和#network.host: localhost 之后,它工作正常。什么?
  • 您是否更改了这些默认设置?
  • 如果您阅读有关这些设置的文档 (elasticsearch.org/guide/en/elasticsearch/reference/current/…),那么您必须从那里指定可解析的主机名或地址。 localhost 两者都不是。

标签: elasticsearch


【解决方案1】:

要检查您需要使用的 elasticsearch 集群运行状况

curl localhost:9200/_cat/health

更多关于 cat API here.

我通常使用 elasticsearch-head 插件将其可视化。

你可以找到它的github项目here

很容易安装sudo $ES_HOME/bin/plugin -i mobz/elasticsearch-head 然后你可以在你的网络浏览器中打开localhost:9200/_plugin/head/

你应该有这样的东西:

【讨论】:

  • Error (52) Empty reply from server 当我尝试执行上述命令时
  • @AzharUddinSheikh 您可能对集群进行了某种安全检查。也许它受到某种密钥或证书的保护......
【解决方案2】:

您可以使用 (CURL) 和 elasticsearch 提供的集群 API 检查 elasticsearch 集群健康状况:

$ curl -XGET 'localhost:9200/_cluster/health?pretty'

这将为您提供所需的状态和其他相关数据。

{
 "cluster_name" : "xxxxxxxx",
 "status" : "green",
 "timed_out" : false,
 "number_of_nodes" : 2,
 "number_of_data_nodes" : 2,
 "active_primary_shards" : 15,
 "active_shards" : 12,
 "relocating_shards" : 0,
 "initializing_shards" : 0,
 "unassigned_shards" : 0,
 "delayed_unassigned_shards" : 0,
 "number_of_pending_tasks" : 0,
 "number_of_in_flight_fetch" : 0
}

【讨论】:

    【解决方案3】:

    _cluster/health API 可以做的远远超过大多数人看到的典型输出:

     $ curl -XGET 'localhost:9200/_cluster/health?pretty'
    

    Elasticsearch 中的大多数 API 都可以采用各种参数来增加其输出。这也适用于Cluster Health API

    示例

    所有指标的健康状况
    $ curl -XGET 'localhost:9200/_cluster/health?level=indices&pretty' | head -50
    {
      "cluster_name" : "rdu-es-01",
      "status" : "green",
      "timed_out" : false,
      "number_of_nodes" : 9,
      "number_of_data_nodes" : 6,
      "active_primary_shards" : 1106,
      "active_shards" : 2213,
      "relocating_shards" : 0,
      "initializing_shards" : 0,
      "unassigned_shards" : 0,
      "delayed_unassigned_shards" : 0,
      "number_of_pending_tasks" : 0,
      "number_of_in_flight_fetch" : 0,
      "task_max_waiting_in_queue_millis" : 0,
      "active_shards_percent_as_number" : 100.0,
      "indices" : {
        "filebeat-6.5.1-2019.06.10" : {
          "status" : "green",
          "number_of_shards" : 3,
          "number_of_replicas" : 1,
          "active_primary_shards" : 3,
          "active_shards" : 6,
          "relocating_shards" : 0,
          "initializing_shards" : 0,
          "unassigned_shards" : 0
        },
        "filebeat-6.5.1-2019.06.11" : {
          "status" : "green",
          "number_of_shards" : 3,
          "number_of_replicas" : 1,
          "active_primary_shards" : 3,
          "active_shards" : 6,
          "relocating_shards" : 0,
          "initializing_shards" : 0,
          "unassigned_shards" : 0
        },
        "filebeat-6.5.1-2019.06.12" : {
          "status" : "green",
          "number_of_shards" : 3,
          "number_of_replicas" : 1,
          "active_primary_shards" : 3,
          "active_shards" : 6,
          "relocating_shards" : 0,
          "initializing_shards" : 0,
          "unassigned_shards" : 0
        },
        "filebeat-6.5.1-2019.06.13" : {
          "status" : "green",
          "number_of_shards" : 3,
    
    所有碎片的健康状况
    $ curl -XGET 'localhost:9200/_cluster/health?level=shards&pretty' | head -50
    {
      "cluster_name" : "rdu-es-01",
      "status" : "green",
      "timed_out" : false,
      "number_of_nodes" : 9,
      "number_of_data_nodes" : 6,
      "active_primary_shards" : 1106,
      "active_shards" : 2213,
      "relocating_shards" : 0,
      "initializing_shards" : 0,
      "unassigned_shards" : 0,
      "delayed_unassigned_shards" : 0,
      "number_of_pending_tasks" : 0,
      "number_of_in_flight_fetch" : 0,
      "task_max_waiting_in_queue_millis" : 0,
      "active_shards_percent_as_number" : 100.0,
      "indices" : {
        "filebeat-6.5.1-2019.06.10" : {
          "status" : "green",
          "number_of_shards" : 3,
          "number_of_replicas" : 1,
          "active_primary_shards" : 3,
          "active_shards" : 6,
          "relocating_shards" : 0,
          "initializing_shards" : 0,
          "unassigned_shards" : 0,
          "shards" : {
            "0" : {
              "status" : "green",
              "primary_active" : true,
              "active_shards" : 2,
              "relocating_shards" : 0,
              "initializing_shards" : 0,
              "unassigned_shards" : 0
            },
            "1" : {
              "status" : "green",
              "primary_active" : true,
              "active_shards" : 2,
              "relocating_shards" : 0,
              "initializing_shards" : 0,
              "unassigned_shards" : 0
            },
            "2" : {
              "status" : "green",
              "primary_active" : true,
              "active_shards" : 2,
              "relocating_shards" : 0,
              "initializing_shards" : 0,
              "unassigned_shards" : 0
    

    API 还具有多种wait_* 选项,它会在立即返回之前或在某些指定的timeout 之后等待各种状态更改。

    【讨论】:

      【解决方案4】:

      如果 Elasticsearch 集群不可访问(例如在防火墙后面),但 Kibana 是:

      Kibana => DevTools => 控制台:

      GET /_cluster/health 
      

      【讨论】:

      • 这确实有效,但 Kibana 如何自动连接到 ES?
      • @HarishNarayanan,它不是自动的 - 它是默认的或通过配置。 Kibana 只是将那些来自 UI 的 GET /_cluster/health 请求附加到它用于连接到 Elasticsearch 的基本 URL(例如 http://localhost:9200)。使用 Kibana 的关键在于,您甚至可能没有对 Elasticsearch 的网络访问权限(例如,没有从集群中公开)——只要您可以访问 Kibana,您仍然可以执行这些查询。
      • 知道了@uvsmtid。我查看了配置文件夹和相关的 yml 文件。得到所需的信息。非常感谢
      【解决方案5】:

      问题:-

      有时,Localhost 可能无法解析。 所以它往往会返回如下所示的输出:

      # curl -XGET localhost:9200/_cluster/health?pretty

      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
      <html><head>
      <meta http-equiv="Content-Type" CONTENT="text/html; charset=iso-8859-1">
      <title>ERROR: The requested URL could not be retrieved</title>
      <style type="text/css"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}PRE{font-family:sans-serif}--></style>
      </head><body>
      <h1>ERROR</h1>
      <h2>The requested URL could not be retrieved</h2>
      <hr>
      <p>The following error was encountered while trying to retrieve the URL: <a href="http://localhost:9200/_cluster/health?">http://localhost:9200/_cluster/health?</a></p>
      <blockquote>
      <p><b>Connection to 127.0.0.1 failed.</b></p>
      </blockquote>
      
      <p>The system returned: <i>(111) Connection refused</i></p>
      
      <p>The remote host or network may be down.  Please try the request again.</p>
      <p>Your cache administrator is <a href="mailto:root?subject=CacheErrorInfo%20-%20ERR_CONNECT_FAIL&amp;body=CacheHost%3A%20squid2%0D%0AErrPage%3A%20ERR_CONNECT_FAIL%0D%0AErr%3A%20(111)%20Connection%20refused%0D%0ATimeStamp%3A%20Mon,%2017%20Dec%202018%2008%3A07%3A36%20GMT%0D%0A%0D%0AClientIP%3A%20192.168.13.14%0D%0AServerIP%3A%20127.0.0.1%0D%0A%0D%0AHTTP%20Request%3A%0D%0AGET%20%2F_cluster%2Fhealth%3Fpretty%20HTTP%2F1.1%0AUser-Agent%3A%20curl%2F7.29.0%0D%0AHost%3A%20localhost%3A9200%0D%0AAccept%3A%20*%2F*%0D%0AProxy-Connection%3A%20Keep-Alive%0D%0A%0D%0A%0D%0A">root</a>.</p>
      
      <br>   
      <hr> 
      <div id="footer">Generated Mon, 17 Dec 2018 08:07:36 GMT by squid2 (squid/3.0.STABLE25)</div>
      </body></html>
      

      # curl -XGET localhost:9200/_cat/indices

      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
      <html><head>
      <meta http-equiv="Content-Type" CONTENT="text/html; charset=iso-8859-1">
      <title>ERROR: The requested URL could not be retrieved</title>
      <style type="text/css"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}PRE{font-family:sans-serif}--></style>
      </head><body>
      <h1>ERROR</h1>
      <h2>The requested URL could not be retrieved</h2>
      <hr>
      <p>The following error was encountered while trying to retrieve the URL: <a href="http://localhost:9200/_cat/indices">http://localhost:9200/_cat/indices</a></p>
      <blockquote>
      <p><b>Connection to 127.0.0.1 failed.</b></p>
      </blockquote>
      
      <p>The system returned: <i>(111) Connection refused</i></p>
      
      <p>The remote host or network may be down.  Please try the request again.</p>
      <p>Your cache administrator is <a href="mailto:root?subject=CacheErrorInfo%20-%20ERR_CONNECT_FAIL&amp;body=CacheHost%3A%20squid2%0D%0AErrPage%3A%20ERR_CONNECT_FAIL%0D%0AErr%3A%20(111)%20Connection%20refused%0D%0ATimeStamp%3A%20Mon,%2017%20Dec%202018%2008%3A10%3A09%20GMT%0D%0A%0D%0AClientIP%3A%20192.168.13.14%0D%0AServerIP%3A%20127.0.0.1%0D%0A%0D%0AHTTP%20Request%3A%0D%0AGET%20%2F_cat%2Findices%20HTTP%2F1.1%0AUser-Agent%3A%20curl%2F7.29.0%0D%0AHost%3A%20localhost%3A9200%0D%0AAccept%3A%20*%2F*%0D%0AProxy-Connection%3A%20Keep-Alive%0D%0A%0D%0A%0D%0A">root</a>.</p>
      
      <br>   
      <hr> 
      <div id="footer">Generated Mon, 17 Dec 2018 08:10:09 GMT by squid2 (squid/3.0.STABLE25)</div>
      </body></html>
      

      解决方案:-

      猜猜,这个错误很可能是服务器中部署的Local Squid返回的。

      因此,在将 localhost 替换为已部署 ElasticSearch 的 local_ip 后,它运行良好。

      【讨论】:

        猜你喜欢
        • 2020-02-17
        • 2019-03-03
        • 1970-01-01
        • 2019-10-25
        • 2018-04-19
        • 1970-01-01
        • 2022-06-27
        • 2020-08-02
        • 1970-01-01
        相关资源
        最近更新 更多