Apache Solr is the search technology that powers many Drupal sites. It integrates easily with Drupal’s search_api contrib module, through the search_api_solr module. It’s easy enough to set up a single site installation of solr on your own, but if you’re serious about building Drupal sites with solr you will be building more than one site. Solr includes a ”multi-core” mode, which lets you serve multiple search cores to separate sites from a single installation. Each core looks, feels, and acts like a totally separate Solr install, so you can develop as many solr sites as you like. Each core has its own configuration, data directory… the works. One core can support extensive custom geo data, and another can be completely location blind. The best part: with Solr multicore, adding a new search core to your existing stack is a trivial 5 minute installation.
But getting a working, sane, and easy to manage solr multicore installation is not quite as trivial as a single site. I get asked for instructions on this all the time, so here they are for posterity. These instructions assume you’re running on a supported version of Ubuntu Linux, but very few steps are distribution-specific. I’ve noted them inline, so you can work out just what you need to do for your unique environment.
1) Understand what you’re doing
I know you aren’t going to read this whole post before getting started, so instead step 1 is to understand the beast.
Drupal’s search_api module allows you to plug in different search engines to act as the back end. We’re going to use the search_api_solr module, so that Drupal passes search indexing and queries to Apache Solr for processing. Installing and configuring this on the Drupal side is beyond the scope of this post, but it’s not radically different from any other contrib module. The radically different part is in setting up Solr, and making sure it knows how to understand the information coming from Drupal.
Apache Solr is a search engine built in Java. Basically you run a java program, feed it a bunch of data, and it stores it in a searchable index. Then you send it search queries, and it gives you a sorted list of results. In order to do this, it needs to understand the structure of the data in the search index, and a handful of similar details. We’re lucky in that Drupal’s search_api_solr comes with exactly the configuration files we need to make Solr understand the indexing and search request data that comes from Drupal. We’ll be able to just copy the configuration files right out of the search_api_solr.
In order to run solr in a secure environment, and in order to feed it information that’s coming in over HTTP, you need a Java Servlet engine. This is basically a web server that is specifically built to pass requests on to Java applications like Solr. You can think of it as a wrapper for Solr. There are a few competing open source servlet engines, but we’re going to use Tomcat in this tutorial. Tomcat is popular, powerful, and easy to install on most modern Linux distributions.
2) Install Apache Tomcat
On Ubuntu and Debian systems, this should be as easy as
sudo apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-user
By default Tomcat’s user database is a simple xml file. We’re going to edit it so that we have an administrative user that can tweak behaviors from Tomcat’s web interface.
<role rolename="admin"/> <role rolename="manager"/> <user username="tomcat" password="mypasswordhere" roles="admin,manager"/> </tomcat-users>
sudo service tomcat6 restart
Now Tomcat is up and running, and you can administer it. By default the administrative interface runs on port 8080. This is actually quite handy to keep around, so I recommend blocking external access to 8080 at the firewall level, and accessing it locally when you need to make configuration changes or tests. Test it out now at http://localhost:8080/ . By default you should see a page that shows links to the administration sections, and some other generic information about your Tomcat instance.
2) Install Apache Solr
Now we’re going to download the Solr Java application, and copy the compiled version of it into tomcat’s jailed “webapps” directory, where it’s safe to run. We’re also going to create a convenience simlink there so we can keep the version information in the filename, and we don’t have to update any config files when we want to update Solr versions. Finally, we’re going to simlink solr’s configuration directory to /etc/solr , so you don’t have to memorize the location.
cd /tmp wget http://apache.rediris.es/lucene/solr/3.6.2/apache-solr-1.4.1.zip unzip apache-solr-3.6.3.zip
Now we create a directory for Solr to keep its compiled Java applications in, right in tomcat’s homedir because that will be easy to find later. We copy the compiled .war file for solr into that new directory, and simlink it to an easier to remember name that we can use in configuration files.
sudo mkdir /usr/share/tomcat6/webapps sudo cp /tmp/apache-solr-3.6.3/dist/apache-solr-3.6.3.war /usr/share/tomcat6/webapps sudo ln -s /usr/share/tomcat6/webapps/apache-solr-3.6.3.war /usr/share/tomcat6/webapps/solr.war
sudo cp -a /tmp/apache-solr-3.6.3/example/multicore /usr/share/tomcat6/solr sudo chown -R tomcat6 /usr/share/tomcat6/solr sudo ln -s /usr/share/tomcat6/solr /etc/solr
<Context docBase="/usr/share/tomcat6/webapps/solr.war" debug="0" privileged="true" allowLinking="true" crossContext="true"> <Environment name="solr/home" type="java.lang.String" value="/usr/share/tomcat6/solr" override="true" /> </Context>
3) Configure Solr Multicore for Convenience
<cores adminPath="/admin/cores"> <core name="core0" instanceDir="core0" /> <core name="core1" instanceDir="core1" /> </cores>
sudo mkdir /etc/solr/cores sudo mv /etc/solr/core[0-1] /etc/solr/cores
<cores adminPath="/admin/cores"> <core name="core0" instanceDir="cores/core0" /> <core name="core1" instanceDir="cores/core1" /> </cores>
4) Add a new core for a Drupal site
sudo cp -a /etc/solr/cores/core0 /etc/solr/cores/myfirstcore sudo cp /path/to/drupal_site/sites/all/modules/search_api_solr/solr-conf/* /etc/solr/cores/myfirstcore/conf
<cores adminPath="/admin/cores"> <core name="core0" instanceDir="cores/core0" /> <core name="core1" instanceDir="cores/core1" /> <core name="myfirstcore" instanceDir="cores/myfirstcore" /> </cores>
sudo chown -R tomcat6 /etc/solr/ sudo service tomcat6 restart