Installing a Multicore ApacheSolr Server with Tomcat on CentOS

Submitted by Brandon Cone on 08/08/2013 - 03:38:pm

ApacheSolr is a great way to spruce up your searches in Drupal.  If you are reading this post, it is probably because you already know what Solr is and want to get it configured on your server so I'll spare you the introductions.

Installing Solr on a CentOS server is actually quite easy once you get a little help. This list is designed to help you get there as well as identify some "gotchas" that I experienced.  (I'm also assuming that you have root access to your server.)

  1. Install Tomcat
    1. yum install tomcat6-lib.noarch tomcat6.noarch tomcat6.admin-webapps.noarch tomcat6-webapps.noarch
  2. Start Tomcat - service tomcat6 start
    1. By default, Tomcat runs on port 8080 of your machine.  You can change this in the Tomcat configuration files if you wish.  Either way, you will need to update your firewall to ensure you can access port 8080 to load the admin interface.  Do this by running the setup command and choosing "Firewall Configuration."  Browse your way to the additional ports section and configure port 8080 for tcp.
    2. Open the Tomcat admin screen by going to http://[mydomain]:8080
  3. In order to see the running Tomcat services, you will need to configure a Tomcat user.  Once you have this done, you can click on Tomcat Manager link and enter the username password combination you configured.
    1. open /usr/share/tomcat6/conf/tomcat-users.xml file.
    2. Edit an existing entry or add your own. 
    3. Save and Close.
  4. Download ApacheSolr.  - You can download source and build if you want but it's a lot easier to just download a packaged build.
    1. wget http://apache.mirrors.hoobly.com/lucene/solr/4.4.0/solr-4.4.0.tgz
  5. Extract the tgz file into a useful working directory.  Since I was logged in as root, I did all my work from /root.
    1. tar -xzvf apache-solr-4.0.0.tgz solr
  6. Stop Tomcat
  7. To keep things clean, I copied the solr example I wanted to use into another directory.  As I wanted a multicore setup, I copied the multicore directory.
    1. cp -r solr/example/multicore /opt/solr
  8. Copy Solr's .war file into the Tomcat webapps directory.  This might either be called solr.war or solr-x.x.x.war where x.x.x is the solr version you downloaded.
    1. cp solr/dist/solr-x-x-x.war /usr/share/tomcat6/webapps/solr.war
  9. Make sure Java knows where to find your Solr installation.  Since I was running it through Tomcat, I defined this path as part of the tomcat6.conf file
    1. JAVA_OPTS="-Dsolr.solr.home=/opt/solr"
  10. You're almost there.  If you try to start Tomcat6 and Solr now, you will most likely get errors if you are using a packaged build of Solr like I did.  The quick solution is that you need to copy the jar files from the jetty instance into Tomcat as your version of solr expects log4j and some other classes to be available.
    1. Copy the necessary libraries from solr/lib/ext into your container's lib directory (/usr/share/tomcat6/lib).
  11. Start Tomcat

That should get you up and running, if not, here are some issues I found which might help you.

  • Make sure there is a solr.xml file in your SOLR_HOME directory.
  • Make sure your core instances are configured with the names and directories and that each directory contains a conf directory with at least a solrconfig.xml and a schema.xml file.
  • Make sure that the solr core directories are accessible by the tomcat user - I changed ownership on mine to be tomcat:root.
  • I got an ambiguous error when starting Solr about unable to initialize searcher.  This was not due to a configuration error but rather to the non-existence of a core/conf/data directory and lack of write permissions to that directory.

This should get your solr instance up and running.  If you've restarted Tomcat, you can see the running services from the Manager Application.  Clicking on the link for solr will take you to the solr administration pages.

Happy Searching!