Multiple SOLR Cores for Magento on Debian/Ubuntu/CentOS/RedHat

On Debian/Ubuntu

The most straightforward installation is pretty easy using tomcat and your package manager. The dependencies will be met automatically.

apt-get install tomcat6

On CentOS/RedHat

You need to grab some alternative repo's to make this possible


rpm -Uvh
rpm -Uhv
rpm -Uvh

Then you can install the package from yum

yum install yum-priorities ant tomcat6 tomcat6-admin

cd /usr/src/
mkdir sun-java
cd sun-java

Now it gets a little trickier. Sun used to permit direct downloads; but they now have a stupid session validation in place - so download the binary via your PC and upload it to the machine.

You need both the Linux JDK and JRE.

The commands would have been:

wget -O jdk.rpm.bin
wget -O jre.rpm.bin

You can alternatively use OpenJDK

wget -O /etc/yum.repos.d/jpackage50.repo
yum install -y java-1.6.0-openjdk

Once you've uploaded the binaries

chmod +x *.bin
ln -s /var/lib/tomcat6 /usr/share/tomcat6

Then the remaining steps

Then drop in your respective selection of solr

mkdir /usr/src/solr
cd /usr/src/solr
tar xvfz apache-solr-3.6.1.tgz
cd apache-solr-3.6.1
cp dist/apache-solr-*.war /var/lib/tomcat6/webapps/solr.war
mkdir -p /var/lib/tomcat6/solr

Then add the Magento solr configuration

touch $INSTALL_DIR/solr.xml
CORES=( "staging" "development" "live" )
for CORE in "${CORES[@]}"; do
  mkdir -p $INSTALL_DIR/$CORE/conf $INSTALL_DIR/$CORE/data 
  cp -par /usr/src/solr/apache-solr-3.6.1/example/solr/conf/* $INSTALL_DIR/$CORE/conf
  cp -par /home/path/public_html/lib/Apache/Solr/Conf/* $INSTALL_DIR/$CORE/conf

Then set up the cores

cat > /var/lib/tomcat6/solr/solr.xml << EOF
<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="true" sharedLib="lib">
  <cores adminPath="/admin/cores">
    <core name="staging" instanceDir="staging" config="solrconfig.xml" schema="schema.xml" />
    <core name="development" instanceDir="development" config="solrconfig.xml" schema="schema.xml" />
    <core name="live" instanceDir="live" config="solrconfig.xml" schema="schema.xml" />

Then finally, clean up permissions and restart solr

chown -R tomcat6:tomcat6 /var/lib/tomcat6/solr
/etc/init.d/tomcat6 restart

Then in Magento, you've now got 3 possible independent cores you can use for your store environments.

  • staging/solr
  • development/solr
  • live/solr