【问题标题】:No alive nodes found in your cluster, Laravel, docker在您的集群、Laravel、docker 中找不到活动节点
【发布时间】:2021-03-23 22:04:18
【问题描述】:

我正在使用 laravel 试验 ElasticSearch。到目前为止,这是我的配置:-

config/elasticquent.php

return array(

 'config' => [
    'hosts'     => ['localhost:9200'],
    'retries'   => 1,
 ],

 'default_index' => 'contents',
);

app/Content.php

class Content extends Model
{
 use ElasticquentTrait;

 protected $fillable = ['title', 'text', 'image'];

 protected $mappingProperties = array(
    'title' => [
        'type' => 'string',
        "analyzer" => "standard",
    ],
    'text' => [
        'type' => 'text',
        "analyzer" => "standard",
    ],
    'image' => [
        'type' => 'string',
        "analyzer" => "standard",
    ],
 );
}

routes/web.php

Route::get('/', function () {
 App\Content::createIndex($shards = null, $replicas = null);
 App\Content::putMapping($ignoreConflicts = true);
 App\Content::addAllToIndex();

 return view('contents.index', [
    'contents' => App\Content::all(),
 ]);
});

Route::get('/search', function() {
 return App\Content::searchByQuery(['match' => ['title' => 'Adipisci']]);
});

composer.json

"require": {
 "elasticquent/elasticquent": "dev-master",
}

// database/migrations/2020_12_12_105155_create_contents_table.php
public function up()
{
 Schema::create('contents', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('title');
    $table->text('text');
    $table->string('image');
    $table->timestamps();
 });
}

我的应用在 docker 容器上运行:http://localhost:3024 我的 elasticsearch 也在 docker 容器上运行:

docker run --rm -d -e "discovery.type=single-node" -e "bootstrap.memory_lock=true" -p 9200:9200 elasticsearch:6.8.1

我可以使用 cURL(以及在浏览器中)访问它:-

curl -X GET 'http://localhost:9200'
{
 "name" : "irt6ohl",
 "cluster_name" : "docker-cluster",
 "cluster_uuid" : "jtqcAMyJTRunrxobr6zE_g",
 "version" : {
  "number" : "6.8.1",
  "build_flavor" : "default",
  "build_type" : "docker",
  "build_hash" : "1fad4e1",
  "build_date" : "2019-06-18T13:16:52.517138Z",
  "build_snapshot" : false,
  "lucene_version" : "7.7.0",
  "minimum_wire_compatibility_version" : "5.6.0",
  "minimum_index_compatibility_version" : "5.0.0"
 },
 "tagline" : "You Know, for Search"
}

我的数据库已启动、迁移和播种正常。 routes/web.php 中的这三行似乎破坏了代码:-

App\Content::createIndex($shards = null, $replicas = null);
App\Content::putMapping($ignoreConflicts = true);
App\Content::addAllToIndex();

这些设置ElasticSearch 设置的基础?

我已经用谷歌搜索了它,其他人也遇到了类似的问题,但我无法找到明确的解决方案。你能照亮它吗?

【问题讨论】:

    标签: laravel elasticsearch


    【解决方案1】:

    问题是每个 docker 几乎就像一个孤立的环境。

    因此,您的应用程序(在 http://localhost:3024 上运行)正在尝试连接到同一容器上的 localhost:9200。因此它会导致您遇到错误。

    要解决此问题,您需要通过网络连接两个容器。

    阅读:Docker Network Connect

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-14
      • 1970-01-01
      • 1970-01-01
      • 2021-03-14
      • 2021-01-04
      • 1970-01-01
      相关资源
      最近更新 更多