Skip to content

Instantly share code, notes, and snippets.

@tegansnyder
Last active December 3, 2018 15:08
Show Gist options
  • Save tegansnyder/c22e1b6fcfedc6181f56 to your computer and use it in GitHub Desktop.
Save tegansnyder/c22e1b6fcfedc6181f56 to your computer and use it in GitHub Desktop.
SOLR setup script for Magento multi-core using default Jetty servlet

This guide assumes you are on Centos or a Redhat / Fedora system.

install Java JDK

sudo yum remove java
sudo yum install java-1.7.0-openjdk
sudo yum install java-1.7.0-openjdk-devel

# download Solr
cd ~/
curl -O http://archive.apache.org/dist/lucene/solr/3.6.2/apache-solr-3.6.2.tgz
tar -xzvf apache-solr-3.6.2.tgz

# rename solr directory to solr
mv apache-solr-3.6.2 solr
# move it to to nice location
sudo mv solr /etc/
cd /etc/solr
# rename example directory to magento
sudo mv example magento

# copying the Magento Solr Configuration from your magento-root folder
cd /etc/solr/magento/solr/conf
yes | cp -R /var/www/magento-root/lib/Apache/Solr/conf/* .


# set permissions
cd /etc/
sudo chown root:root solr
sudo chown root:root solr/*

Setting up the Solr cores.

Before starting Solr lets setup the cores we want. This is useful if you have multiple Magento instances each with there own Solr index.

cd /etc/solr/magento/solr

Make the solr.xml file look like this:

<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="false">
  <cores adminPath="/admin/cores">
    <core name="instance1" instanceDir="instance1" />
    <core name="instance2" instanceDir="instance2" />
  </cores>
</solr>

Then create the directories:

mkdir -p /etc/solr/magento/solr/instance1/conf
mkdir -p /etc/solr/magento/solr/instance1/conf

Then copy the bash conf folder into each core directory:

yes | cp -R /etc/solr/magento/solr/conf/* /etc/solr/magento/instance1/conf
yes | cp -R /etc/solr/magento/solr/conf/* /etc/solr/magento/instance2/conf

Scripting Solr Startup and Shutdown

Create a script called /etc/init.d/solr with the contents below:

#!/bin/sh
#
# solr       used for searching magento stores
# chkconfig: 35 92 08
# description: Starts and stops Apache Solr
# processname: solr-server
 
SOLR_DIR="/etc/solr/magento"
JAVA_OPTIONS="-Xmx1024m -DSTOP.PORT=8079 -DSTOP.KEY=magento -jar  start.jar"
LOG_FILE="/var/log/solr.log"
JAVA="/usr/bin/java"
 
case $1 in
start)
echo -n "Starting Solr"
cd $SOLR_DIR
$JAVA $JAVA_OPTIONS 2> $LOG_FILE &
;;
stop)
echo -n "Stopping Solr"
cd $SOLR_DIR
$JAVA $JAVA_OPTIONS --stop
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}" >&2
exit 1
;;
esac

```bash
sudo chmod +x /etc/init.d/solr
sudo /etc/init.d/solr start (stop/restart)

When you have all the cores in place you can start Solr:

sudo /etc/init.d/solr start

After you configure it in your Magento admin make sure to flush FPC and reindex:

n98-magerun.phar index:reindex catalogsearch_fulltext

You can then visit the Solr admin: http://magento-store.com:8983/solr/

@joaquinhdzg
Copy link

Thank you very helpful.

Maybe this comments will help:
a) In the "Scripting Solr Startup and Shutdown" section, the last 3 lines do not belong to the "/etc/init.d/solr" script.

```bash
sudo chmod +x /etc/init.d/solr
sudo /etc/init.d/solr start (stop/restart)

b) And maybe add an automatic star on reboot:
chkconfig solr on

Regards,
Joaquin.

@gauravt
Copy link

gauravt commented Sep 20, 2016

Does it also require a Magento module to communicate between Solr and Magento.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment