docker - 如何通过docker管理连接被拒绝错误elasticsearch-kibana-nginx?

标签 docker elasticsearch nginx docker-compose kibana

也许我花了 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 Docker 文件:
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

最佳答案

elasticsearch.yml将第一行更改为:

network.host: 0.0.0.0

以前,您告诉 elasticsearch 仅在 localhost 上监听,因此来自其他容器的任何连接都不会按预期工作,因为 Elasticsearch 服务未在其他接口(interface)上监听,但是当您将其设置为 0.0.0.0 时您将使 elasticsearch 能够接收来自其他容器的连接,并且您不应该得到 Connection Refused问题

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

The next part below is out of the question scope but worth mentioning.



您可能需要更换 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 ,您的方式和这些脚本都使您能够在启动另一个容器的服务之前等待另一个连接可用。

关于docker - 如何通过docker管理连接被拒绝错误elasticsearch-kibana-nginx?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55324233/

相关文章:

php - 为什么 file_put_contents() 有时会抛出 "No error"错误?

linux - 隐藏文件 .env 未使用 Docker COPY 复制

Docker 上的 Django - 关系 "django_session"在字符 109 处不存在

amazon-web-services - AWS和ELB网络吞吐量限制

elasticsearch - 如何使用流利的为 Elasticsearch 添加时间戳和 key

google-chrome - HTTP/2 服务器推送导致重复请求

linux - Docker 构建失败并显示 "RUN: command not found"

docker - 没有基本身份验证凭据 - `docker push image_name`

elasticsearch - Elasticsearch V5 Analyzer演示示例不起作用

wordpress - Varnish + nginx ssl + woocommerce - wc-ajax 不正常