繁体   English   中英

Elasticsearch错误:无法连接到本地主机端口9200:连接被拒绝

[英]Elasticsearch error: Failed to connect to localhost port 9200: Connection refused

我正在尝试创建安装了Elasticsearch的Docker映像。 我知道Elasticsearch已经有他的自定义Docker映像,但是我需要使用安装了Python 3.6.5的AWS Lambda Function的相同环境。 因此,我必须扩展AWS Docker映像,并且必须安装Elasticsearch服务。

在这里您可以找到我的Dockerfile:

FROM lambci/lambda-base:build

ENV PATH=/var/lang/bin:$PATH \
    LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \
    AWS_EXECUTION_ENV=AWS_Lambda_python3.6 \
    PYTHONPATH=/var/runtime \
    PKG_CONFIG_PATH=/var/lang/lib/pkgconfig:/usr/lib64/pkgconfig:/usr/share/pkgconfig

RUN rm -rf /var/runtime /var/lang && \
  curl https://lambci.s3.amazonaws.com/fs/python3.6.tgz | tar -xz -C / && \
  sed -i '/^prefix=/c\prefix=/var/lang' /var/lang/lib/pkgconfig/python-3.6.pc && \
  curl https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz | tar -xJ && \
  cd Python-3.6.8 && \
  LIBS="$LIBS -lutil -lrt" ./configure --prefix=/var/lang && \
  make -j$(getconf _NPROCESSORS_ONLN) libinstall libainstall inclinstall && \
  cd .. && \
  rm -rf Python-3.6.8

EXPOSE 9200 9300

# Add these as a separate layer as they get updated frequently
RUN pip install -U pip setuptools --no-cache-dir && \
    pip install -U virtualenv pipenv --no-cache-dir && \
    pip install -U awscli boto3 aws-sam-cli==0.10.0 aws-lambda-builders==0.1.0 --no-cache-dir && \
    yum install wget -y && \
    echo "vm.max_map_count=262144" >> /etc/sysctl.conf && \
    # I try to install elasticsearch manually
    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.1.rpm && \
    rpm --install elasticsearch-6.6.1.rpm && \
    service elasticsearch start && \
    chkconfig --add elasticsearch && \
    sed -i -e "s/#network.host: 192.168.0.1/network.host: 127.0.0.1/g" /etc/elasticsearch/elasticsearch.yml && \
    sed -i -e "s/#http.port: 9200/http.port: 9200/g" /etc/elasticsearch/elasticsearch.yml && \
    sed -i -e "s/# Elasticsearch performs poorly when the system is swapping the memory./network.bind_host: 127.0.0.1\nnetwork.publish_host: localhost/g" /etc/elasticsearch/elasticsearch.yml

RUN service elasticsearch start && \
    service elasticsearch status && \
    service elasticsearch status

构建映像时,映像已正确构建,并且Elasticsearch服务正在运行。 我可以看到日志: elasticsearch (pid 87) is running... 问题是我无法对http:// localhost:9200进行API调用,因为它说: Failed to connect to localhost port 9200: Connection refused

我需要在容器内部而不是从外部使用elasticsearch服务。 我究竟做错了什么?

您没有指出实际如何运行Docker容器。 仅在docker文件中公开端口是不够的。 您还必须使用-p选项。 例如:

docker run -p 9200:9200 <image name here>

有关详细信息,请参见https://docs.docker.com/engine/reference/commandline/run/

您要做的是使用应用程序的内部IP地址。 这就是你得到它的方式

dokku elasticsearch:info <Your elasticsearch container name here>

那你现在可以做

curl http://172.75.0.7:9200

假设您的内部IP为172.75.0.7

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM