24
Nov 2012
Multi Core Apache Solr using Search API
Apache Solr is a search platfrom from Apache Lucene Project. Drupal has integration with Apache Solr which is provided by Search API solr search which is dependent on Search API module. Solr Server is usually installed on some external server which is used to index search data. Since servers are capable enough to index data for multiple sites, the same server can be configured to index data for multiple sites, this particular configuration is called Multi-Core Solr Configuration.
On a linux server, the following packages have to be installed.(This blog is basically aimed for ubuntu, please find the corresponding command for your linux distributions.)
- Java.
- Tomcat.
sudo apt-get install openjdk-7-jdk #Install Java
sudo apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-user tomcat6-docs tomcat6-examples
Start tomcat
sudo /etc/init.d/tomcat6 restart
Tomcat runs on port 8080, so tying http://example-server:8080/ would show a page saying "It works !".
Dowload Apache Solr and extract the file
wget http://apache.techartifact.com/mirror/lucene/solr/3.6.0/apache-solr-3.6.... tar -xvzf apache-solr-3.6.0.tgz
Look for tomcat
whereis tomcat6
# The output should be tomcat6: /etc/tomcat6 /usr/share/tomcat6
cd /usr/shara/tomcat6
mkdir webapps # This folder should be created by default when you install tomcat, in case it is not there create one.
Copy the solr apache-solr-3.6.0.war into webapps folder. To the directory where apache solr was extracted.
sudo cp apache-solr-3.6.0/dist/apache-solr-3.6.0.war /usr/share/webapps/solr.war
Copy the example Apache SOLR application directory and all files within (in the unpacked folder) to a new solr folder in /usr/share/tomcat6:
sudo cp -R apache-solr-3.6.0/example/solr /usr/share/tomcat6/solr/
Create the Tomcat6-SOLR config file in /etc/tomcat6/Catalina/localhost/solr.xml
sudo vim /etc/tomcat6/Catalina/localhost/solr.xml# Add following lines to the file
<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>
Edit the Tomcat6 tomcat-users.xml file to add users to manage tomcat6
sudo nano /etc/tomcat6/tomcat-users.xml
<tomcat-users>
<role rolename="admin"/>
<role rolename="manager"/>
<user username="admin" password="my-password" roles="admin,manager"/>
</tomcat-users>
Edit the file
sudo vim /etc/default/tomcat6
In the above opened file, make sure that below configuration is set to no.
TOMCAT6_SECURITY=no
This completes the Solr Installation. Next we would connect a Drupal Site to Solr.
Download the required modules
drush dl search_api search_api_solr search_api_page
Download the Solr PHP Client and copy it to sites/all/libraries.
Make the backups of the defaut files.
cd /usr/share/tomcat6/solr/conf
sudo mv schema.xml schema.orig.xml
sudo mv solrconfig.xml solrconfig.orig.xml
Now copy these files from the search api solr module. Goto sites/all/modules/search_api_solr/includes of your Drupal installation and copy the schema.xml and solrconfig.xml files to /usr/share/tomcat6/solr/conf
sudo cp schema.xml /usr/share/tomcat6/solr/conf/schema.xml
sudo cp solrconfig.xml/usr/share/tomcat6/solr/conf/solrconfig.xml
Now configure the server in multi core configuration.
Goto the directory where apache solr was extracted
sudo cp ~/apache-solr-3.6.0/example/multicore/solr.xml /usr/share/tomcat6/solr/solr.xml
Each site should have different configuration in /usr/share/tomcat6/solr
Suppose we have two sites: site1, site2
sudo mkdir /usr/share/tomcat6/solr/site1 # Configuration for Drupal Site 1.
sudo mkdir /usr/share/tomcat6/solr/site2 # Configuration for Drupal Site 2.
Then, copy the /usr/share/tomcat6/conf directory into each directory you create:
sudo cp -R /usr/share/tomcat6/solr/conf/ /usr/share/tomcat6/solr/site1/conf/
sudo cp -R /usr/share/tomcat6/solr/conf/ /usr/share/tomcat6/solr/site2/conf/
Edit the solr.xml file in /usr/share/tomcat6/solr to add your site
sudo nano /usr/share/tomcat6/solr/solr.xml
# The content of the file would be
<cores adminPath="/admin/cores">
<core name="site1" instanceDir="site1" />
<core name="site2" instanceDir="site2" />
</cores>
</solr>
where each line <core name/> is for different sites. You can add another sites by adding another <core name="sitex" instanceDir="sitex" /> to this file.
Now for the site1 Drupal Installation enable the module Search API Search API Solr and do it site2 too.
drush en search_api search_api_solr
In the Search API configuration(admin/config/search/search_api) and click add server and fill in the following details
- Server Name: Site 1 Solr Server.
- Solr host: localhost or the remote host.
- Solr port: 8080
- Solr path: solr/site1 # This is the one defined in solr.xml file.
And save it, you should get a messsage: The Solr server could be reached (latency: 2.6741027832031 ms).
Similarly do it for site2, the only difference would be the Solr path which should be set to: solr/site2.
So two sites have their search data being indexed at a central place, but the index data of one site will not corrupt the data of other as they are configured in different directories.
