Deploy Solr on Tomcat
- November 9th, 2009
- Write comment
This article will guide you through the process of deploying Apache Solr 1.3 onto a Tomcat environment. To do this we will be utilising Tomcat’s context fragments. We will not be covering how to index using Solr, I would highly recommend looking at Solrj for this.
My Setup
I feel it is important for you to know what platform I am deploying Solr onto. I am running Windows XP, with Tomcat 6.0.20.
Preparation
Before we start lets make sure you have all the right software. I would recommend if like me you are using a windows based system to install Tomcat using the windows installer available from the Tomcat download site once downloaded and installed do not start the service. secondly download the Solr.war file from the Solr download site and keep it somewhere safe on your server/machine and note the path to the war file. Now we are ready to create the context.
The Context
The context fragment needs to be placed in a specific directory structure, firstly navigate to tomcat\conf directory. Once there create a directory whose name is Catalina which will reference your Tomcat installation within that directory create a further directory with the name of your host, for example in my basic example I will be using my machine as the host so the directory will be called localhost.
Within this directory create an XML file called [whatever you want your index to be called].xml this file is the context fragment. For example my context file is called unimaginatively solr.xml.
Coding the Fragment
Within your new empty context fragment we need to add a short burst of code pointing tomcat at a few key places within Solr. firstly we have to tell Tomcat where to get the Solr.war file we downloaded earlier, remember the path, good.
<Context docBase=”..\conf\apache-solr-1.3.0.war” debug=”0″ crossContext=”true” >
The docbase attribute of the context is relatively to your bin directory i.e. for a standard installation the bin directory can be found within the Tomcat directory. So you can see from the first line of this code, that my war file is within the conf directory and I point to it using a relative path from the bin directory.
<Environment name=”solr/home” type=”java.lang.String” value=”../conf/solr” override=”true” />
The next line and believe it or not the last required line of code within the context, is going to tell Tomcat where to place the Solr home this is the configuration files, and data directory for Solr so in essence where your data will be stored. So as you can see from the the code that again I have placed my Solr home within the conf directory of Tomcat. Again this path is relative to the bin directory.
and that’s it you now should have a working Solr deployment.
Hope this helps.
Starting Tomcat
Now we are ready to start the Tomcat service. When the service starts you should notice two directories appear the first will be within the conf directory, and the second will be within webapps directory