, Johann Schmitz

Recently, we had an presentation at work about Apache solr, a great and fast document-base search engine based on Apace Lucene. Here is a guide how to deploy a solr instance on tomcat on gentoo.

Solr ships with a jetty instance. While this is great for quick and dirty deployments, i dislike this way for a clean and stable production installation. So i will describe the steps to deploy the .war file of solr on a Tomcat.

Installing Tomcat

We will install the lastest stable version in the portage of Tomcat (7.0.27). To do this, run emerge www-servers/tomcat -av. This install the required dependencies.

Installing solr

Download the lastest stable version (3.6.0) from one of the mirrors. The archive contains the required libs, API documentation, and some example docs.

Unpack the solr archive to a temporary location (e.g. /tmp/solr). We will install solr to /opt/solr; this director will hold your index too, so depending on the amount of data, you need a lot of space here.

Copy the example/solr/ directory from the extracted distribution archive to /opt/solr and change the permissions to tomcat:tomcat. This directory contains the default set of configuration files and meta informations like common stopwords files. Now copy the file dist/apache-solr-3.6.0.war to /opt/solr/solr.war (this is the main solr application and needed libraries).

Configuring solr and Tomcat

The last step is the configuration of solr and Tomcat. First, we have to change the location of the index files because the default configuration uses a relative directory. This works for the shipped jetty server, but not for an installed Tomccat server. Open /opt/solr/conf/solrconfig.xml and change the <dataDir />-Node to <dataDir>${solr.data.dir:/opt/solr/data/}</dataDir> (or any other directory which is writable by tomcat and has enough space for your index data).

Now, create /opt/solr/solr-web.xml with the following content

<?xml version="1.0" encoding="utf-8"?>
<Context docBase="/opt/solr/solr.war" debug="0" crossContext="true">
  <Environment name="solr/home" type="java.lang.String" value="/opt/solr" override="true"/>
</Context>

and link it to /etc/tomcat-7/Catalina/localhost/solr-web.xml. Now start tomcat and open http://localhost:8080/solr-web/admin/. You should see the solr interface.

Importing test data

Now you can import the sample docs from example/exampledocs/ as described in Indexing data in the solr tutorial (you have to change the URL variable to http://localhost:8080/solr-web/update to actually post to the solr instance deployed in tomcat).