Solr Multicore: Installation, Configuration

If you start Solr with the default configuration, there will be only one instance running. That’s enough if you have only one website which you want to index but if you have several websites, you probably don’t want them to share an index as you then would get search results from both websites.
Luckily Solr already brings the so called multicore feature with it. It allows you to run multiple instances that use different configuration sets and indexes.

This little howto will show you how to install / configure Solr to make use of the multicore feature.

1. Install the Sun Java Runtime Environment
On Debian Linux you will do this by executing apt-get install sun-java6-jre

2. Choose the directory in which you want to install Solr. In this example we will use /opt.
If it doesn’t exist already, create the directory and cd to it.
cd /opt

3. Go to http://www.apache.org/dyn/closer.cgi/lucene/solr/ and choose a mirror. In this example we will use http://ftp-stud.hs-esslingen.de/pub/Mirrors/ftp.apache.org/dist//lucene/solr/. Download the latest Solr version, currently 1.4.1:
wget http://ftp-stud.hs-esslingen.de/pub/Mirrors/ftp.apache.org/dist//lucene/solr/1.4.1/apache-solr-1.4.1.tgz

4. Extract the downloaded archive:
tar xzf apache-solr-1.4.1.tgz

5. Copy the Solr examples directory. In this example we will copy it to /opt/solr/.
cp -R apache-solr-1.4.1/example/ solr

6. cd to /opt/solr/
cd /opt/solr/

7. Remove the following directories (you probably won’t need them):
- example-DIH
- exampledocs
- work

rm -Rf example-DIH exampledocs work

8. Copy /opt/solr/multicore/solr.xml to /opt/solr/solr/solr.xml and remove the multicore directory.
solr.xml describes the name and location of the cores to use.
cp /opt/solr/multicore/solr.xml /opt/solr/solr/ && rm -Rf /opt/solr/multicore/

9. Edit /opt/solr/solr/solr.xml and modify it to match your needs. For example:
<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="true">
<cores adminPath="/admin/cores">
<core name="myfirstwebsite" instanceDir="site_myfirstwebsite" />
<core name="mysecondwebsite" instanceDir="site_mysecondwebsite" />
</cores>
</solr>

10. Create the directories you specified as "instanceDir" in step 9. Copy /opt/solr/solr/conf into them and create data directories.
mkdir -p /opt/solr/solr/site_myfirstwebsite/data && cp -R /opt/solr/solr/conf/ /opt/solr/solr/site_myfirstwebsite/
mkdir -p /opt/solr/solr/site_mysecondwebsite/data && cp -R /opt/solr/solr/conf/ /opt/solr/solr/site_mysecondwebsite/

11. Edit /opt/solr/solr/site_myfirstwebsite/conf/solrconfig.xml and /opt/solr/solr/site_mysecondwebsite/conf/solrconfig.xml. Change the dataDir-tag to match the new data directories you created in step 10:
<dataDir>/opt/solr/solr/site_myfirstwebsite/data</dataDir> respectively <dataDir>/opt/solr/solr/site_mysecondwebsite/data</dataDir>

12. Start Solr. We will use Jetty here because we wouldn’t need Tomcat for anything else but Solr.
java -jar -server -Xmx128M -Dfile.encoding=UTF8 -Djava.headless=True /opt/solr/start.jar

After Solr has been startet you can access the Solr Admin at http://SOLR_HOSTNAME:8983/solr/ (you should find a link pointing to the Solr Admin for every core you have configured before). Solr queries need to go to http://SOLR_HOSTNAME:8983/solr/CORE_NAME/, f.exp. http://192.168.10.41:8983/solr/myfirstwebsite/select/?q=*%3A*&version=2.2&start=0&rows=10&indent=on