How do I configure Solr replication with multiple cores

荒凉一梦 提交于 2019-12-02 19:43:26

What you need to do is copy the solr instance that you have on the slave server and configure the replication handler on the solrconfig.xml. It's best practice to have a different instanceDir directory for each core since usually every core has its own schema.xml and solrconfig.xml. Anyway you can use the same conf just configuring your solr.xml to point to the same instanceDir but a different dataDir, which you configure as dataDir in your solrconfig.xml as well:

<solr persistent="true" sharedLib="lib">
    <cores adminPath="/admin/cores">
        <core name="core0" instanceDir="core">
            <property name="dataDir" value="/data/core0" />
        </core>
        <core name="core1" instanceDir="core">
            <property name="dataDir" value="/data/core1" />
        </core>
    </cores>
</solr>

This should be your situation if you currently have multiple cores but a single solrconfig.xml.

The solrconfig.xml replication section on the slaves need to contain the url of the master, including the core name, which of course is different for each core. But you can use the placeholder ${solr.core.name} like this:

<requestHandler name="/replication" class="solr.ReplicationHandler" >
    <lst name="slave">
        <str name="masterUrl">http://master_host:port/solr/${solr.core.name}/replication</str>
        <str name="pollInterval">00:00:20</str>
    </lst>
</requestHandler>

In fact, some properties like solr.core.name are automatically added to the core scope and you can refer to them in your configuration. As a result, the replication section can be the same for every core if you don't have any core specific settings.

Furthermore, you could use the same config for master and slave with the following configuration and just change the value (true or false) that you assign to the environment variables enable.master and enable.slave based on what you want to do. I mean that you can use the same file, but of course it's going to be on different machines since it wouldn't make a lot of sense to have master and slaves on the same machine.

<requestHandler name="/replication" class="solr.ReplicationHandler" >
    <lst name="master">
        <str name="enable">${enable.master:false}</str>
        <str name="replicateAfter">commit</str>
    </lst>
    <lst name="slave">
        <str name="enable">${enable.slave:false}</str>
        <str name="masterUrl">http://master_host:8983/solr/${solr.core.name}/replication</str>
        <str name="pollInterval">00:00:60</str>
    </lst>
</requestHandler>

Yes, you need to have the exact same copy of the files in each copy of the core you're replicating.

To unload even more your solr instances, i suggest you to have a master used only for indexing and 2 slaves, replicated from master, used to query your documents.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!