【问题标题】:No alive nodes found in your cluster在您的集群中找不到活动节点
【发布时间】:2017-02-03 14:34:54
【问题描述】:

我安装了 elasticsearch with the help of this link

require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;

$client = ClientBuilder::create()->setHosts(["localhost:9200"])->build();  
$response = ''; 
try{
    $params = [
        'index' => 'my_index',
        'type' => 'my_type',
        'id' => 'my_id',
        'body' => ['testField' => 'abc']
    ]; 
    $response = $client->indices()->create($params);        
}catch(Exception $e){
    echo "Exception : ".$e->getMessage();
}
print_r($response);
die('End : Elastic Search');

它返回我在您的集群中找不到活动节点。 当我将端口更改为 80

$client = ClientBuilder::create()->setHosts(["localhost:80"])->build();

它给了我以下错误。

方法不允许。 URL /my_index 不允许请求的方法 PUT。

【问题讨论】:

  • 你能在弹性服务器上发布你的 elasticsearch.yml 文件吗?
  • 你为什么要在 80 和 9200 之间改组弹性端口,默认情况下,只有当你明确将其更改为 80 时,弹性服务器才会监听 9200 端口。我可以看看你的 elasticsearch.yml 文件查看您是否启用了对端口 9200 或其他内容的远程访问
  • @user3775217 我可以在 /etc/elasticsearch 目录中找到 elasticsearch.yml 文件。该文件中的所有内容都已注释。
  • 嗯,这意味着您的弹性服务器正在侦听默认端口 9200
  • 你是如何安装elasticsearch的?您在帖子中分享的关于 elasticsearch 的链接是安装 elasticsearch php 客户端而不是 elasticsearch 服务器。

标签: elasticsearch php-7 elasticsearch-plugin


【解决方案1】:

检查您的网络是否正在监视弹性服务的 ip,如果您使用的是 docker,在组合容器之前,如果您正在监视服务的 ip 并在 .env 文件中添加 ip,请通过 shell 检查您的 Web 应用服务器内部并再次执行 docker compose。 在另一种情况下,检查您的 vps o 开发环境是否正在 ping o 观察弹性服务的 ip

【讨论】:

    【解决方案2】:

    您是否尝试重新启动 elasticsearch 守护程序?喜欢:

    systemctl restart elasticsearch
    

    然后,检查它是否正在运行:

    systemctl status elasticsearch
    

    如果没有,请检查日志文件是否有任何异常。

    【讨论】:

      【解决方案3】:

      如果你使用 docker 中的 Elasticsearch 服务器作为 doc,https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

      但它使用不同的网络(网络:- esnet)和其他服务,它无法与应用程序网络通信。删除网络设置后,它运行良好。

      【讨论】:

        【解决方案4】:

        您在创建索引和创建文档之间混为一谈,首先您需要创建索引(如常规关系数据库中的表),然后立即插入文档

        require 'vendor/autoload.php';
        use Elasticsearch\ClientBuilder;
        
        $indexParams = [
            'index' => 'my_index',
            'body' => [
                'settings' => [
                    'number_of_shards' => 5,
                    'number_of_replicas' => 1
                ]
            ]
        ];
        
        $docParams = [
            'index' => 'my_index',
            'type' => 'my_type',
            'id' => 'my_id',
            'body' => ['testField' => 'abc']
        ];    
        
        $client = ClientBuilder::create()->setHosts(["localhost:9200"])->build();  
        $response = ''; 
        try {
            /* Create the index */
            $response = $client->indices()->create($indexParams);
            print_r($response);
        
            /* put doc in the index */
            $response = $client->index($docParams);
            print_r($response);
        
        } catch(Exception $e) {
            echo "Exception : ".$e->getMessage();
        }
        die('End : Elastic Search');
        

        【讨论】:

        • 即使上面的代码也返回了同样的错误。 例外:在您的集群中找不到活动节点结束:弹性搜索
        • 尝试通过80端口连接
        • 现在我得到了另一个错误。 方法不允许。 URL /my_index 不允许请求的方法 PUT。
        【解决方案5】:

        在方法 CurlHandler::_invokeAsArray 上的 vendor\guzzlehttp\ringphp\src\Client\CurlHandler.php 上设置断点并查看 $response 也可以使用

        $client = ClientBuilder::create()->setHosts([['host' =>self::$CONF['elasticSearchHost'],'port' => '80','scheme'=>'http']])->build();
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-03-23
          • 1970-01-01
          • 2021-03-14
          • 2021-01-04
          • 2020-06-14
          • 1970-01-01
          • 2018-01-17
          • 2015-12-11
          相关资源
          最近更新 更多