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 our products

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!

Note for anyone following these instructions: If you intend to use the velocity browse interface, the above instructions (running out of /opt/solr/) break the filepath for the velocity writer.

To fix this, you’ll need to edit solrconfig.xml (lines 75-85) to point to the appropriate /contrib and /dist paths. (move them from /opt/solr-4.7.2 to /opt/solr as necessary)

The configuration example in the second method sets JAVA_HOME to /usr/java/default, however, the openjdk package does not create this link. To fix this create the directory <code>/usr/java</code> then run

<pre> ln -s /usr/lib/jvm/java-7-openjdk-amd64 /usr/java/default </pre>

Hi, I have some questions:

a. In section “Configuring a schema.xml for Solr” and so on, I have not too clear what is I must to do exactly if I decided to use the easy installation method. Most of the tutorial seems to be centred on manual installation. In such a case, how I can undo the easy installation in order to do the manual installation instead?

b. It is better to have Solr 3.6 than Solr 4 or later? I need to do complete indexing (words and displacements).

Thank you for your contribution, it is very useful.

Nacho

I have an other question:

Given the easy installation method, How to index documents and search them?

All tutorials that I have seen, consider different installations (for example, resources available in the example directory, which is not existent in this installation). I’m a beginner and it is so hard for me.

Thank you all in advance.

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
July 21, 2014

@brainbuz: Thanks, I’ve updated the article.

I installed successfully apache solr from terminal and showing INFO org.eclipse.jetty.server.AbstractConnector – Started SocketConnector@0.0.0.0:8983

. But url http://domanname:8983 is still couldn’t connect.

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
August 1, 2014

@kaythikhaing07: Does your domain name point to your droplet’s IP address? See How To Set Up a Host Name with DigitalOcean.

Hello,

Thanks for these great tutorials.

Easy to follow and works great.

I would like to a tutorials installing solr on tomcat. deploy the solr.war and access the solr web interface.

Let me know if someone cross this or have a doc.

Regards,

peacengell.

There is a contradiction in this article:

it needs a Java servlet container such as Tomcat or Jetty. In this article, we’ll use Jetty

Then later:

In this article, we will install solr-tomcat, so execute the following command:

The second is correct, tomcat is used.

I got the easy install to work by visiting http://my-ip-address:8080

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!

Become a contributor for community

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

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.