Gary Sieling

Install Solr on Ubuntu

First, you need a JDK.

I ran this:

apt-get install openjdk-7-jdk

You can also use the Oracle JDK, but it requires signing an additional license. It also seems to involve a more convoluted installation (they make JAVA_HOME point to a symlink to the JDK, which changes as you upgrade).

For me, this JDK was installed here (you may want to note this):
/usr/lib/jvm/java-7-openjdk-i386/

Before running the solr installation steps, go to the Solr download page, and find the current version.

sudo su root
cd ~
wget http://apache.arvixe.com/lucene/solr/5.5.0/solr-5.5.0.tgz
tar xzf solr-5.5.0.tgz solr-5.5.0/bin/install_solr_service.sh --strip-components=2
sudo chmod +x install_solr_service.sh
sudo ./install_solr_service.sh solr-5.5.0.tgz

To run solr, you should then be able to run this:

service solr start

However, this may not work at first.

If you get an error that it can’t find the JDK:

The currently defined JAVA_HOME (/usr/lib/jvm/java-8-oracle) refers
to a location where Java could not be found.  Aborting.
Either fix the JAVA_HOME variable or remove it from the
environment so that the system PATH will be searched.

If this happens, do:

vi /etc/default/solr.in.sh

And add this line (using the path you saved above):

 
SOLR_JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386"

If you get a permissions denied error on /dev/null:

/opt/solr/bin/solr: line 120: /dev/null: Permission denied
Java not found, or an error was encountered when running java.
A working Java 7 or later is required to run Solr!
Please install Java or fix JAVA_HOME before running this script.
Command that we tried: '/usr/lib/jvm/java-7-openjdk-i386/bin/java -version'
Active Path:
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin

This indicates that /dev/null is a file, rather than a device. Run this:

rm /dev/null
mknod /dev/null c 1 3
chmod 666 /dev/null

Once you do this, solr should work.

However, you then should consider disabling external access, since the UI has no security.

The best way to do this is with firewall rules, since this blocks network traffic (make sure you take a snapshot of your virtual machine before you tinker with iptables, because you can lock yourself out)

sudo iptables -A INPUT -p tcp -s localhost --dport 8983 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 8983 -j DROP

If the above causes you a problem, you can still get out by rebooting.

This makes it permanent:

/sbin/iptables-save

Another option is to limit access to your IP address, although if your IP changes frequently this is not ideal, and it risks you losing the setting if you upgrade.

Alternately, since Solr by default runs on Jetty, you can restrict access to only the loopback address1. The disadvantage of doing this through Jetty is that it assumes you trust Solr not to open more ports without your awareness.

If you go the firewall route, a handy option is SSH port forwarding, which will allow you to access the solr UI when you SSH into the box.

If you use Putty this means adding “-L 8983:localhost:8983” to the command line arguments. Once you connect this way, you can use “http://localhost:8983/solr/#/” to connect to the Solr admin panel.

Logging
You may also want to check the log settings. By default log rotation appears to be enabled correctly, although the file size is a bit small:

File: /opt/solr/server/resources/log4j.properties

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.MaxFileSize=4MB
log4j.appender.file.MaxBackupIndex=9
  1. http://stackoverflow.com/questions/1955455/how-to-secure-jetty-to-only-allow-access-from-loopbacklocalhost []
Exit mobile version