Solr on Ubercart.org

During our hackathon @ ubercamp we decided to install solr search on ubercart.org. Here is how we got solr running as a service, with tomcat, drupal, and the Apachesolr module.

Install solr / tomcat

I decided to use tomcat in this case, mainly because I wanted to create an init script to start/stop the solr serivce, and to automatically bring it online when the server is rebooted.

I followed the SolrTomcat Instructions, except I didn't start tomcat. We need to change a couple things first.

mkdir solr-tomcat
cd solr-tomcat/
wget http://mirrors.ibiblio.org/pub/mirrors/apache/tomcat/tomcat-5/v5.5.25/bin/apache-tomcat-5.5.25.zip
NIGHTLY=solr-`/bin/date +%F`
wget http://people.apache.org/builds/lucene/solr/nightly/$NIGHTLY.zip
unzip apache-tomcat-5.5.25.zip
unzip $NIGHTLY.zip
cp apache-solr-nightly/dist/apache-solr-nightly.war apache-tomcat-5.5.25/webapps/solr.war
cp -r apache-solr-nightly/example/solr .
chmod a+x apache-tomcat-5.5.25/bin/*

Configuring Tomcat

If you start tomcat right now, everything will work as long as you launch the service from this directory. This won't play friendly with an init script, so we are going to make a few changes.

First we're going to follow the solrtomcat instructions for Configuring Solr Home with JNDI. cd apache-tomcat-5.5.25/conf/Catalina/localhost/
nano solr.xml
Add the following but replace the docBase and solr/home value with your actual paths: <Context docBase="/var/solr-tomcat/apache-tomcat-5.5.25/webapps/solr.war" debug="0" crossContext="true" >
<Environment name="solr/home" type="java.lang.String" value="/var/solr-tomcat/solr" override="true" /> </Context>

By default all of the solr information will be stored in the directory where the service is launched. We are going to change the solrconfig.xml to save things where we want them: cd ../../../../solr/conf
nano solrconfig.xml

Look for dataDir and change it to the absolute path to the solr directory:

<!-- Used to specify an alternate directory to hold all index data
other than the default ./data under the Solr home.
If replication is in use, this should match the replication configuration. -->
<dataDir>/var/solr-tomcat/solr/</dataDir>

Since we are in the solr conf directory, we are going to replace the schema.xml file with the one packaged with the apachesolr module:

cp /path/to/apachsolr/schema.xml ./

Adding the init script

Next we are going to add an init script to start/stop the server.

cd /etc/init.d
nano solr

copy / paste the following init script, make sure the paths are correct

#! /bin/sh
# Basic support for IRIX style chkconfig
###
# chkconfig: 235 98 55
# description: Manages the services you are controlling with the chkconfig command
###
case "$1" in
start)
echo -n "Starting solr"
#To run it as root:
/var/solr-tomcat/apache-tomcat-5.5.25/bin/startup.sh
echo "."
;;
stop)
echo -n "Stopping solr"
/var/solr-tomcat/apache-tomcat-5.5.25/bin/shutdown.sh

echo "."
;;

*)
echo "Usage: /sbin/service solr {start|stop}"
exit 1
esac

exit 0

Now we are going to make the script executable, and enable it with chkconfig:

chmod 755 solr
chkconfig --add solr

Start it up

/etc/init.d/solr start

You should be able to browse to your url on port 8080 and see a tomcat splash screen. /solr/admin will show you the solr admin interface. If you get the following error there is one more thing to do. Starting solrNeither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
Modify the catalina script: nano /var/solr-tomcat/apache-tomcat-5.5.25/bin/catalina.sh and add the proper location to the JAVA_HOME variable JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun-1.5.0.15

Apachesolr Config

The only thing left to do is point the apachsolr module to the right location. Those settings can be found under admin/settings/apachesolr. Change the port to 8080 and you should be all set.

multiple solr indices using the same solr.war

mike:

good article. works very well and i was able to get the apache solr indexing for my drupal site. i wanted to add indexing to another drupal site on the same machine and was having some problems

i tried the multiple solr webapps as per - http://wiki.apache.org/solr/SolrTomcat#head-024d7e11209030f1dbcac9974e55...

here's what i did

$ cd /opt/solr-tomcat/
$ cp -r apache-solr-nightly/example/solr solr2
$ cd solr2/conf
$ nano solrconfig.xml
/opt/solr-tomcat/solr2/

$ cd /opt/solr-tomcat/
$ cd apache-tomcat-5.5.27/conf/Catalina/localhost/
$ cp solr.xml solr2.xml
$ nano solr2.xml

then i restarted solr /etc/init.d/solr stop, start

i then went to the tomcat manager at
http://localhost:8080/manager/html
and noticed i have 2 applications now in the Applications table
/solr and /solr2

for /solr the Running column is "true" and for /solr2 it is
'false'.

i clicked on start in the Commands column for /solr2
http://localhost:8080/manager/html/start?path=/solr2
and it gave an error message

FAIL - Application at context path /solr2 could not be started

and the tomcat logs showed
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Document base /opt/solr-tomcat/apache-tomcat-5.5.27/webapps/solr2 does not exist or is not a readable directory

any idea how to use the same solr.war and use it for indexing 2 drupal sites on the same machine ?

thx.

yash