1.主机SolrConfig.xml
<requestHandler name="/replication" class="solr.ReplicationHandler" >
<lst name="master">
<!--Replicate on 'startup' and 'commit'. 'optimize' is also a valid value for replicateAfter. -->
<str name="replicateAfter">startup</str>
<str name="replicateAfter">commit</str> <!--Create a backup after 'optimize'. Other values can be 'commit', 'startup'. It is possible to have multiple entries of this config string. Note that this is just for backup, replication does not require this. -->
<!-- <str name="backupAfter">optimize</str> --> <!--If configuration files need to be replicated give the names here, separated by comma -->
<str name="confFiles">schema.xml,stopwords.txt,elevate.xml</str>
<!--The default value of reservation is 10 secs.See the documentation below . Normally , you should not need to specify this -->
<str name="commitReserveDuration">00:00:10</str>
</lst>
</requestHandler>
1)replicateAfter可取startup、commit、optimize,表示触发复制的时机。使用中,这三个值都可以配上。
2)backupAfter表示备份时机,如果需要备份,solr会在配置的时机自动生成备份。
3)confFiles表示在复制时需要复制到slave的文件列表。
4)commitReserveDuration默认是10秒,这个值通常你通常不需要修改,除非你的网络慢到传输5M数据需要10秒以上的时间。
2.从机SolrConfig.xml
<requestHandler name="/replication" class="solr.ReplicationHandler" >
<lst name="slave"> <!--fully qualified url for the replication handler of master . It is possible to pass on this as a request param for the fetchindex command-->
<str name="masterUrl">http://master_host:port/solr/corename/replication</str> <!--Interval in which the slave should poll master .Format is HH:mm:ss . If this is absent slave does not poll automatically.
But a fetchindex can be triggered from the admin or the http API -->
<str name="pollInterval">00:00:20</str>
<!-- THE FOLLOWING PARAMETERS ARE USUALLY NOT REQUIRED-->
<!--to use compression while transferring the index files. The possible values are internal|external
if the value is 'external' make sure that your master Solr has the settings to honour the accept-encoding header.
see here for details http://wiki.apache.org/solr/SolrHttpCompression
If it is 'internal' everything will be taken care of automatically.
USE THIS ONLY IF YOUR BANDWIDTH IS LOW . THIS CAN ACTUALLY SLOWDOWN REPLICATION IN A LAN-->
<str name="compression">internal</str>
<!--The following values are used when the slave connects to the master to download the index files.
Default values implicitly set as 5000ms and 10000ms respectively. The user DOES NOT need to specify
these unless the bandwidth is extremely low or if there is an extremely high latency-->
<str name="httpConnTimeout">5000</str>
<str name="httpReadTimeout">10000</str> <!-- If HTTP Basic authentication is enabled on the master, then the slave can be configured with the following -->
<str name="httpBasicAuthUser">username</str>
<str name="httpBasicAuthPassword">password</str>
</lst>
</requestHandler>
说明:上面的参数也不需要太多解释,其中pollInterval参数表明slave从master复制数据的频率。
如果对实时性要求不高,通常5-10分钟即可,也避免slave的indexsearcher频繁的切换,同时,master的commit频率也可相对保持一致。
HTTP API
solr的ReplicationHandler提供了一系列http命令(参数command),支持的可选值如下:
1)indexversion:slave从master获取最新的索引点信息。
2)filecontent:slave从master下载指定文件的内容。
3)filelist:slave从master获取指定indexversion的索引文件列表(及需要复制的配置文件)。
4)backup:备份索引。如果担心索引有损坏的可能性,可以定期备份索引。
5)fetchindex:手动复制数据,和slave自动复制相当。
6)disablepoll:停止slave的复制。
7)enablepoll:开启slave的复制。
8)abortfetch:终止slave上正在进行的下载文件过程。
9)commits:show当前仍旧保留的IndexCommit信息。
10)details:show slave当前的复制细节信息。
11)enablereplication:启动master对所有slave的复制功能
12)disablereplication:关闭master对所有slave的复制功能