solr服务器主从的配置

 solr的主从同步是按core进行配置的,每个core的solrconfig.xml都需要进行主从的配置。

    主节点的core下面的solrconfig.xml的配置:

[html] view plaincopy在CODE上查看代码片派生到我的代码片

    <requestHandler name="/replication" class="solr.ReplicationHandler" >  
          <lst name="master">  
                  <str name="replicateAfter">commit</str>  
                  <str name="replicateAfter">startup</str>  
      
                  <str name="confFiles">schema.xml</str>  
          </lst>  
      </requestHandler>  

    这个配置的意思是,一旦服务器重启,或者有数据commit的时候,就会进行同步。

    从节点的core下面的solrconfig.xml的配置:

[html] view plaincopy在CODE上查看代码片派生到我的代码片

    <requestHandler name="/replication" class="solr.ReplicationHandler" >  
        <lst name="slave">  
            <str name="masterUrl">http://10.28.175.246:8080/solr/waiter</str>  
            <str name="pollInterval">00:00:20</str>  
         </lst>  
     </requestHandler>  

    配置的意思是说,轮训拉取主节点更新日志的时间是20秒,拉取的地址是http://10.28.175.246:8080/solr,同步的core是waiter。

    重启两台solr。现在进行主从同步的验证。

    在主节点上通过页面进行添加数据:

    
    问题出现了,通过页面上添加的数据,无法同步到从节点!在页面上添加了多条数据,都未同步到从节点。只有当主节点重启的时候,从节点才有数据过来。

    查各种配置问题,查网上各种资料,不得其解!

    于是,我改用代码的方式在主节点提交数据,测试了增加数据和删除数据,并且在这些代码之后,调用了commit()方法。然后发现主从同步很正常!

    初步判断用solr4.6管理页面添加的数据,solr服务器本身没有调用commit()方法。

ps个人项目配置文件

主服务器:

<?xml version="1.0" encoding="UTF-8" ?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<!--
 This is a stripped down config file used for a simple example...  
 It is *not* a good example to work from.
-->
<config>
  <luceneMatchVersion>4.10.2</luceneMatchVersion>
  <!--  The DirectoryFactory to use for indexes.
        solr.StandardDirectoryFactory, the default, is filesystem based.
        solr.RAMDirectoryFactory is memory based, not persistent, and doesn't work with replication. -->
  <directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.StandardDirectoryFactory}"/>

  <dataDir>${solr.core0.data.dir:}</dataDir>

  <!-- To enable dynamic schema REST APIs, use the following for <schemaFactory>:
 
       <schemaFactory class="ManagedIndexSchemaFactory">
         <bool name="mutable">true</bool>
         <str name="managedSchemaResourceName">managed-schema</str>
       </schemaFactory>
       
       When ManagedIndexSchemaFactory is specified, Solr will load the schema from
       he resource named in 'managedSchemaResourceName', rather than from schema.xml.
       Note that the managed schema resource CANNOT be named schema.xml.  If the managed
       schema does not exist, Solr will create it after reading schema.xml, then rename
       'schema.xml' to 'schema.xml.bak'.
       
       Do NOT hand edit the managed schema - external modifications will be ignored and
       overwritten as a result of schema modification REST API calls.

       When ManagedIndexSchemaFactory is specified with mutable = true, schema
       modification REST API calls will be allowed; otherwise, error responses will be
       sent back for these requests.
  -->
  <schemaFactory class="ClassicIndexSchemaFactory"/>

  <updateHandler class="solr.DirectUpdateHandler2">
    <updateLog>
      <str name="dir">${solr.core0.data.dir:}</str>
    </updateLog>
  </updateHandler>
  <!-- realtime get handler, guaranteed to return the latest stored fields
    of any document, without the need to commit or open a new searcher. The current
    implementation relies on the updateLog feature being enabled. -->
  <requestHandler name="/get" class="solr.RealTimeGetHandler">
    <lst name="defaults">
      <str name="omitHeader">true</str>
    </lst>
  </requestHandler>  
 
 <!-- <requestHandler name="/replication" class="solr.ReplicationHandler" startup="lazy" />  -->
      <requestHandler name="/replication" class="solr.ReplicationHandler" >  
          <lst name="master">  
                  <str name="replicateAfter">commit</str>  
                  <str name="replicateAfter">startup</str>  
                  <str name="confFiles">schema.xml</str>  
          </lst>  
      </requestHandler>  


  <requestDispatcher handleSelect="true" >
    <requestParsers enableRemoteStreaming="false" multipartUploadLimitInKB="2048" formdataUploadLimitInKB="2048" />
  </requestDispatcher>
 
  <requestHandler name="standard" class="solr.StandardRequestHandler" default="true" />
  <requestHandler name="/analysis/field" startup="lazy" class="solr.FieldAnalysisRequestHandler" />

  <requestHandler name="/update" class="solr.UpdateRequestHandler"/>
 
  <requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers" />
     
  <requestHandler name="/admin/ping" class="solr.PingRequestHandler">
    <lst name="invariants">
      <str name="q">solrpingquery</str>
    </lst>
    <lst name="defaults">
      <str name="echoParams">all</str>
    </lst>
  </requestHandler>
   
  <!-- config for the admin interface -->
  <admin>
    <defaultQuery>solr</defaultQuery>
  </admin>
