Installation and configuration of Apache Solr

This post was written by Mahi-Bhat on October 19, 2013
Posted Under: Uncategorized

1. Download Solr release from http://lucene.apache.org/solr/downloads.html

#wget http://mirror.olnevhost.net/pub/apache/lucene/solr/4.4.0/solr-4.4.0.tgz

2. Begin by unzipping the Solr release and changing your working directory to be the “example” directory.

#tar -xzvf solr-4.4.0.tgz

3. Check Java installed or not

#java -version

4. If not installed then install it using yum

#yum search java | grep ‘openjdk’
#sudo yum install java-1.7.0-openjdk.x86_64

5. Create a solr daemon named solr in /etc/rc.d/init.d and copy the following

########################################################
#!/bin/bash
# chkconfig: 2345 98 02
# description: Starts and stops Solr production

# source function library
#./etc/rc.d/init.d/functions

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

SOLR_HOME=/home/solr-4.4.0/example
PIDFILE=/var/run/solr.pid

START_COMMAND=”java -jar start.jar”
LOG_FILE=”$SOLR_HOME/logs/console.log”

NAME=”Solr”

start() {
echo -n “Starting $NAME…”
if [ -f $PIDFILE ]; then
echo -n “$PIDFILE exists. $NAME may be running.”
else
cd $SOLR_HOME
#$START_COMMAND 2 > $LOG_FILE &
$START_COMMAND > $LOG_FILE &
sleep 2
echo `ps -ef | grep -v grep | grep “$START_COMMAND” | awk ‘{print $2}’` > $PIDFILE
echo “Done”
fi
return 0
}

stop() {
echo -n “Stopping $NAME…”
kill `cat $PIDFILE`
rm $PIDFILE
echo “Done”
return 0
}

case “$1” in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 5
start
;;

*)
echo “Usage: $0 (start | stop | restart)”
exit 1
esac

exit $?
#############################################################

6. Add the daemon to auto start script for system boot

sudo /sbin/chkconfig –add solr
sudo /sbin/chkconfig –list solr
sudo /sbin/chkconfig solr on

7. Change mode of the script

#sudo chmod 766 /etc/rc.d/init.d/solr

8. Run the solr server
–Either–

sudo /etc/rc.d/init.d/solr start

–Or directly running start jar file–

#java -jar start.jar (single core –not required now)

9. Access solr admin utility using a browser

http://localhost:8983/solr

References
http://www.ibm.com/developerworks/opensource/library/os-php-apachesolr/
http://wiki.apache.org/solr

Add a Comment

required, use real name
required, will not be published
optional, your blog address