首页 > 解决方案 > 当我尝试创建索引时,Docker + elasticsearch 总是返回“在集群中找不到活动节点”

问题描述

我正在尝试为已经存在的 laravel 项目设置 docker。正如你们所知,Laravel Scout 提供了一个简单的、基于驱动程序的解决方案,用于将全文搜索添加到我们的 Eloquent 模型中,我在自己的项目中使用它。我使用 laradock 并安装 elasticsearch 作为 scout 的驱动程序。但是,当我尝试创建索引php artisan elastic:create-index App\\MyIndexConfigurator(甚至是 scout 导入命令)时,它会出现此错误No alive nodes found in your cluster

奇怪的是,如果我得到http://localhost:9200/_cluster/health,它看起来很好:

`{
  cluster_name: "laradock-cluster",
  status: "green",
  timed_out: false,
  number_of_nodes: 1,
  number_of_data_nodes: 1,
  active_primary_shards: 0,
  active_shards: 0,
  relocating_shards: 0,
  initializing_shards: 0,
  unassigned_shards: 0,
  delayed_unassigned_shards: 0,
  number_of_pending_tasks: 0,
  number_of_in_flight_fetch: 0,
  task_max_waiting_in_queue_millis: 0,
  active_shards_percent_as_number: 100
}`

这是我的 scout_elastic 配置:

return [
    'client' => [
        'hosts' => [
            env('SCOUT_ELASTIC_HOST', 'localhost:9200'),
        ],
    ],
    'update_mapping' => env('SCOUT_ELASTIC_UPDATE_MAPPING', true),
    'indexer' => env('SCOUT_ELASTIC_INDEXER', 'single'),
    'document_refresh' => env('SCOUT_ELASTIC_DOCUMENT_REFRESH'),
];

这是我的 docker-compose.yml:

### ElasticSearch ########################################
    elasticsearch:
      build: ./elasticsearch
      volumes:
        - elasticsearch:/usr/share/elasticsearch/data
      environment:
        - cluster.name=laradock-cluster
        - node.name=laradock-node
        - bootstrap.memory_lock=true
        - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        - cluster.initial_master_nodes=laradock-node
      ulimits:
        memlock:
          soft: -1
          hard: -1
      ports:
        - "${ELASTICSEARCH_HOST_HTTP_PORT}:9200"
        - "${ELASTICSEARCH_HOST_TRANSPORT_PORT}:9300"
      depends_on:
        - php-fpm
      networks:
        - frontend

- 后端

编辑:

curl -XGET http://elasticsearch:9200/_cluster/health

{
"cluster_name":"laradock-cluster","status":"green",
"timed_out":false,
"number_of_nodes":1,
"number_of_data_nodes":1,
"active_primary_shards":0,
"active_shards":0,
"relocating_shards":0,
"initializing_shards":0,
"unassigned_shards":0,
"delayed_unassigned_shards":0,
"number_of_pending_tasks":0,
"number_of_in_flight_fetch":0,
"task_max_waiting_in_queue_millis":0,
"active_shards_percent_as_number":100.0
}

.env:

APP_NAME=Laravel
APP_ENV=local
APP_DEBUG=true
APP_URL=http://127.0.0.1

SCOUT_DRIVER=elastic
SCOUT_ELASTIC_HOST=elasticsearch:9200

标签: phplaravelelasticsearchlaradock

解决方案


您需要更改 SCOUT_ELASTIC_HOST

应该SCOUT_ELASTIC_HOST=http://elasticsearch:9200不是http://localhost:9200


推荐阅读