Sunday, August 31, 2014

Running Solr on Apache Tomcat


Check the video for configuration

First of all we need an Apache Tomcat servlet container. It can be found at the Apache Tomcat
website – http://tomcat.apache.org. I concentrated on the Tomcat Version 7.x because it was mature and stable.

To run Solr on Apache Tomcat we need to follow these simple steps:

Firstly, you need to install Apache Tomcat. The Tomcat installation is beyond the
scope of this tutorial so we will assume that you have already installed this servlet
container in the directory specified by the $TOMCAT_HOME system variable.

The second step is preparing the Apache Tomcat configuration files. To do that we
need to add the following inscription to the connector definition in the server.xml
configuration file:

URIEncoding="UTF-8"

The portion of the modified server.xml file should look like the following
code snippet:

<Connector port="8080" protocol="HTTP/1.1"
        connectionTimeout="20000"
        redirectPort="8443"
        URIEncoding="UTF-8" />

The third step is to create a proper context file. To do that, create a solr.xml file
in the $TOMCAT_HOME/conf/Catalina/localhost directory. The contents of
the file should look like the following code:

<Context path="/solr" docBase="/usr/share/tomcat/webapps/solr.war"
debug="0" crossContext="true">
<Environment name="solr/home" type="java.lang.String" value="/
usr/share/solr/" override="true"/>
</Context>

The next thing is the Solr deployment. To do that we need the apache-solr-
4.x.war file that contains the necessary files and libraries to run Solr that
is to be copied to the Tomcat webapps directory and renamed solr.war.

The one last thing we need to do is add the Solr configuration files. The files that you
need to copy are files such as schema.xml, solrconfig.xml, and so on. Those
files should be placed in the directory specified by the solr/home variable (in our
case /usr/share/solr/). Please don't forget that you need to ensure the proper
directory structure. If you are not familiar with the Solr directory structure please take
a look at the example deployment that is provided with the standard Solr package.

Please remember to preserve the directory structure you'll see in the example
deployment, so for example, the /usr/share/solr directory should contain
the solr.xml (and in addition zoo.cfg in case you want to use SolrCloud)
file with the contents like so:

<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="true">
      <cores adminPath="/admin/cores" defaultCoreName="collection1">
      <core name="collection1" instanceDir="collection1" />
      </cores>
</solr>

All the other configuration files should go to the /usr/share/solr/collection1/
conf directory (place the schema.xml and solrconfig.xml files there along with
any additional configuration files your deployment needs). Your cores may have other
names than the default collection1, so please be aware of that.

Now we can start the servlet container, by running the following command:

bin/startup.bat

In the log file you should see a message like this:

Info: Server startup in 3097 ms

To ensure that Solr is running properly, you can run a browser and point it to an
address where Solr should be visible, like the following:

http://localhost:8080/solr/admin

If you see the page with links to administration pages of each of the cores defined, that
means that your Solr is up and running.

Please feel free to review and comment, many more tutorials to roll-out.