How to Deploy Solr 4.3 On Jetty 9

OS

Ubuntu 13.04

Download

Apache Solr 4.3: http://mirror.reverse.net/pub/apache/lucene/solr/4.3.0/solr-4.3.0-src.tgz

Jetty 9: http://eclipse.org/downloads/download.php?file=/jetty/stable-9/dist/jetty-distribution-9.0.3.v20130506.tar.gz&r=1

Install Jetty 9

Jetty 9 requires JDK 7, so if you don’t have it installed, install it first. In Ubuntu, it is very convenient to install openjdk using apt-get.

apt-get install -y openjdk-7-jdk
mkdir -p /usr/java
ln -s /usr/lib/jvm/java-7-openjdk-amd64 /usr/java/default
echo "export JAVA_HOME=/usr/java/default" >> ~/.profile

Extract the tarball of Jetty 9 to a preferred directory, e.g. /opt. Then set $JETTY_HOME, create a new user called “jetty” and make it the owner of $JETTY_HOME.

tar zxvf jetty-distribution-9.0.3.v20130506.tar.gz -C /opt
mv /opt/jetty-distribution-9.0.3.v20130506/ /opt/jetty/
echo "export JETTY_HOME=/opt/jetty/" >> ~/.profile
useradd jetty -U -s /bin/false
chown -R jetty:jetty /opt/jetty

Copy script jetty.sh to /etc/init.d/ to make it run as a service.

cp -a /opt/jetty/bin/jetty.sh /etc/init.d/jetty

Create the settings file of jetty in /etc/default

vi /etc/default/jetty

and paste following in it.

JAVA_HOME=/usr/java/default # Path to Java
NO_START=0 # Start on boot
JETTY_HOST=0.0.0.0 # Listen to all hosts
JETTY_USER=jetty # Run as this user

Then start it as a service.

service jetty start

Once it prompts “Starting Jetty: OK”, you can visit http://localhost:8080/ to see the welcome page of Jetty 9.

If you want Jetty to start when boot up, execute following code

update-rc.d jetty defaults

If you want to change the port Jetty runs on, edit start.ini in $JETTY_HOME and change jetty.port

vi /opt/jetty/start.ini
...

#=============
# HTTP Connector
#-----------------------
jetty.port=9090
http.timeout=30000
etc/jetty-http.xml

...

Install Solr 4.3

Extract the tarball of Solr to anywhere you like.

tar zxvf solr-4.3.0-src.tgz -C /tmp

Copy the .war package to webapps directory of $JETTY_HOME, copy solr directory in the example/ directory to a preferred directory as $SOLR_HOME, e.g /opt. dist/ and contrib/ are also necessary.

cp -a solr-4.3.0/dist/solr-4.3.0.war /opt/jetty/webapps/solr.war
cp -a solr-4.3.0/example/solr /opt/solr
cp -a solr-4.3.0/dist /opt/solr
cp -a solr-4.3.0/contrib /opt/solr

Also, you will need the context and some modules to have Solr run properly on Jetty.

