Apache

How To Install Apache Solr With Tomcat On CentOS

What is Solr?

Apache Solr is a fast open-source java search server. It is based on the Apache Lucene search libraries. It enables you to easily create search engines which searches websites, databases and files. It provides full-text search, highlight the hits and near real time indexing.

As I said above Apache Solr search server is written in Java. So, It uses a servlet container in the backend to run. If you install Apache Solr by default it comes with Jetty as the servlet container that you can uses to run some examples.

In this article I will guide you how to install Solr with Tomcat. Follow the below steps to do this.

Solr Account Creation

First create a user on the system and installed solr under that account. In my case I have created a user called “tom“.

# adduser tom
# passwd tom

Download Solr

Download the current stable version of solr from http://lucene.apache.org. Type the below wget command to download it.

# su - tom
$ wget http://apache.petsads.us/lucene/solr/4.2.0/solr-4.2.0.tgz
$ tar zxvf solr-4.2.0.tgz

Download Tomcat

Download the Tomcat current stable version of tomcat from http://tomcat.apache.org. Type the below wget command to download it. Now we will run both Tomcat and Solr under tom account that we create above.

$ wget http://mirror.symnds.com/software/Apache/tomcat/tomcat-7/v7.0.39/bin/apache-tomcat-7.0.39.tar.gz
$ tar xvfz apache-tomcat-7.0.39.tar.gz

Create Solr Directory

Create a solr directory, and in this directory we will host all the solr cores and this will also be used as SOLR_HOME.

# mkdir -p /home/tom/solr/example/
# cd /home/tom/solr-4.2.0/example
# cp -r solr /home/tom/solr/example/

Environment Variable Setup

Setup Environment Variable in .bash_profile that are required by both Tomcat and Solr. Add the below lines into .bash_profile.

# vim ~/.bash_profile
export CATALINA_HOME=/home/tom/apache-tomcat-7.0.39
export PATH=~/bin:~/local/bin:$CATALINA_HOME/bin:$PATH 
export CATALINA_OPTS="-server -Xmx2048m -Xms2048m"
export JAVA_OPTS="-Dsolr.data.dir=/home/tom/solr/example/solr"
export JAVA_OPTS="$JAVA_OPTS -Dsolr.solr.home=/home/tom/solr/example/solr"
export SOLR_HOME=/home/tom/solr/example/solr

Save and close file and execute the .bash_profile.

$ cd
$ . ./.bash_profile

Copy The Solr War File Into Example Directory

You have to copy the solr war file from distribution directory to the example SOLR_HOME directory that we created above.

$ cd /home/tom/solr-4.2.0/dist
$ cp solr-4.2.0.war /home/tom/solr/example/solr/

Change Tomcat Ports

You can change the Tomcat port if you want to install more than one Tomcat on the same server. If you are installing single Tomcat on the server so you don’t need to change these ports. As you can see in the below file Tomcat is running on 8005 port for shutdown, 8080 for http, 8443 for https and
8009 for AJP.

$ cd /home/tom/apache-tomcat-7.0.39/conf
$ grep -i port server.xml
<Server port="8005" shutdown="SHUTDOWN">
 <Connector port="8080" protocol="HTTP/1.1"
 <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
 <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Start Tomcat

catalina.sh script is used to start and stop the Tomcat, start the Tomcat typing below command:

$ cd /home/tom/apache-tomcat-7.0.39/bin

$ ./catalina.sh start
Using CATALINA_BASE:   /home/tom/apache-tomcat-7.0.39
Using CATALINA_HOME:   /home/tom/apache-tomcat-7.0.39
Using CATALINA_TMPDIR: /home/tom/apache-tomcat-7.0.39/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /home/tom/apache-tomcat-7.0.39/bin/bootstrap.jar:/home/tom/apache-tomcat-7.0.39/bin/tomcat-juli.jar

Note:- You will get the following error message if you don’t have installed Java on the system. Also make sure you have JAVA_HOME environment variable setup to point to Java on your system.

$ ./catalina.sh start
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program

Check Tomcat Log File For Error

You can also verify that the Tomcat started without any error.

$ cd /home/solrdev/apache-tomcat-7.0.39/logs

$ ls
manager.2017-01-24.log
host-manager.2017-01-24.log
localhost_access_log.2017-01-24.txt
localhost.2017-01-24.log
catalina.2017-01-24.log
catalina.out

$ tail catalina.out
INFO: Starting ProtocolHandler ["http-bio-8082"]
Jan 24, 2017 23:04:27 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8011"]
Jan 24, 2017 23:04:27 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 642 ms

Create Solr.xml

Now create a solr configuration file solr.xml like below:

$ cd /home/tom/apache-tomcat-7.0.39/conf/Catalina/localhost
$ vim solr.xml
<?xml version="1.0" encoding="utf-8"?>
<Context docBase="/home/tom/solr/example/solr/solr-4.2.0.war" debug="0" crossContext="true">
 <Environment name="solr/home" type="java.lang.String" value="/home/tom/solr/example/solr" override="true"/>
</Context>

Save and close file. After this, you can copy one of the solr example cores that comes with the Apache Solr to the /home/tom/solr/example/solr directory and add this to the /home/tom/solr/example/solr/solr.xml file. If you’ve developed your own core, copy those over to the /home/tom/solr/example/solr directory, and modify the /home/tom/solr/example/solr/solr.xml file with the core information.

For example, you have to add an entry similar to the following in the file /home/tom/solr/example/solr/solr.xml if your core name is “solrpro” .

$ vi solr.xml
  <cores adminPath="/admin/cores">
 <core name="solrpro" instanceDir="solrpro" />
 </cores> 

Type http://{your-ip-address}:8080/solr in your browser to view your Solr cores.

Thanks:)

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment