Skip to content

Instantly share code, notes, and snippets.

@chinthakagodawita
Last active November 2, 2015 05:19
Show Gist options
  • Save chinthakagodawita/394b6fda2043c8d6dec7 to your computer and use it in GitHub Desktop.
Save chinthakagodawita/394b6fda2043c8d6dec7 to your computer and use it in GitHub Desktop.

Install (Oracle) Java

(this has better performance than the OpenJDK): via http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

Make sure Oracle Java 7 is set as the default for the java command:

sudo update-java-alternatives -s java-7-oracle

And finally set up environment variables:

sudo apt-get install oracle-java7-set-default

Install Tomcat

sudo apt-get install tomcat7 tomcat7-admin

Once done, stop the Tomcat service so we can install Solr:

sudo service tomcat7 stop

Next, we configure Tomcat so that we have access to the management interface (accessible at http://server:8080/manager/html):

# Edit the users file
sudo nano /var/lib/tomcat7/conf/tomcat-users.xml

Add the following line before the </tomcat-users> tag:

<user username="admin" password="openitnow" roles="tomcat,admin,manager-gui"/>

Install Solr

Download the latest version of Solr from http://lucene.apache.org/solr/ (4.9.0 as of this writing):

wget http://apache.mirror.uber.com.au/lucene/solr/4.9.0/solr-4.9.0.tgz -P ~/
tar xvf ~/solr-4.9.0.tgz

Create a Solr data directory:

sudo mkdir /var/lib/tomcat7/solr

Deploy the Solr application into Tomcat:

sudo cp ~/solr-4.9.0/dist/solr-4.9.0.war /var/lib/tomcat7/webapps/solr.war
# Start then stop Tomcat so that it deploys the application
sudo service tomcat7 start
sudo service tomcat7 stop

Create Tomcat's Solr config:

echo '<Context docBase="/var/lib/tomcat7/webapps/solr.war" debug="0" privileged="true" allowLinking="true" crossContext="true">
  <Environment name="solr/home" type="java.lang.String" value="/var/lib/tomcat7/solr" override="true" />
</Context>
' > /var/lib/tomcat7/conf/Catalina/localhost/solr.xml

Copy the logging configuration over to Solr:

sudo cp ~/solr-4.9.0/example/resources/log4j.properties /usr/share/tomcat7/lib/
sudo cp ~/solr-4.9.0/example/lib/ext/* /usr/share/tomcat7/lib/

For a default example install, copy the config files over (in a production install, use the Solr config for the site being deployed, usually in the repository):

sudo cp -R ~/solr-4.9.0/example/multicore/core* /var/lib/tomcat7/solr/
sudo cp ~/solr-4.9.0/example/multicore/*.* /var/lib/tomcat7/solr/
chown -R tomcat7:tomcat7 /var/lib/tomcat7/solr

Managing cores

Adding a new core:

# Create a directory for the new core
sudo mkdir /var/lib/tomcat7/solr/newCore
# Copy the example config over
sudo cp -R /var/lib/tomcat7/solr/examplecore /var/lib/tomcat7/solr/newCore/
# Let Solr know about this new core
sudo nano /var/lib/tomcat7/solr/solr.xml

In solr.xml, beneath the tag, add a new entry resembling the following:

<core name="newCore" instanceDir="newCore" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment