Pages

Monday 22 July 2013

Installation Guide To Set Up Solr 4.3 With Apache Tomcat (Windows & Cygwin)

Installation Guide to Set Up Solr 4 With Apache Tomcat On Windows

This is a short guide on how to set up Apache Solr on Windows 7 running on Apache Tomcat. Be aware that Solr-4.3.0 and Apache-tomcat-7.0.40. Older versions of Solr use different folder structure and therefore this guide will not adequately cover its requirements.

Preparation

First of all we need an Apache Tomcat servlet container. It can be found at the Apache Tomcat website:Apache Website Any version beyond 7.0.0 is considered stable with sufficient support and documentation available. Please Download Tomcat & Solr in preparation to starting this guide. You will also require the Java Runtime Environment to be downloaded and set up. Its location will be referred to as $JAVA.

  • Solr 4.3.0
  • Tomcat 7 or Tomcat 8
  • Cygwin
  • JRE 7

Set-up

  • Firstly, choose the location you wish to install Tomcat and copy the files from your downloads to your chosen directory. This will be referred to as $TOMCAT_HOME. Do the same for your Solr download, copy the files to your chosen location and this will be referred to as which will be referred to as $SOLR.
  • Edit the server.xml file in $TOMCAT_HOME/conf to look like the following code snippet:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8" />
  • Now copy the [$SOLR]/example/solr directory somewhere else and rename it solr_home. This will be your main Solr installation to run your Solr server and will be referred to as $SOLR_HOME.
  • The next thing is setting up the Solr deployment. To do that we need the apache-solr-4.0.0.war (found in $SOLR/example/webapps) file that contains the necessary files and libraries to run Solr to be copied to the $TOMCAT_HOME/webapps directory and renamed solr.war.
  • Create a proper context file by creating a solr.xml file in the $TOMCAT_HOME/conf/Catalina/localhost directory. If the Catalina/localhost/ directory does not exist then you will need to make it yourself. The contents of the file should look like the following code:
<Context docBase="/solr.war"debug="0" crossContext="true">
<Environment name="solr/home" type="java.lang.String" value="$SOLR_HOME" override="true"/>
</Context>
  • Modify solr_home/collection1/conf/solrconfig.xml to set the absolute directory:
<lib dir="$SOLR/contrib/extraction/lib" regex=".*\.jar" />
  • Also set the data directory like:
<dataDir>${solr.data.dir:$SOLR_HOME/data}</dataDir>
  • Now we can start the servlet container. Navigate to the $TOMCAT_HOME/bin and double click: startup.bat. Using command prompt:
cd $TOMCAT_HOME/bin
startup.bat run
  • Copy the jar files from $SOLR\example\lib\ext into the $TOMCAT_HOME/lib folder and also copy the $SOLR/example/solr/example/resources/log4j.properties into the same location.
  • Runtimes may need to be set in the startup.bat file. Add set JAVA_HOME=$JAVA or equivalent location to the second line of the file catalina.bat if it fails to run.
  • Your Solr server is now running and to ensure that Solr is running properly, you can open a browser and navigate to:http://localhost:8080/solr/. The Solr administration screen should appear and there are a variety of options to choose from. 

Next Steps

The next step is to ensure that Tika's extracting request handler is configured correctly so that it can deal with pdf, doc, xls etc files:
http://amac4.blogspot.co.uk/2013/07/setting-up-tika-extracting-request.html

You will also want to set-up de-duplication and potentially Solr's Highlighting functionality:http://amac4.blogspot.co.uk/2013/08/setting-up-highlighting-for-solr-4.htmlhttp://amac4.blogspot.co.uk/2013/08/solr-deduplication.html

Tomcat Options

When running Tomcat you have various options which are availible to you here:

  • stop: This stops Apache Tomcat
  • restart: This restarts Apache Tomcat
  • debug: This start Apache Tomcat in debug mode
  • run: This runs Apache Tomcat in the current window, so you can see the output on the console from which you run Tomcat.

