Ubuntu 8.04LTS (Hardy) Installing Apache Solr
Doing some research on which backend to use with Haystack I’ve decided on trying out Solr first. Solr is a search engine that runs on the JVM and comes highly recommened. Since I had never installed any Java software before it was a little intimidating, but as always I was up for the challenge.
Installing Java
The first thing we have to do before we can install Solr is install Sun’s version of Java. To do this we’ll have to add the multiverse repository by editing the source list.
sudo vi /etc/apt/sources.list
Now add the following to lines. These will tell Aptitude where the repositories are located and which version of Ubuntu to use.
deb http://archive.ubuntu.com/ubuntu/ hardy multiverse
deb-src http://archive.ubuntu.com/ubuntu/ hardy multiverse
After adding the multiverse repository we’ll want to update aptitude.
sudo apt-get update
Now that we have the latest package lists for the multiverse repository let’s install Sun Java 6.
sudo apt-get install sun-java6-jdk
Ubuntu doesn’t switch Java’s bin symlinks automatically so we’ll have to do that using the update-alternatives tool
sudo update-alternatives --config java
Select the number that corresponds with the following line.
/usr/lib/jvm/java-6-sun/jre/bin/java
Now that we have Java installed properly let’s move on to installing the solr-jetty package.
Installing Solr and Jetty
Conveniently Ubuntu has a package already setup for us that includes both Solr and Jetty together. To install the solr-jetty package run the following command.
sudo apt-get install solr-jetty
Unfortunately Jetty’s debian package has a bug in it with this version of Ubuntu (8.04). So we’ll have to install tomcat5.5 as well. There maybe a better way to work around this without having to install both servers, but this is the only way I could get it to work for myself. Let’s install the tomcat package.
sudo apt-get install tomcat5.5
Now that we have tomcat5.5 install we can go ahead and shut it off. You may have to adjust Tomcat’s run levels later so it doesn’t start back up when your server reboot, but for now this will save us some memory in the mean time.
sudo /etc/init.d/tomcat5.5 stop
The last step to fixing this bug is to edit your start.config file.
sudo /etc/jetty/start.config
And add the following line somewhere near the bottom.
$(tomcat.lib.home)/jasper-compiler-jdt.jar ! available org.eclipse.jdt.core.JDTCompilerAdapter
Let’s restart Jetty to have our changes take effect.
sudo /etc/init.d/jetty restart
To make sure everything is working fine we can use curl to hit our server.
curl -I 127.0.01:8280
And finally test to make sure our Solr admin is working properly.
curl -I http://127.0.0.1:8280/solr/admin/
If you see a 500 error, no Java compiler found, repeat steps above and proceed to pull out hair :)
Changing Jetty’s default port and opening up the firewall.
Since we’re going to open up Jetty’s listening port in our firewall we’ll probably want to change the default port so it’s a guessing game for those with malicious intent. Let’s do that now.
sudo vim /etc/jetty/jetty.xml
## Find the "Configure the Request Listeners" section and change the default port to one
## of your choosing. I chose to use port 8000 for this example.
<Set name="Port"><SystemProperty name="jetty.port" default="8000"/></Set>
After we’ve changed the default port we’ll have to open up that same port in our iptables if we want to be able to access the Solr admin from the web.
su
vim /etc/iptables.test.rules
Add the following line somewhere near your other http connections ports.
-A INPUT -p tcp --dport 8000 -j ACCEPT
We can update and then verify that our rules are correct and working properly.
iptables-restore < /etc/iptables.test.rules
iptables -L
Once we are satisfied we can then permanently save our rules using the following command
iptables-save > /etc/iptables.up.restore
Now we’ll need to restart Jetty for the new port to take effect. We’re already using the root account so we don’t need to type sudo. However, I recommend switching back to our own user account after we finish.
/etc/init.d/jetty restart
su username
If everything is setup correctly you should now be able to open up your web browser and visit Solr’s web based admin interface.
http://your.server.ip.address:8000/solr/admin
Next up we’ll configure Haystack to use Solr as a backend for some django search awesomeness.