【问题标题】:how to manage connection refuse error elasticsearc-kibana-nginx over docker?如何通过docker管理连接被拒绝错误elasticsearch-kibana-nginx?
【发布时间】:2019-08-14 21:26:36
【问题描述】:

也许我花了 6 个小时在谷歌上搜索以找到答案。但我找不到任何解决方案。我想用 nginx 增加 1 个节点 elasticsearch +1 kibana(用于负载平衡、代理和安全问题)但是当 docker 在 kibana 部分创建错误时。如何使用以下代码在 nginx 上托管 elasticsearch node-kibana?

Error:Unable to revive connection: http://elasticsearch:9200/

Elasticsearch.yml:

network.host: localhost
http.port: 9200
xpack.security.enabled: false
xpack.monitoring.enabled: true
xpack.graph.enabled: false
xpack.watcher.enabled: false

ElasticSearch Dockerfile:

FROM docker.elastic.co/elasticsearch/elasticsearch:6.6.2
COPY ./config/elasticsearch.yml /usr/share/elasticsearch/config/elasticsearch.yml 
RUN elasticsearch-plugin  install analysis-kuromoji

kibana.yml:

---
# Default Kibana configuration from kibana-docker.

server.name: kibana
server.host: "0"
elasticsearch.url: http://elasticsearch:9200
elasticsearch.username: elastic
elasticsearch.password: changeme
xpack.monitoring.ui.container.elasticsearch.enabled: true

Kibana Dockerfile:

FROM docker.elastic.co/kibana/kibana:6.6.2
COPY ./config/kibana.yml /opt/kibana/config/kibana.yml
RUN apt-get update && apt-get install -y netcat
COPY entrypoint.sh /tmp/entrypoint.sh
RUN chmod +x /tmp/entrypoint.sh
RUN kibana plugin --install elastic/sense
CMD ["/tmp/entrypoint.sh"]

入口点.sh:

#!/usr/bin/env bash

# Wait for the Elasticsearch container to be ready before starting Kibana.
echo "Stalling for Elasticsearch"
while true; do
  nc -q 1 elasticsearch 9200 2>/dev/null && break
done
echo "Starting Kibana"
exec kibana

nginx.conf:

upstream elasticsearch {
  server 38.252.127.221:9200;
  keepalive 15;
}

upstream kibana {
  server 38.252.127.221:5601;
  keepalive 15;
}

server {
  listen 9200;

  location / {
    auth_basic           "Protected Elasticsearch";
    auth_basic_user_file /etc/nginx/htpasswd.users;

    proxy_pass http://elasticsearch;
    proxy_redirect off;
    proxy_buffering off;

    proxy_http_version 1.1;
    proxy_set_header Connection "Keep-Alive";
    proxy_set_header Proxy-Connection "Keep-Alive";
  }
}

server {
  listen 5601;
  location / {
    auth_basic           "Protected Kibana";
    auth_basic_user_file /etc/nginx/htpasswd.users;
    proxy_pass  http://kibana;
    proxy_redirect off;
    proxy_buffering off;
    proxy_http_version 1.1;
    proxy_set_header Connection "Keep-Alive";
    proxy_set_header Proxy-Connection "Keep-Alive";
  }
}

docker-compose.yml

version: '2'
services:
 elasticsearch:
container_name: esc
image: esi:1.0.0
build: ./es
volumes:
  - ./data/es:/usr/share/elasticsearch/data
ports:
    - 9200:9200
expose:
    - 9300
kibana:
container_name: kibanac
image: kibanai:1.0.0
build: ./kibana
links:
  - elasticsearch
ports:
  - 5601:5601
nginx:
image: nginx:latest
restart: unless-stopped
volumes:
  - ./nginx/config:/etc/nginx/conf.d:ro,Z
  - ./nginx/htpasswd.users:/etc/nginx/htpasswd.users:ro,Z
ports:
  - "8900:5601"
  - "8901:9200"

 depends_on:
  - elasticsearch
  - kibana

【问题讨论】:

    标签: docker elasticsearch nginx docker-compose kibana


    【解决方案1】:

    elasticsearch.yml 中将第一行更改为:

    network.host: 0.0.0.0
    

    之前您告诉 elasticsearch 仅在 localhost 上侦听,因此来自其他容器的任何连接都不会按预期工作,因为弹性搜索服务未在其他接口上侦听但是当您将其设置为 0.0.0.0 时,您将使 elasticsearch 能够从其他容器接收连接,你不应该得到Connection Refused 问题

    另外请注意,您不需要发布 9200、5601 端口,因为这将使任何人都可以直接调用它们而无需通过 nginx 基本身份验证。

    下面的下一部分不在问题范围内,但值得一提。

    您可能需要替换下面添加的entrypoint.sh 的这一部分:

    # Wait for the Elasticsearch container to be ready before starting Kibana.
    echo "Stalling for Elasticsearch"
    while true; do
      nc -q 1 elasticsearch 9200 2>/dev/null && break
    done
    

    通过使用wait-for-itwait-for,您的方式和这些脚本都可以让您在启动另一个容器的服务之前等待另一个连接可用。

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 2018-12-02
      • 2021-05-28
      • 2021-06-27
      • 2020-09-21
      • 2017-05-20
      • 1970-01-01
      • 1970-01-01
      • 2019-01-28
      相关资源
      最近更新 更多