Tutorial

How To Install Solr on Ubuntu 14.04

Published on April 23, 2014
How To Install Solr on Ubuntu 14.04

Introduction

Solr is a search engine platform based on Apache Lucene. It is written in Java and uses the Lucene library to implement indexing. It can be accessed using a variety of REST APIs (e.g. XML and JSON). This is the feature list from their website:

  • Advanced Full-Text Search Capabilities
  • Optimized for High Volume Web Traffic
  • Standards Based Open Interfaces - XML, JSON and HTTP
  • Comprehensive HTML Administration Interfaces
  • Server statistics exposed over JMX for monitoring
  • Linearly scalable, auto index replication, auto failover and recovery
  • Near Real-time indexing
  • Flexible and Adaptable with XML configuration
  • Extensible Plugin Architecture

In this article, I will show you how to install Solr on Ubuntu using two different methods. The first one will be the simple method and the second the more advanced method. I recommend the second method because it installs a newer version of Solr on all Ubuntu versions, even in the most recent version 14.04 at time of writing.

Installing Solr using apt-get (easy way)

If you want to install Solr the easy way, you should use this section of the article. Solr doesn’t work alone; it needs a Java servlet container such as Tomcat or Jetty. In this article, we’ll use Jetty, although Tomcat is just as easy. First, we should install the Java JDK. If you want to install a custom version, please see this article. If you want a simple installation, execute the following commands:

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

Ubuntu provides 3 Solr packages by default: solr-common, the package that contains the actual Solr code; solr-tomcat, Solr integrated with Tomcat; and solr-jetty, which is just like solr-tomcat but with the Jetty web server. In this article, we will install solr-tomcat, so execute the following command:

sudo apt-get -y install solr-tomcat

Your Solr instance should now be available at http://YOUR_IP:8080/solr. Skip the next section on installing manually if you want to configure Solr.

Installing Solr Manually

To install Solr manually, you will need a little more time. First, we should install the Java JDK. If you want to install a custom version, please see this article. For this section, we will be using Jetty instead of Tomcat. If you want a simple installation, execute the following command:

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

We can now start the real installation of Solr. First, download all files and uncompress them:

cd /opt
wget http://archive.apache.org/dist/lucene/solr/4.7.2/solr-4.7.2.tgz
tar -xvf solr-4.7.2.tgz
cp -R solr-4.7.2/example /opt/solr
cd /opt/solr
java -jar start.jar

Check if it works by visiting http://YOUR_IP:8983/solr. When it works, go back into your SSH session and close the window with Ctrl+C. Then open the /etc/default/jetty file (nano /etc/default/jetty) and paste this into it:

NO_START=0 # Start on boot
JAVA_OPTIONS="-Dsolr.solr.home=/opt/solr/solr $JAVA_OPTIONS"
JAVA_HOME=/usr/java/default
JETTY_HOME=/opt/solr
JETTY_USER=solr
JETTY_LOGS=/opt/solr/logs

Save it and open the file /opt/solr/etc/jetty-logging.xml (nano /opt/solr/etc/jetty-logging.xml) and paste this into it:

