【发布时间】:2016-12-04 23:37:17
【问题描述】:
这是我的docker-compose.yml
nginx:
build: ./nginx/
ports:
- 80:80
links:
- php
volumes_from:
- app
php:
image: php:7.0-fpm
expose:
- 9000
volumes_from:
- app
links:
- elastic
app:
image: php:7.0-fpm
volumes:
- .:/var/www/html
command: "true"
elastic:
image: elasticsearch:2.3
volumes:
- ./elasticsearch/data:/usr/share/elasticsearch/data
- ./elasticsearch/logs:/usr/share/elasticsearch/logs
expose:
- "9200"
ports:
- "9200:9200"
当我尝试通过转到 localhost:9200 来访问 Elasticsearch 时,它可以工作。
但是当我尝试使用 PHP 创建索引时,出现以下错误:
致命错误:未捕获 Elasticsearch\Common\Exceptions\NoNodesAvailableException:没有活着 在您的集群中找到的节点
这是客户端代码:
<?php
namespace App\Elasticsearch;
use Elasticsearch\ClientBuilder;
class Client
{
public static function getClient()
{
return ClientBuilder::create()
->build();
}
}
实例化 Elasticsearch 对象的代码:
<?php
require 'vendor/autoload.php';
use App\Elasticsearch\Client;
use App\Elasticsearch\Indices\UserIndex;
$es = Client::getClient();
如果我var_dump($es),它会转储 Elasticsearch 客户端对象。
但是当我尝试创建索引时,它会引发错误。
<?php
namespace App\Elasticsearch\Indices;
use App\Elasticsearch\Indices\AbstractIndex;
use Elasticsearch\Client;
class UserIndex extends AbstractIndex
{
public function __construct(Client $client)
{
$this->client = $client;
}
}
// Create User Index
$userIndex = new UserIndex($es);
var_dump($userIndex->createIndex('users'));
更新
这个页面。我试过了
$es = Client::getClient();
try {
// Create User Index
$userIndex = new UserIndex($es);
var_dump($userIndex->createIndex('users'));
} catch (Exception $e) {
var_dump($es->transport->getLastConnection()->getLastRequestInfo());
}
现在它显示了 Curl 错误,即
["curl"] array(2) { ["error"] "连接本地端口失败 9200: 连接被拒绝" ["errno"] 7
【问题讨论】:
-
看起来确实是端口问题(有点像github.com/elastic/elasticsearch-php/issues/…)
-
如何从 php 访问弹性体?
-
@opHASnoNAME 我更新了有问题的那部分
标签: php elasticsearch docker docker-compose