php - 当我尝试创建索引时,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
解决方案
您需要更改 SCOUT_ELASTIC_HOST
应该SCOUT_ELASTIC_HOST=http://elasticsearch:9200
不是http://localhost:9200
推荐阅读
- google-cloud-platform - Google Cloud 中全球 IP 地址和区域 IP 地址之间的区别
- python - 错误:json.decoder.JSONDecodeError:预期值:第 1 行第 1 列(字符 0)
- cellular-network - 移动BTS下会不会有死点?
- php - 如何使用 heic 安装 imagick 以替代 php verison?
- nginx - urn:ietf:params:acme:error:unauthorized :: 客户端缺乏足够的授权
- responsive-images - 响应式图像始终显示比预期大一号
- c++ - 添加到 AVL 树的 Int 输入(用于日期)不正确
- javascript - 如何检查两个对象的相等性(仅特定的键值)
- ruby-on-rails - 如何使用 rails 6 中的命令删除 searchkick gem 中的索引以用于生产 ENV?
- python - 无法使用 Python 3.10 在 Windows 上安装 flask_sqlalchemy