Search This Blog

Wednesday, April 9, 2014

Installing Apache Solr with Jetty in CentOS

Apache Solr comes with the Jetty web server to be run as an example server. For single-instance installations, this built-in configuration is robust enough. Enabling Solr as a typical startup service makes management much easier. All of the following directions should be run as the root user and are loosely based on the Solr wiki.
As a prerequisite, newer versions of Solr require an upgraded version of Java -
yum -y install java-1.7.0-openjdk.x86_64
To download Solr and drop it into our installation directory (/opt/solr) -
curl -O http://www.us.apache.org/dist/lucene/solr/4.4.0/solr-4.4.0.tgz
tar xzf solr-4.4.0.tgz
mv solr-4.4.0/example /opt/solr
Now to enable Solr as a standard service (since Red Hat typically uses /etc/sysconfig for storing environment variables, this location is changed as well) -
# Download the Jetty default startup script
curl -o /etc/init.d/solr http://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk/jetty-distribution/src/main/resources/bin/jetty.sh

# Change file to be executable
chmod +x /etc/init.d/solr

# Change references from Jetty configuration to Solr
perl -pi -e 's/\/default\/jetty/\/sysconfig\/solr/g' /etc/init.d/solr

# Enable the Solr service
chkconfig solr on
Creating a dedicated Solr user allows permissions to be explicitly defined and reduce confusion caused by shared user accounts -
useradd -r -d /opt/solr -M -c "Apache Solr" solr
Change permissions of Solr installation to this user
chown -R solr:solr /opt/solr/
The startup script looks for environment variables in /etc/sysconfig/solr. That configuration file should look like -
JAVA_HOME=/usr/java/default
JAVA_OPTIONS="-Dsolr.solr.home=/opt/solr/solr $JAVA_OPTIONS"
JETTY_HOME=/opt/solr
JETTY_USER=solr
JETTY_LOGS=/opt/solr/logs