001. How To Install Apache Solr On Apache Tomcat

Tested On

OS: CentOS 6.4 x86_64
Solr Version: 4.4
Tomcat Version: 6.0.24.0
Hardware: Virtual Box 4.2.12

About

Quote from Solr site:
“Solr is popular, blazing fast open source enterprise search platform from the Apache Lucene project. Its major features include powerful full-text search, hit highlighting, faceted search, near real-time indexing, dynamic clustering, database integration, rich document (e.g., Word, PDF) handling, and geospatial search. Solr is highly reliable, scalable and fault tolerant, providing distributed indexing, replication and load-balanced querying, automated failover and recovery, centralized configuration and more. Solr powers the search and navigation features of many of the world’s largest internet sites”

Install Solr

  • Update your operating system and reboot
yum update -y
reboot
  • Install tomcat and prerequisite packages
yum install wget tomcat6 java-1.6.0-openjdk apr -y
  • Configure tomcat to start at boot
chkconfig tomcat6 on
  • Download and install solr
mkdir /usr/local/src/solr
cd /usr/local/src/solr
wget http://apache.spd.co.il/lucene/solr/4.4.0/solr-4.4.0.tgz
cd /opt/
tar zvf /usr/local/src/solr/solr-4.*.tgz
mv solr-4.* solr
cp solr/dist/solr-4.4.0.war /opt/solr/example/solr/solr.war
chown tomcat:tomcat -R /opt/solr
chown tomcat:tomcat /usr/share/tomcat6
  • Add UTF-8 URI encoding option to apache tomcat connector
vi /etc/tomcat6/server.xml
...
<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
               URIEncoding="UTF-8" />
....
  • Create tomcat configuration file for the Solr application
vi /etc/tomcat6/Catalina/localhost/solr.xml
<Context path="/solr" docBase="/opt/solr/example/solr/solr.war" debug="0" crossContext="true">
        <Environment name="solr/home" type="java.lang.String" value="/opt/solr/example/solr" override="true"/>
</Context>
  • Copy Solr extensions files and log4j configuration file to tomcat
cp /opt/solr/example/lib/ext/* /usr/share/java/tomcat6/
cp /opt/solr/example/resources/log4j.properties /usr/share/java/tomcat6/
  • Create velocity log file
touch /usr/share/tomcat6/velocity.log
chown tomcat:tomcat /usr/share/tomcat6/velocity.log
  • Start tomcat daemon
service tomcat6 start
  •  Browse to Solr application using your web browser to check that it works
    http://192.168.10.12:8080/solr/

That’s all. Now you can use your Solr server to index and search new documents

Useful links:

  • http://lucene.apache.org/solr/