【问题标题】:add multiple endpoints of solr unsing solarium添加 solr unsing 日光浴室的多个端点
【发布时间】:2016-08-01 22:23:31
【问题描述】:

当我添加多个 solr 服务器作为端点并使用单个日光浴室客户端在任何 solr 服务器上触发查询时; 我将复制主/从添加到 solr。现在我尝尝当onecore(主或从)的服务器出现故障时客户端/日光浴室必须使用可用的端点。

我收到此错误:

Message: Solr HTTP error: HTTP request failed, Failed connect to 127.0.0.1:8983; No error

因为我在端口 8983 中停止了 solr,并且 solr 在端口 9000 的从属核心上运行,在这种情况下,如果 localhost 没有运行,我正在寻找连接到 localhost2。 这是我的代码:

$config = array(
         "endpoint" => array("localhost" => array("host"=>"127.0.0.1",
         "port"=>"8983", "path"=>"/solr", "core"=>"master",),
         "localhost2" => array("host"=>"127.0.0.1",
         "port"=>"9000", "path"=>"/solr", "core"=>"slave",)

        ) );

    $client = new Solarium\Client($config);
            $ping = $client->createPing();
            $client->ping($ping,"localhost2");
            $client->getEndpoints();

当密钥 localhost 未运行且密钥 localhost2 在端口 9000 中运行时,我收到此消息 Solr HTTP 错误:HTTP 请求失败,连接到 127.0.0.1:8983 失败;没有错误

以及$client->getEndpoints()的输出;

object(Solarium\Client) {
    [protected] options => array(
        'adapter' => 'Solarium\Core\Client\Adapter\Curl',
        'endpoint' => array(
            'localhost' => array(
                'host' => '*****',
                'port' => '*****',
                'path' => '/solr',
                'core' => 'master'
            ),
            'localhost2' => array(
                'host' => '*****',
                'port' => '*****',
                'path' => '/solr',
                'core' => 'slave'
            )
        )
    )
    [protected] queryTypes => array(
        'select' => 'Solarium\QueryType\Select\Query\Query',
        'update' => 'Solarium\QueryType\Update\Query\Query',
        'ping' => 'Solarium\QueryType\Ping\Query',
        'mlt' => 'Solarium\QueryType\MoreLikeThis\Query',
        'analysis-document' => 'Solarium\QueryType\Analysis\Query\Document',
        'analysis-field' => 'Solarium\QueryType\Analysis\Query\Field',
        'terms' => 'Solarium\QueryType\Terms\Query',
        'suggester' => 'Solarium\QueryType\Suggester\Query',
        'extract' => 'Solarium\QueryType\Extract\Query',
        'get' => 'Solarium\QueryType\RealtimeGet\Query'
    )
    [protected] pluginTypes => array(
        'loadbalancer' => 'Solarium\Plugin\Loadbalancer\Loadbalancer',
        'postbigrequest' => 'Solarium\Plugin\PostBigRequest',
        'customizerequest' => 'Solarium\Plugin\CustomizeRequest\CustomizeRequest',
        'parallelexecution' => 'Solarium\Plugin\ParallelExecution\ParallelExecution',
        'bufferedadd' => 'Solarium\Plugin\BufferedAdd\BufferedAdd',
        'prefetchiterator' => 'Solarium\Plugin\PrefetchIterator',
        'minimumscorefilter' => 'Solarium\Plugin\MinimumScoreFilter\MinimumScoreFilter'
    )
    [protected] eventDispatcher => object(Symfony\Component\EventDispatcher\EventDispatcher) {
        [private] listeners => array()
        [private] sorted => array()
    }
    [protected] pluginInstances => array()
    [protected] endpoints => array(
        'localhost' => object(Solarium\Core\Client\Endpoint) {
            [protected] options => array(
                'host' => '*****',
                'port' => '*****',
                'scheme' => 'http',
                'path' => '/solr',
                'core' => 'master',
                'timeout' => (int) 5,
                'key' => 'localhost'
            )
        },
        'localhost2' => object(Solarium\Core\Client\Endpoint) {
            [protected] options => array(
                'host' => '*****',
                'port' => '*****',
                'scheme' => 'http',
                'path' => '/solr',
                'core' => 'slave',
                'timeout' => (int) 5,
                'key' => 'localhost2'
            )
        }
    )
    [protected] defaultEndpoint => 'localhost'
    [protected] adapter => null
}

【问题讨论】:

    标签: php solr cakephp-2.6 solarium


    【解决方案1】:

    这就是我设法在“端点”之间切换的方式:

    $endpoints=[
        'endpoint' => [
                'foo' => [
                    'host' => '127.0.0.1',
                    'port' => '9000',
                    'path' => 'foo',
                    'core' => 'foo',
                    'timeout' => 15
                ],
                'baz' => [
                    'host' => '127.0.0.1',
                    'port' => '7464',
                    'path' => 'baz',
                    'core' => 'baz',
                    'timeout' => 15
                ],
        ]
    ];
    $solrClient = new Solarium\Client($config);
    $solrClient->setDefaultEndPoint('baz');
    

    而函数 setDefaultEndPoint 将发挥作用

    设置默认端点

    `

    【讨论】:

      【解决方案2】:

      这用于在 PHP 框架中建立多个 solr 连接。

      在您的配置文件夹中添加以下代码

      <?php
          $config['endpoint1'] = array( // endpoint1 is a FIRST connection.
              'endpoint' => array(
                  'localhost' => array(
                    'host' => 'host_name', // localhost or www.host.com
                    'port' => 'port_value', //Default 8983 or 8080 etc,
                    'path' => '/solr/',
                    'core' => 'solr_core_name' // core1 or movie1 or etc,
                  )
              )
          );
          $config['endpoint2'] = array( // endpoint2 is a secound connection.
              'endpoint' => array(
                'localhost' => array(
                    'host' => 'host_name', // localhost or www.host.com
                    'port' => 'port_value', //Default 8983 or 8080 etc,
                    'path' => '/solr/',
                    'core' => 'solr_core_name' // core1 or movie1 or etc,
                )
              )
          );
      ?>
      

      并在__construct()方法中添加连接链接

      public function __construct() {
         parent::__construct();
         $this->config->load('solarium');
         $this->endpoint1 = new Solarium\Client($this->config->item('endpoint1')); 
         $this->endpoint2 = new Solarium\Client($this->config->item('endpoint2')); 
      }
      

      如果对设置 solr 及其连接有任何疑问,请参阅 to this Github repository

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-03-03
        • 2013-07-08
        • 1970-01-01
        • 2013-07-04
        • 2016-03-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多