<pre> <?xml version=“1.0”?> <!DOCTYPE Configure PUBLIC “-//Mort Bay Consulting//DTD Configure//EN” “http://jetty.mortbay.org/configure.dtd”> <!-- =============================================================== –> <!-- Configure stderr and stdout to a Jetty rollover log file –> <!-- this configuration file should be used in combination with –> <!-- other configuration files. e.g. –> <!-- java -jar start.jar etc/jetty-logging.xml etc/jetty.xml –> <!-- =============================================================== –> <Configure id=“Server” class=“org.mortbay.jetty.Server”>

  &lt;New id="ServerLog" class="java.io.PrintStream"&gt;
    &lt;Arg&gt;
      &lt;New class="org.mortbay.util.RolloverFileOutputStream"&gt;
        &lt;Arg&gt;&lt;SystemProperty name="jetty.logs" default="."/&gt;/yyyy_mm_dd.stderrout.log&lt;/Arg&gt;
        &lt;Arg type="boolean"&gt;false&lt;/Arg&gt;
        &lt;Arg type="int"&gt;90&lt;/Arg&gt;
        &lt;Arg&gt;&lt;Call class="java.util.TimeZone" name="getTimeZone"&gt;&lt;Arg&gt;GMT&lt;/Arg&gt;&lt;/Call&gt;&lt;/Arg&gt;
        &lt;Get id="ServerLogName" name="datedFilename"/&gt;
      &lt;/New&gt;
    &lt;/Arg&gt;
  &lt;/New&gt;

  &lt;Call class="org.mortbay.log.Log" name="info"&gt;&lt;Arg&gt;Redirecting stderr/stdout to &lt;Ref id="ServerLogName"/&gt;&lt;/Arg&gt;&lt;/Call&gt;
  &lt;Call class="java.lang.System" name="setErr"&gt;&lt;Arg&gt;&lt;Ref id="ServerLog"/&gt;&lt;/Arg&gt;&lt;/Call&gt;
  &lt;Call class="java.lang.System" name="setOut"&gt;&lt;Arg&gt;&lt;Ref id="ServerLog"/&gt;&lt;/Arg&gt;&lt;/Call&gt;&lt;/Configure&gt;

</pre>

Then, create the Solr user and grant it permissions:

sudo useradd -d /opt/solr -s /sbin/false solr
sudo chown solr:solr -R /opt/solr

After that, download the start file and set it to automatically start up if it hasn’t been done already:

sudo wget -O /etc/init.d/jetty http://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk/jetty-distribution/src/main/resources/bin/jetty.sh
sudo chmod a+x /etc/init.d/jetty
sudo update-rc.d jetty defaults

Finally start Jetty/Solr:

sudo /etc/init.d/jetty start

You can now access your installation just as before at http://YOUR_IP:8983/solr.

Configuring a schema.xml for Solr

First, rename the /opt/solr/solr/collection1 to an understandable name like apples (use whatever name you’d like). (This can be skipped if you installed it using apt-get. In that case, you can execute the following command instead: cd /usr/share/solr):

cd /opt/solr/solr
mv collection1 apples
cd apples

Also, if you installed Solr manually, open the file core.properties (nano core.properties) and change the name to the same name.

Then, remove the data directory and change the schema.xml:

rm -R data
nano conf/schema.xml

Paste your own schema.xml in here. There is a very advanced schema.xml in the Solr Repository. You can probably find a lot more of them on the internet, but I won’t go into depth about that. Restart Jetty/Tomcat:

For the simple installation.

sudo service tomcat6 restart

For the advanced installation.

sudo /etc/init.d/jetty restart

When you now visit your Solr instance, you should see the Dashboard with the collection somewhere.

Conclusion

You have now successfully installed Solr and can start using it for your own site! If you don’t know how to make a schema.xml, find a tutorial on how to do that. Then, find a library for your programming language that connects with Solr.

<div class=“author”>Submitted by: <a href=“http://www.benstechtips.net/go/doarticle”>Koen Vlaswinkel</a></div>

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
10 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Great post, but please update with the comments. Some links are broken, and start.ini is not found. The right info is in the comments.

Thanks anyway!

Thx for this useful guide, at the beginning I wasn’t able to modify my schema.xml , but at the end my path was the other one, so now it’s all working, thx so much again !

Tried installing apache solr with both the methods(completely removed previous installation files before starting another method) and both are showing the “Page Not Found” error. http://YOUR_IP:8080/solr http://YOUR_IP:8983/solr

Apart from the given steps procedure, is there anything needed to change values on any conf files? Also, I am working with sudo user access and serverpilot app directory location. Do I need to aware of any settings on server before doing this?

Thanks all in advance.

I have an error:

update-rc.d jetty defaults update-rc.d: using dependency based boot sequencing insserv: warning: script ‘K01jetty’ missing LSB tags and overrides insserv: warning: script ‘jetty’ missing LSB tags and overrides

Whats wrong?

Thanks

Same problem, anyone?

/etc/init.d/jetty start generates Cannot find a start.ini in your JETTY_BASE directory: /opt/solr ???

same problem here while with previus link all went perfect!!

/etc/init.d/jetty start generates Cannot find a start.ini in your JETTY_BASE directory: /opt/solr ???

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel