如何管理超过 docker 的连接拒绝错误 elasticsearch-kibana-nginx?
how to manage connection refuse error elasticsearc-kibana-nginx over docker?
也许我用了 6 个小时谷歌搜索来寻找答案。但我找不到任何解决方案。我想用 nginx 启动 1 个节点 elasticsearch +1 kibana(用于负载平衡、代理和安全问题)但是当 docker 在 kibana part.How 上创建错误时,我可以使用 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"]
entrypoint.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 仅在本地主机上侦听,因此来自其他容器的任何连接都不会按预期工作,因为 elastic search 服务未在其他接口上侦听,但是当您将其设置为 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-it or wait-for,您的方式和这些脚本都可以让您在启动另一个容器的服务之前等待另一个连接可用。
也许我用了 6 个小时谷歌搜索来寻找答案。但我找不到任何解决方案。我想用 nginx 启动 1 个节点 elasticsearch +1 kibana(用于负载平衡、代理和安全问题)但是当 docker 在 kibana part.How 上创建错误时,我可以使用 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"]
entrypoint.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 仅在本地主机上侦听,因此来自其他容器的任何连接都不会按预期工作,因为 elastic search 服务未在其他接口上侦听,但是当您将其设置为 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-it or wait-for,您的方式和这些脚本都可以让您在启动另一个容器的服务之前等待另一个连接可用。