运行 docker 上的 ELK,Kibana 说:无法从 Elasticsearch 节点检索版本信息

Running ELK on docker, Kibana says: Unable to retrieve version information from Elasticsearch nodes

我指的是在 elasticsearch 文档中给出的 example 使用 docker compose 在 docker 上启动弹性堆栈(elastic 和 kibana)。它给出了 docker 撰写 2.2 版文件的示例。因此,我尝试将其转换为 docker compose 3.8 版文件。此外,它还创建了三个弹性节点并启用了安全性。我想从一开始就把它保持在最低限度。所以我尝试关闭安全性并将弹性节点的数量减少到 2。这就是我当前的撰写文件的样子:

version: "3.8"

services:  
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.0.0-amd64
    volumes:
      - esdata01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    environment:
      - node.name=es01
      - cluster.name=docker-cluster
      - cluster.initial_master_nodes=es01
      - bootstrap.memory_lock=true
      - xpack.security.enabled=false
    deploy:
      resources:
        limits:
          memory: 1g 
    
    ulimits:
      memlock:
        soft: -1
        hard: -1
    healthcheck:
      # [
      #   "CMD-SHELL",
      #   # "curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
      # ]

      # Changed to:
      test: ["CMD-SHELL", "curl -f http://localhost:9200 || exit 1"]

      interval: 10s
      timeout: 10s
      retries: 120
  kibana:
    depends_on:
      - es01
    image: docker.elastic.co/kibana/kibana:8.0.0-amd64
    volumes:
      - kibanadata:/usr/share/kibana/data
    ports:
      - 5601:5601
    environment:
      - SERVERNAME=kibana
      - ELASTICSEARCH_HOSTS=https://localhost:9200
    deploy:
      resources:
        limits:
          memory: 1g
    healthcheck:
      test:
        [
          "CMD-SHELL",
          "curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found'",
        ]
      interval: 10s
      timeout: 10s
      retries: 120
volumes:
  esdata01:
    driver: local
  kibanadata:
    driver: local

然后,我试着运行吧:

docker stack deploy -c docker-compose.nosec.noenv.yml elk
Creating network elk_default
Creating service elk_es01
Creating service elk_kibana

当我试图检查他们的状态时,它显示如下:

$ docker container list
CONTAINER ID   IMAGE                                                       COMMAND                  CREATED         STATUS                            PORTS                NAMES
3dcd08134e38   docker.elastic.co/kibana/kibana:8.0.0-amd64                 "/bin/tini -- /usr/l…"   3 minutes ago   Up 3 minutes (health: starting)   5601/tcp             elk_kibana.1.ng8aspz9krfnejfpsnqzl2sci
7b548a43c45c   docker.elastic.co/elasticsearch/elasticsearch:8.0.0-amd64   "/bin/tini -- /usr/l…"   3 minutes ago   Up 3 minutes (healthy)            9200/tcp, 9300/tcp   elk_es01.1.d9a107j6wkz42shti3n6kpfmx
            

我注意到 kibana 的状态卡在 (health: starting)。当我使用命令 docker service logs -f elk_kibana 检查 Kibana 的日志时,它有以下 WARNERROR 行:

[WARN ][plugins.security.config] Generating a random key for xpack.security.encryptionKey. To prevent sessions from being invalidated on restart, please set xpack.security.encryptionKey in the kibana.yml or use the bin/kibana-encryption-keys command.
[WARN ][plugins.security.config] Session cookies will be transmitted over insecure connections. This is not recommended.
[WARN ][plugins.security.config] Generating a random key for xpack.security.encryptionKey. To prevent sessions from being invalidated on restart, please set xpack.security.encryptionKey in the kibana.yml or use the bin/kibana-encryption-keys command.
[WARN ][plugins.security.config] Session cookies will be transmitted over insecure connections. This is not recommended.
[WARN ][plugins.reporting.config] Generating a random key for xpack.reporting.encryptionKey. To prevent sessions from being invalidated on restart, please set xpack.reporting.encryptionKey in the kibana.yml or use the bin/kibana-encryption-keys command.
[WARN ][plugins.reporting.config] Found 'server.host: "0.0.0.0"' in Kibana configuration. Reporting is not able to use this as the Kibana server hostname. To enable PNG/PDF Reporting to work, 'xpack.reporting.kibanaServer.hostname: localhost' is automatically set in the configuration. You can prevent this message by adding 'xpack.reporting.kibanaServer.hostname: localhost' in kibana.yml.
[ERROR][elasticsearch-service] Unable to retrieve version information from Elasticsearch nodes. connect ECONNREFUSED 127.0.0.1:9200

好像kibana无法连接Elasticsearch,为什么?是不是因为禁用了安全性而我们不能禁用安全性?

PS-1: 早些时候,当我在 docker compose 文件中的 kibana 环境中如下设置 elasticsearch host 时:

ELASTICSEARCH_HOSTS=https://es01:9200  # that is 'es01' instead of `localhost`

它给了我以下错误:

[ERROR][elasticsearch-service] Unable to retrieve version information from Elasticsearch nodes. getaddrinfo ENOTFOUND es01

所以,在检查了问题之后,我将es01更改为之前指定的localhost(即完整docker在[=51=之前撰写文件内容]-1.)

PS-2:localhost 替换为 192.168.0.104 会出现以下错误

[ERROR][elasticsearch-service] Unable to retrieve version information from Elasticsearch nodes. connect ECONNREFUSED 192.168.0.104:9200
[ERROR][elasticsearch-service] Unable to retrieve version information from Elasticsearch nodes. write EPROTO 140274197346240:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:

试试这个:

ELASTICSEARCH_HOSTS=http://es01:9200

我不知道为什么它可以 运行 在我的电脑上,因为 Elasticsearch 应该使用 SSL。但在你的情况下使用 http 工作得很好。