21 comments:

  1. MAN! great job!

    ReplyDelete
  2. This is really helpfull

    ReplyDelete
  3. Thanks a lot for the wonderful post....

    Also, Would you please let me help with an error I am encountering,
    it says :solrcore 'collection1' is not available due to init failure

    ReplyDelete
    Replies
    1. I updated my blog, there were a few minor typos. Check again and you may solve it

      Delete
    2. I got this error, and it was due to the 'value' attribute in .
      Change it from '$SOLR_HOME' to the actual path of SOLR_HOME. For instance, mine was /home/nick/solr_home. Changing it to the this hardcoded directory solved this problem for me.

      Delete
  4. This was really helpful !! Thanks.

    ReplyDelete
  5. I followed the guide but I get a "resource not available" error when trying to see whether Solr is running. This has to be the 4th guide I have tried and I am still getting the same error. Any ideas? :/

    ReplyDelete
    Replies
    1. Check your log files in $TOMCAT_HOME/logs/catalina.out. Mine was telling me that "/solr.war" wasnt a valid path in the tag, docBase attribute. I changed the docBase attribute from '/solr.war' to '$TOMCAT_HOME/webapps/solr.war' and it worked.

      Delete
    2. also, you could just try 'solr.war' without the /

      Delete
  6. I'm getting the following page when running - http://localhost:8080/solr/

    HTTP Status 404 - /solr/

    type Status report

    message /solr/

    description The requested resource is not available.

    Apache Tomcat/8.0.9

    Allan please help.

    ReplyDelete
    Replies
    1. 1. Check your log files first.

      2. I assume you understand that the $TOMCAT_HOME etc are placeholders that you need to replace with the actual locations

      3. Check the guide again, small things can cause a crash -

      If it still aint working, i can possibly send you my copies of the relevant files

      Delete
    2. I got above same error.

      I used Tocat 7 .

      I placed solr_home and solr folder in Tomcat folder.

      I checked Tomcats\logs\catalina .The following error in catalina file.

      1.SEVERE: Parse Fatal Error at line 5 column 31: Element type "Context" must be followed by either attribute specifications, ">" or "/>".
      org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 31; Element type "Context" must be followed by either attribute specifications, ">" or "/>".
      2.SEVERE: Error deploying configuration descriptor C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\Catalina\localhost\solr.xml
      org.xml.sax.SAXParseException; lineNumber: 50; columnNumber: 31; Element type "Context" must be followed by either attribute specifications, ">" or "/>".


      Although I edited something like solr.xml in C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\Catalina\localhost,

      I think my solr.xml is somthing wrong. Pls advice to me. Thanks

      Delete
  7. 1. Check your log files first.

    2. I assume you understand that the $TOMCAT_HOME etc are placeholders that you need to replace with the actual locations

    3. Check the guide again, small things can cause a crash -

    If it still aint working, i can possibly send you my copies of the relevant files

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. There is a missing space between the docBase value 2nd quote and the debug keyword which cause an error in tomcat startup

    ReplyDelete
  10. Used these instuctions at (for windows scroll near the bottom with heading "Tomcat on Windows" :
    http://wiki.apache.org/solr/SolrTomcat
    Just had to change the $CATALINA_HOME/conf/Catalina/localhost/solr.xml from value="C:\solr" to value="C:\web\solr":




    ReplyDelete
  11. Nice post, clear steps. I used tomcat-8.0.15 with solr-4.10.2 on Windows 8.1 Worked perfectly. Thanks.

    ReplyDelete
  12. i got error
    HTTP Status 404 - /solr/

    type Status report

    message /solr/

    description The requested resource is not available.

    Apache Tomcat/7.0.63

    ReplyDelete
  13. Hello everyone
    I am getting this error when I type http://localhost:8080/solr/

    HTTP Status 404 - /solr/

    type Status report

    message /solr/

    description The requested resource is not available.

    Apache Tomcat/7.0.63

    ReplyDelete
  14. I also got error :solrcore 'collection1' is not available due to init failure like kings of my dreams user in my Apache tomcat training in Hyderabad and your reply helps me.Thank you.

    ReplyDelete