Apache Solr Master-Slave Replication

Apache Solr is the open source enterprise search platform from the Apache Lucene™ project. Solr is written in Java and runs as a standalone full-text search server within a servlet container such as Jetty. In the next lines we’ll make a master-slave replication so the slave can process all user queries while the master is being updated. You can find more information about Solr Replication here.

Setting up the master

We will start with making a copy of the example Solr setup which is located in the “example/” folder.

mkdir master; cp -R example/* master/

By default there’s only one core named “collection1”. Let’s give our master core more propriety name. We’ll name it “project-master” and edit the core’s configuration file which is located in master/solr/solr.xml.

pico master/solr/solr.xml

You should update the file so the cores section look like this:

<cores adminPath="/admin/cores" defaultCoreName="project-master" host="${host:}" hostPort="${jetty.port:}" hostContext="${hostContext:}" zkClientTimeout="${zkClientTimeout:15000}">
  <core name="project-master" instanceDir="project-master" />
</cores>

Let’s rename the default “collection1” core to “project-master”.

mv master/solr/collection1/ master/solr/project-master/

We are ready to configure the “project-master” core.

pico master/solr/project-master/conf/solrconfig.xml

You should find the Solr Replication section and make it look like this:

<requestHandler name="/replication" class="solr.ReplicationHandler">
  <lst name="master">
    <str name="replicateAfter">startup</str>
    <str name="replicateAfter">commit</str>
    <str name="confFiles">schema.xml,stopwords.txt,elevate.xml</str>
    <str name="commitReserveDuration">00:00:10</str>
  </lst>
  <str name="maxNumberOfBackups">1</str>
</requestHandler>

The master is now configured.

Setting up the slave

We must repeat almost the same process of setting the master but with slightly changes. Let’s make a copy of the example Solr setup again. This time we’ll use it for our slave server.

mkdir slave; cp -R example/* slave/

We’ll rename the default core like we’ve done it when configuring the master so instead of “collection1” we will name our core “project-slave”.

pico slave/solr/solr.xml

You should update the file so the cores section look like this:

<cores adminPath="/admin/cores" defaultCoreName="project-slave" host="${host:}" hostPort="${jetty.port:}" hostContext="${hostContext:}" zkClientTimeout="${zkClientTimeout:15000}">
  <core name="project-slave" instanceDir="project-slave" />
</cores>

Let’s rename the default “collection1″ core to “project-slave”.

mv slave/solr/collection1/ slave/solr/project-slave/

It’s time to configure the “project-slave” core.

pico slave/solr/project-slave/conf/solrconfig.xml

You should find the Solr Replication section and make it look like this:

<requestHandler name="/replication" class="solr.ReplicationHandler" >
  <lst name="slave">
    <str name="masterUrl">http:⁄⁄localhost:8983/solr/project-master/replication</str>
    <str name="pollInterval">00:00:20</str>
    <str name="compression">internal</str>
    <str name="httpConnTimeout">5000</str>
    <str name="httpReadTimeout">10000</str>
  </lst>
</requestHandler>

The slave is now configured, too.

Starting the replication

Enter the master directory and start the master using the following command:

java -Denable.master=true -jar start.jar

If everything is OK, you should see the following message: INFO:oejs.AbstractConnector:Started SocketConnector@0.0.0.0:8983

We’ll use different port for the slave so enter its directory and run the following command:

java -Djetty.port=8181 -Denable.slave=true -jar start.jar

If everything is OK, you should see the following message: INFO:oejs.AbstractConnector:Started SocketConnector@0.0.0.0:8181

You should be able to check the status of the replicaton using the following URLs:

Master: http://localhost:8983/solr/#/project-master/replication
Slave: http://localhost:8181/solr/#/project-slave/replication