Install Apache Solr 4.9 on a CentOS 7 VPS

Apache Solr is an open source enterprise search platform used to easily create search engines which searches websites, files and databases. Its major features include powerful full-text search, faceted search, distributed search, hit highlighting and index replication.
In this tutorial we will show you how to install Apache Solr on a CentOS 7 VPS.

Make sure your operating system is fully up to date by executing the following command:

yum update

Install the latest available version of Java on your server:

yum list available | grep -i jdk


Verify that Java is properly installed:

java -version
java version "1.7.0_65"
OpenJDK Runtime Environment (rhel- u65-b17)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)

The next step is to download and unpack the Solr archive. At the time of writing this tutorial, the latest stable version is Solr 4.9. Once you have the package, unpack it into the directory of your choice (in this tutorial we use ‘/opt’ for the Solr 4.9 installation). So, download and unpack Apache Solr 4.9 on your Centos 7 VPS:

cd /opt
wget http://www.bizdirusa.com/mirrors/apache/lucene/solr/4.9.0/solr-4.9.0.tgz
tar -xvf solr-4.9.0.tgz
mv /opt/solr-4.9.0 /opt/solr
mv /opt/solr/example /opt/solr/core

Create a systemd service for Solr or if you are used to the old init scripts, you can keep using them. Create an init script for the Solr service:

vi /etc/init.d/solr
# chkconfig: 2345 20 20
# short-description: Solr
# description: Startup script for Apache Solr Server

JAVA="/usr/bin/java -DSTOP.PORT=8079 -DSTOP.KEY=stopkey -jar start.jar"

start() {
echo -n "Starting Solr... "
$JAVA > $LOG_FILE 2>&1 &
sleep 2

    if [ $RETVAL = 0 ]
        echo "done."
        echo "failed. See error code for more information."
    return $RETVAL

stop() {
echo -n "Stopping Solr... "
pkill -f start.jar > /dev/null

    if [ $RETVAL = 0 ]
        echo "done."
        echo "failed. See error code for more information."
    return $RETVAL

case "$1" in
echo $"Usage: solr {start|stop|restart}"
exit 3
exit $RETVAL

Set the proper permission for the ‘solr’ script and make Solr automatically start on server boot:

chmod +x /etc/init.d/solr

chkconfig --add solr

You can now start Solr using the following command:

/etc/init.d/solr start

You should also be able to use the ‘service’ command to start,stop and restart Solr:

service solr start
service solr stop
service solr restart

Once Solr is up and running you should be able to access it through your favorite web browser at
http://server_IP:8983/solr/ (just replace ‘server_IP’ with your server IP address appropriately):

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install Apache Solr search platform for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.


Categories: Tutorials

View Comments

Leave a Comment