</config>

从服务器

<?xml version="1.0" encoding="UTF-8" ?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<!--
 This is a stripped down config file used for a simple example...  
 It is *not* a good example to work from.
-->
<config>
  <luceneMatchVersion>4.10.2</luceneMatchVersion>
  <!--  The DirectoryFactory to use for indexes.
        solr.StandardDirectoryFactory, the default, is filesystem based.
        solr.RAMDirectoryFactory is memory based, not persistent, and doesn't work with replication. -->
  <directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.StandardDirectoryFactory}"/>

  <dataDir>${solr.core0.data.dir:}</dataDir>

  <!-- To enable dynamic schema REST APIs, use the following for <schemaFactory>:
 
       <schemaFactory class="ManagedIndexSchemaFactory">
         <bool name="mutable">true</bool>
         <str name="managedSchemaResourceName">managed-schema</str>
       </schemaFactory>
       
       When ManagedIndexSchemaFactory is specified, Solr will load the schema from
       he resource named in 'managedSchemaResourceName', rather than from schema.xml.
       Note that the managed schema resource CANNOT be named schema.xml.  If the managed
       schema does not exist, Solr will create it after reading schema.xml, then rename
       'schema.xml' to 'schema.xml.bak'.
       
       Do NOT hand edit the managed schema - external modifications will be ignored and
       overwritten as a result of schema modification REST API calls.

       When ManagedIndexSchemaFactory is specified with mutable = true, schema
       modification REST API calls will be allowed; otherwise, error responses will be
       sent back for these requests.
  -->
  <schemaFactory class="ClassicIndexSchemaFactory"/>

  <updateHandler class="solr.DirectUpdateHandler2">
    <updateLog>
      <str name="dir">${solr.core0.data.dir:}</str>
    </updateLog>
  </updateHandler>
  <!-- realtime get handler, guaranteed to return the latest stored fields
    of any document, without the need to commit or open a new searcher. The current
    implementation relies on the updateLog feature being enabled. -->
  <requestHandler name="/get" class="solr.RealTimeGetHandler">
    <lst name="defaults">
      <str name="omitHeader">true</str>
    </lst>
  </requestHandler>  
 
   <requestHandler name="/replication" class="solr.ReplicationHandler" >  
    <lst name="slave">  
        <str name="masterUrl">http://192.168.200.68:8807/solr/core_item</str>  
        <str name="pollInterval">00:00:10</str>  
     </lst>  
 </requestHandler>


  <requestDispatcher handleSelect="true" >
    <requestParsers enableRemoteStreaming="false" multipartUploadLimitInKB="2048" formdataUploadLimitInKB="2048" />
  </requestDispatcher>
 
  <requestHandler name="standard" class="solr.StandardRequestHandler" default="true" />
  <requestHandler name="/analysis/field" startup="lazy" class="solr.FieldAnalysisRequestHandler" />

  <requestHandler name="/update" class="solr.UpdateRequestHandler"/>
 
  <requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers" />
     
  <requestHandler name="/admin/ping" class="solr.PingRequestHandler">
    <lst name="invariants">
      <str name="q">solrpingquery</str>
    </lst>
    <lst name="defaults">
      <str name="echoParams">all</str>
    </lst>
  </requestHandler>
   
  <!-- config for the admin interface -->
  <admin>
    <defaultQuery>solr</defaultQuery>
  </admin>

</config>



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值