cp -a solr-4.3.0/example/contexts/solr-jetty-context.xml /opt/jetty/webapps/solr.xml
cp -a solr-4.3.0/example/lib/ext/* /opt/jetty/lib/ext/

Add a line to the settings file of Jetty

echo JAVA_OPTIONS="-Dsolr.solr.home=/opt/solr $JAVA_OPTIONS" >> /etc/default/jetty

Since the directory structure is changed, you need to edit solrconfig.xml to make solr able to read files in dist/ and contrib/. You also need to comment the non-existent-dir example to avoid warning.

vi /opt/solr/collection1/conf/solrconfig.xml
<!-- modify the path as following -->
...
<lib dir="../../contrib/extraction/lib" regex=".*\.jar" />
<lib dir="../../dist/" regex="solr-cell-\d.*\.jar" />

<lib dir="../../contrib/clustering/lib/" regex=".*\.jar" />
<lib dir="../../dist/" regex="solr-clustering-\d.*\.jar" />

<lib dir="../../contrib/langid/lib/" regex=".*\.jar" />
<lib dir="../../dist/" regex="solr-langid-\d.*\.jar" />

<lib dir="../../contrib/velocity/lib" regex=".*\.jar" />
<lib dir="../../dist/" regex="solr-velocity-\d.*\.jar" />
...

<!--  <lib dir="/non/existent/dir/yields/warning" /> -->

Make “jetty” the owner of $SOLR_HOME so that Jetty can access files in this directory.

chown -R jetty:jetty /opt/solr

Restart Jetty.

service jetty restart

Jetty will deploy Solr automatically and you should be able to visit Solr at http://localhost:9090/solr

 

 

 

 

 

Advertisements
This entry was posted in Solr. Bookmark the permalink.

18 Responses to How to Deploy Solr 4.3 On Jetty 9

  1. Pingback: [FE LOG]5.13-5.18 | Java Notes

  2. Pingback: Fetch and Index Web Pages with Nutch, MySQL and Solr | Java Notes

  3. shobhanray says:

    Excellent post. I’m surprised there aren’t many replies/views here. Have referred so many blogs and cookbooks for solr + jetty but only this one worked flawlessly. Thank you for taking time to write this blog. Following the Nutch one as well and eagerly looking forward to read all of ‘em.
    Cheers.

    • dcvan24 says:

      Thanks for your comments.I am glad that the post could help. Leave me a message if you have any questions and I will try to answer them.

  4. Josh says:

    Firstly, thank you for the steps. This worked very well with Ubuntu 12.04.
    There are two issues that I found that might need some clarification.
    Where you write:
    cp -a solr-4.3.0/example/contexts/solr-jetty-context.xml /opt/solr/webapps/solr.xml
    Should this not be:
    cp -a solr-4.3.0/example/contexts/solr-jetty-context.xml /opt/jetty/webapps/solr.xml

    and where you write the edits to the /opt/solr/collection1/conf/solrconfig.xml file
    should they not go up two levels instead of one.
    I.e.

    instead of:

    These two items just kind of struck me as a bit odd. I may be completely off the mark but I thought I would raise them for some clarification.

    Thanks again.

    • dcvan24 says:

      Thank you for the correction. I will edit the post soon. However, for the second issue, the path should work if you follow the steps strictly. The main idea is to let solrconfig.xml able to read the libraries.

      Hope this will help. Thanks!

      • Josh says:

        Maybe I am being thick here, but from the point of view of:
        /opt/solr/collection1/conf/solrconfig.xml:

        . = /opt/solr/collection1/conf
        .. = /opt/solr/collection1
        ../.. = /opt/solr
        ../../dist = /opt/solr/dist
        ../../contrib = /opt/solr/contrib
        

        Am I missing something?

      • dcvan24 says:

        That’s right, and dist/ and contrib/ should be in the root directory of solr if you follow the steps. So the path specified in solrconfig.xml should be right.

      • Josh says:

        So if that is correct and the paths to dist and contrib are /opt/solr/dist and /opt/solr/contrib, respectively, why do you have:

        <lib dir="../contrib/extraction/lib" regex=".*\.jar" />
        <lib dir="../dist/" regex="solr-cell-\d.*\.jar" />
        

        and not:

        <lib dir="../../contrib/extraction/lib" regex=".*\.jar" />
        <lib dir="../../dist/" regex="solr-cell-\d.*\.jar" />
        
      • dcvan24 says:

        Oh I see. I made a mistake. Thank you very much for reminding me of that! I’ve edited that.

  5. Josh says:

    Re the up two levels vs one level. This didn’t show up in the previous post for some reason.

    What I meant was
    solrconfig.xml seems like it should be edited like:
    lib dir=”../../contrib/extraction/lib” instead of lib dir=”../contrib/extraction/lib” for all the entries.

  6. Artem says:

    Hello, thank you for your post. There is a problem I encountered with Solr + Jetty 9 though: Solr does not properly shut down. It can be checked if by writing f.e. a custom UpdateHandler and overriding close() method (at least this is how I noticed the issue) – close() method just does not run. It works in example installation and in the same custom installation with Jetty 8 but it won’t work with Jetty 9. Not sure what might be the reason.

  7. John Karr says:

    For the people having path problems, I used absolute paths in the solrconfig.xml file, just replace ../../ with /opt/solr/ (assuming you followed the path suggestions). Applying these directions to 4.4 I did run into a glitch which I think was with the new method by which solr finds its cores. When I copied the example over collection1 was in solr/solr, just moving everything up 1 level resolved solr’s inability to read the solrconfig.xml file

    Overall this article was really useful and has been cut and pasted as the core of my notes on this. I am just learning solr and getting to the point where I wanted to set up something like I would run it in production.

  8. Alan Burns says:

    I think there is good information here but it is not working for me. I receive a
    Problem accessing /solr. Reason:

    NOT_FOUND

    When I go to localhost:8080/solr (our port is different).

    Jetty is running just fine. It is only the solr that is causing the problem.

    Any ideas or suggestions?

    Thanks in advance.

  9. Marteinn says:

    Great guide! Noticed you have a little type on the line:
    echo “export $JETTY_HOME=/opt/jetty/” >> ~/.profile

    Use “echo “export JETTY_HOME=/opt/jetty/” >> ~/.profile” instead.

    Thanks!
    / Martin

  10. Pingback: How to install CKAN on Ubuntu 16.04 [Tutorial under development] - Luiz Felipe F M Costa

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s