在群集中找不到活动的节点|连接被拒绝(Docker,PHP)

时间:2019-05-14 09:57:49

标签: php laravel docker elasticsearch

更新后的信息

使用dd($clientBuilder->transport->getLastConnection()->getLastRequestInfo());

我可以注销以下内容

    "curl" => array:2 [
      "error" => "Failed to connect to localhost port 30003: Connection refused"

但是事情是通过网络浏览器在localhost:30003下可以使用 Elasticsearch

到达此站点时的示例输出:

{

    "name": "xyz",
    "cluster_name": "docker-cluster",
...
}

我确实配置了主机

        $clientBuilder = ClientBuilder::create()
            ->setHosts(['http://localhost:30003/'])
            ->build();

当我dd($clientBuilder)时,主机设置为localhost:30003

          #serializer: SmartSerializer {#385 …}
          #transportSchema: "http"
          #host: "localhost:30003"
          #path: "/"

同样,服务器已启动并正在运行,我可以通过Web浏览器访问它,但仍然收到错误消息:

  

在集群中找不到活动节点

  • Elasticsearch版本: 6.7.0

  • Elasticsearch PHP版本: 6.7.0(最新)

在我的 docker-compose 文件中,我将端口30003映射到9200

      ports:
        - "30003:9200"

1 个答案:

答案 0 :(得分:0)

Elasticsearch 没有导致错误。

cURL出现错误7 ,这意味着它无法建立连接。

我想到的解决方案如下:

        $clientBuilder = ClientBuilder::create()
            ->setHosts([
                [
                    'host' => 'docker.for.mac.localhost',
                    'port' => '30003'
                ]
            ])
            ->build();

我从localhost切换到docker.for.mac.localhost

这很有帮助,因为我使用的是docker容器,并且每个容器都有不同的ip地址