![](/img/trans.png)
[英]Elasticsearch PHP client throwing exception "No alive nodes found in your cluster"
[英]Docker + elasticsearch always return "no alive nodes found in your cluster" when I attempt to create-index
我正在嘗試為已經存在的 laravel 項目設置 docker。 正如你們所知,Laravel Scout 提供了一個簡單的、基於驅動程序的解決方案,用於向我們的 Eloquent 模型添加全文搜索,我在我自己的項目中使用它。 我使用 laradock 並安裝 elasticsearch 作為偵察的驅動程序。 但是,當我嘗試創建索引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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.