Solr主从集群配置简要说明

  关于solr的集群主要分为主从和SolrCloud两种。主从,比较适合以读为主的场景。SolrCloud适合数据量大,时不时会有更新的情形。那么solr的主从配置很简单。在solrconfig.xml中找到 <requestHandler name="/replication" class="solr.ReplicationHandler" > 。这里的replication主要解决主从复制的。它主要实现:在主进行数据写操作,在slave节点进行读操作。当并发量大些,可以通过扩展slave节点数来应对,多个slave做一个反向代理和负载均衡(在本文中,就不做说明了,如有需要,可以使用nginx或者apache等负载软件),供查询使用。好了,先看看主节点配置:

  <requestHandler name="/replication" class="solr.ReplicationHandler" > 
    <!--
       To enable simple master/slave replication, uncomment one of the 
       sections below, depending on whether this solr instance should be
       the "master" or a "slave".  If this instance is a "slave" you will 
       also need to fill in the masterUrl to point to a real machine.
    -->

       <lst name="master">
         <str name="replicateAfter">commit</str>
         <str name="replicateAfter">startup</str>
         <str name="confFiles">schema.xml,stopwords.txt,spellings.txt,synonyms.txt</str>
       </lst>

    <!--
       <lst name="slave">
         <str name="masterUrl">http://your-master-hostname:8983/solr</str>
         <str name="pollInterval">00:00:60</str>
       </lst>
    -->

  

master 标志该core 为主节点。复制的行为发生在commit、startup之后。cofFiles表示,向从节点复制的配置文件(记住,主从的solrconfig.xml配置不一样,不要把solrconfig.xml也复制到从节点了)。

  再看看slave节点的配置,slave配置很简单,把上面的配置文件中master那段注释掉。把slave那段放开即可。将masterUrl换成master的url,格式:http://your-master-host:port/solr/your_core_name。具体配置如下:
<requestHandler name="/replication" class="solr.ReplicationHandler" > 
    <!--
       To enable simple master/slave replication, uncomment one of the 
       sections below, depending on whether this solr instance should be
       the "master" or a "slave".  If this instance is a "slave" you will 
       also need to fill in the masterUrl to point to a real machine.
    -->
    <!--
       <lst name="master">
         <str name="replicateAfter">commit</str>
         <str name="replicateAfter">startup</str>
         <str name="confFiles">schema.xml,stopwords.txt</str>
       </lst>
    -->
   
       <lst name="slave">
         <str name="masterUrl">http://192.9.104.116:8090/solr/POI</str>
         <str name="pollInterval">00:00:20</str>
       </lst>
  
  </requestHandler>

  

pollInterval 表示多久向master同步一次数据,数据格式{时}:{分}:{秒}。这个要根据你的业务场景。如果更新比较频繁,就把这个值调小点,反之,就调大些。在同步数据时,根据网络和机器配置等不同,slave之间的数据会存在不同步的情况。如果,你对此有要求,需要注意了。总之,任何一种集群方案都不是万能的。solr的主从模式目前存在诸多问题,比如:主节点有单点故障等等,希望后续的版本会有些改进。

 

posted @ 2015-03-20 12:54  李克华  阅读(7801)  评论(0编辑  收藏  举报