Solr installation under Tomcat
This post is a guide for installing Solr under Tomcat server. The steps illustrated here are tested on Mac OS, but it should also work on linux and unix systems.
Download Tomcat and Solr
Download tomcat http://tomcat.apache.org/download-60.cgi
Download solr http://lucene.apache.org/solr/downloads.html
On unix like systems, Solr can be downloaded from command line
cd /Users/Edwin/ wget http://archive.apache.org/dist/lucene/solr/3.5.0/apache-solr-3.5.0-src.tgz tar -xvf apache-solr-3.5.0-src.tgz
Tomcat Set Up
Extract tomcat to
/Users/Edwin/tomcat/tomcat6/
Edit /Users/Edwin/tomcat/tomcat6/conf/tomcat-users.xml to enable manager login as user “tomcat” and password “tomcat”, it could set to other user and password as you like for better security.The file should look like this after edit.
<?xml version='1.0' encoding='utf-8'?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <tomcat-users> <!-- NOTE: By default, no user is included in the "manager-gui" role required to operate the "/manager/html" web application. If you wish to use this app, you must define such a user - the username and password are arbitrary. --> <!-- NOTE: The sample user and role entries below are wrapped in a comment and thus are ignored when reading this file. Do not forget to remove <!.. ..> that surrounds them. --> <!-- <role rolename="tomcat"/> <role rolename="role1"/> <user username="tomcat" password="tomcat" roles="tomcat"/> <user username="both" password="tomcat" roles="tomcat,role1"/> <user username="role1" password="tomcat" roles="role1"/> --> <role rolename="manager"/> <role rolename="admin"/> <user username="tomcat" password="tomcat" roles="manager,admin"/> </tomcat-users>
Now, we can start the tomcat by run the below script
/Users/Edwin/tomcat/tomcat6/bin/start.sh
And then we visit localhost:8080
Building Solr
The below steps need to have jdk 1.6 and ant installed
Assume solr was downloaded extracted to /Users/Edwin/apache-solr-3.5/, do the below in the command line to build the solr example
cd /Users/Edwin/apache-solr-3.5/solr/ ant example
Run solr by issuing the below command in the command line and then visit localhost:8983/solr/admin
cd /Users/Edwin/apache-solr-3.5/solr/example java -jar start.jar
Build the solr war file by
cd /Users/Edwin/apache-solr-3.5/solr ant dist
Installing Solr under Tomcat
With the above steps, we have built the Solr and the example. We are now ready to install the example as an instance under Tomcat
Do the below commands to create a solr home directory and copy the example/solr directory and the war file to there
mkdir /Users/Edwin/solr/ cp -r /Users/Edwin/apache-solr/solr/example /Users/Edwin/solr/example cp /Users/Edwin/apache-solr/solr/dist/apache*.war /Users/Edwin/solr/example/solr/solr.war
Open the file /Users/Edwin/solr/example/solr/conf/solrconfig.xml, find the
<dataDir>${solr.data.dir:/Users/Edwin/solr/example/solr/data}</dataDir>
Create a Tomcat context fragment file /Users/Edwin/tomcat/tomcat6/conf/Catalina/localhost/solr-example.xml
<?xml version="1.0" encoding="utf-8"?> <Context docBase="/Users/Edwin/solr/example/solr/solr.war" debug="0" crossContext="true"> <Environment name="solr/home" type="java.lang.String" value="/Users/Edwin/solr/example/solr" override="true"/> </Context>
Restart the Tomcat
cd /Users/Edwin/tomcat/tomcat6/bin/ ./shutdown.sh ./start.sh
Go to localhost:8080/solr-example/admin to load the solr admin page.
When indexing data, solr creates data files in the directory /Users/Edwin/solr/example/solr/data which has to be writable by tomcat or any other users that is doing the indexing. The below will grant read, write and execute access to all users for every files under /Users/Edwin/solr/example
sudo chmod -R 777 /Users/Edwin/solr/example
This is convenient to solve permission issues during indexing data into solr, but it should only be used for convenience on DEV environment, never grant all access on prod environment.
See File ownerships and file permisions on Linux and unix like systems for more information.
Solr3.5 issue with Tomcat
For solr3.5, there is the below issue when trying to load the solar admin page
HTTP Status 500 - Severe errors in solr configuration. Check your log files for more detailed information on what may be wrong. If you want solr to continue after configuration errors, change: <abortOnConfigurationError>false</abortOnConfigurationError> in solr.xml ------------------------------------------------------------- org.apache.solr.common.SolrException: Error loading class 'solr.VelocityResponseWriter' at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:389) at org.apache.solr.core.SolrCore.createInstance(SolrCore.java:425) at org.apache.solr.core.SolrCore.createInitInstance(SolrCore.java:447) at org.apache.solr.core.SolrCore.initPlugins(SolrCore.java:1556) at org.apache.solr.core.SolrCore.initPlugins(SolrCore.java:1550) at org.apache.solr.core.SolrCore.initPlugins(SolrCore.java:1583)
To fix this issue open the file /Users/Edwin/solr/example/solr/conf/solrconfig.xml and replace the line
<queryResponseWriter name="velocity" class="solr.VelocityResponseWriter" enable="${solr.velocity.enabled:true}"/>
With
<queryResponseWriter name="velocity" class="solr.VelocityResponseWriter" enable="${solr.velocity.enabled:false}"/>
Restart the Tomcat
This is a lib referencing issue of the VelocityResponseWriter which usually happen the solr installation under Tomcat. For a better explanation of this issue, see the post http://lucene.472066.n3.nabble.com/solr-VelocityResponseWriter-error-in-version-3-5-0-td3570020.html
Search within Codexpedia
Search the entire web