Skip to content

Instantly share code, notes, and snippets.

@seyhunak
Last active August 29, 2015 14:09
Show Gist options
  • Save seyhunak/80631fe1ecaae62e6819 to your computer and use it in GitHub Desktop.
Save seyhunak/80631fe1ecaae62e6819 to your computer and use it in GitHub Desktop.
Rails 4 - Sunspot - Solr - Tomcat

Instructions

Install OpenJDK

sudo apt-get -y install openjdk-7-jdk
sudo mkdir /usr/java
sudo ln -s /usr/lib/jvm/java-7-openjdk-amd64 /usr/java/default

Install Tomcat

sudo apt-get install tomcat7
sudo apt-get install tomcat7-admin

Install Solr

sudo wget http://archive.apache.org/dist/lucene/solr/4.8.1/solr-4.8.1.tgz
sudo tar -xvf solr-4.8.1.tgz 
sudo cp -R solr-4.8.1/example/ /opt/solr

Setup Solr with Tomcat

sudo cp -R /opt/solr/lib/ext/* /usr/share/tomcat7/lib/
sudo cp /opt/solr/webapps/solr.war /var/lib/tomcat7/webapps/solr.war
sudo cp -R /opt/solr /var/lib/tomcat7
sudo chown -R tomcat7:tomcat7 /var/lib/tomcat7/solr
service tomcat7 restart

cd /var/lib/tomcat7/solr
sudo mkdir <my_collection>
cd <my_collection>
sudo mkdir data
sudo chown -R tomcat7:tomcat7 /var/lib/tomcat7/solr

Setup Rails

cp <RAILS_ROOT>/solr/conf/schema.xml /var/lib/tomcat7/solr/<my_collection>
cp <RAILS_ROOT>/solr/conf/solrconfig.xml /var/lib/tomcat7/solr/<my_collection>

sudo chown -R tomcat7:tomcat7 /var/lib/tomcat7/solr
sudo service tomcat7 restart
### config/sunspot.yml
production:
solr:
hostname: localhost
port: 8080
log_level: WARNING
path: /solr/my_collection
# read_timeout: 2
# open_timeout: 0.5
@leandromoreira
Copy link

and I also needed to add my core
curl "http://localhost:8080/solr/admin/cores?action=CREATE&name=production&instanceDir=production&config=solrconfig.xml&schema=schema.xml&dataDir=data&persist=true"

persist=truemakes the magic, otherwise every time you restar server you lost your core conf

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