Installing Solr instances under Tomcat

from: http://wiki.apache.org/solr/SolrTomcat

Assuming that Solr and its example are built, this is how to install the Solr example as an instance under Tomcat.

Copy the example/solr directory from the source to the installation directory like /opt/solr/example/solr, herafter $SOLR_HOME. Copy the .war file dist/apache-solr-*.war into $SOLR_HOME as solr.war.

The configuration file $SOLR_HOME/conf/solrconfig.xml in the example sets dataDir for the index to be ./solr/data relative to the current directory – which is true for running the Jetty server provided with the example, but incorrect for Tomcat running as a service. Modify the dataDir to specify the full path to $SOLR_HOME/data:

<dataDir>${solr.data.dir:/opt/solr/example/solr/data}</dataDir>

The dataDir can also be temporarily overridden with the JAVA_OPTS environment variable prior to starting Tomcat:

export JAVA_OPTS="$JAVA_OPTS -Dsolr.data.dir=/opt/solr/example/solr/data"

Create a Tomcat Context fragment to point docBase to the $SOLR_HOME/solr.war file and solr/home to $SOLR_HOME:

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

Symlink or place the file in $CATALINA_HOME/conf/Catalina/localhost/solr-example.xml, where Tomcat will automatically pick it up. Tomcat deletes the file on undeploy (which happens automatically if the configuration is invalid).

Repeat the above steps with different installation directories to run multiple instances of Solr side-by-side.

If Tomcat is not already running, start it with service tomcat6 start or $CATALINA_HOME/bin/startup.sh run. The Solr admin should be available at http://<host>:8080/solr-example/admin.

Leave a Reply