【问题标题】:Embedded elasticsearch is not accessible from outside无法从外部访问嵌入式弹性搜索
【发布时间】:2017-06-27 14:52:01
【问题描述】:

我有带有嵌入式弹性搜索的 Spring Boot 应用程序。我可以以 localhost:9200 的身份访问它,但它没有以真实 IP xx.xxx.x.xx:9200 响应。

端口是开放的,问题是它只监听本地接口。

netstat -vanp tcp | grep 9200
tcp4       0      0  127.0.0.1.9200         *.*                    LISTEN      131072 131072  31425      0
tcp6       0      0  ::1.9200               *.*                    LISTEN      131072 131072  31425      0
tcp6       0      0  fe80::1%lo0.9200       *.*                    LISTEN      131072 131072  31425      0

如何强制它听所有的,就像我为 web 8080 所做的那样

netstat -vanp tcp | grep 8080
tcp46      0      0  *.8080                 *.*                    LISTEN      131072 131072  23002      0

我正在使用:

  • spring-boot-starter-parent 1.4.1.RELEASE
  • spring-boot-starter-data-elasticsearch 1.4.1.RELEASE
  • elasticsearch 2.4.0 版

这是我的 application-dev.yml 的一部分

data:
    elasticsearch:
        cluster-name:
        cluster-nodes:
        properties:
            path:
              logs: target/elasticsearch/log
              data: target/elasticsearch/data
            http:
              enabled: true

谢谢

【问题讨论】:

    标签: elasticsearch spring-boot spring-data-elasticsearch


    【解决方案1】:

    您需要将嵌入式 Elasticsearch 绑定到所有主机 ip(或至少绑定到机器的真实 ip),在我看来您正在绑定到 localhost,因此在配置您的 elasticsearch 时需要此条目:

    Settings.Builder nodeSettings = nodeBuilder().settings();
    ...
    nodeSettings.put("network.host", "0.0.0.0");
    

    这会将您的弹性搜索绑定到您的主机 IP 地址。

    【讨论】:

    • 非常感谢它工作正常。我已将您的方法应用于 application-dev.yml network: host: 0.0.0.0 - 抱歉,这里的 cmets 不支持新行
    • 是的,当然。我在代码中这样做是因为您提到您正在使用它嵌入。顺便说一句,您可能知道,但从 5.x 开始,elasticsearch 不再支持嵌入式模式:elastic.co/blog/elasticsearch-the-server
    • 感谢您的来信。会做好准备的。
    猜你喜欢
    • 1970-01-01
    • 2021-10-10
    • 2014-10-20
    • 2021-08-01
    • 2018-03-15
    • 1970-01-01
    • 2019-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多