Solr has been tested on Tomcat 5.5, 6, and 7. In Tomcat 7 changes were made to how URLs are resolved which has resulted in a bug where requests with paths ending in a "/" may not work correctly with Solr, but will work if the "/" is removed. SeeSOLR-2022 for full details.
See the instructions in the generic Solr installation page for general info before consulting this page.
Contents
Apache Tomcat is a web application server for Java servlets. These are instructions for manually installing Tomcat 6 on Linux, recommended because distribution Tomcats are either old or quirky.
Create the solr user. As solr, extract the Tomcat 6.0 download into /opt/tomcat6, hereafter referred to as the$CATALINA_HOME directory.
Edit $CATALINA_HOME/conf/tomcat-users.xml to enable the manager login as user "tomcat" with password "tomcat" (insecure):
<role rolename="manager"/><role rolename="admin"/><user username="tomcat" password="tomcat" roles="manager,admin"/>
Start Tomcat with $CATALINA_HOME/bin/catalina.sh run. Tomcat runs on the port defined$CATALINA_HOME/conf/server.xml, configured by default to port 8080.
The startup script tomcat6 can be placed in /etc/init.d/tomcat6 on CentOS/RedHat/Fedora so that you can start Tomcat usingservice tomcat6 start. Usechkconfig to enable the tomcat6 service to start on boot.
Skip this section if you have a binary distribution of Solr. These instructions are for buildingSolr from source, if you have a nightly tarball or have checked out the trunk from subversion athttp://svn.apache.org/repos/asf/lucene/dev/trunk. Assumes that you haveJDK 1.6 already installed.
In the source directory, run ant dist to build the .war file underdist. Build the example for theSolr tutorial by runningant example. Change to the 'example' directory, runjava -jar start.jar and visitlocalhost:8983/solr/admin to test that the example works with the Jetty container.
Assuming that Solr and its example are built, this is how to install the Solr example as an instance under Tomcat.
Copy the example/solr directory from the source to the installation directory like/opt/solr/example/solr, herafter$SOLR_HOME. Copy the .war filedist/apache-solr-*.war into $SOLR_HOME assolr.war.
The configuration file $SOLR_HOME/conf/solrconfig.xml in the example setsdataDir for the index to be./solr/data relative to the current directory - which is true for running the Jetty server provided with the example, but incorrect for Tomcat running as a service. Modify thedataDir to specify the full path to$SOLR_HOME/data:
<dataDir>${solr.data.dir:/opt/solr/example/solr/data}</dataDir>
The dataDir can also be temporarily overridden with theJAVA_OPTS environment variable prior to starting Tomcat:
export JAVA_OPTS="$JAVA_OPTS -Dsolr.data.dir=/opt/solr/example/solr/data"
Create a Tomcat Context fragment to point docBase to the$SOLR_HOME/solr.war file andsolr/home to $SOLR_HOME:
<?xml version="1.0" encoding="utf-8"?><Context 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>
Symlink or place the file in $CATALINA_HOME/conf/Catalina/localhost/solr-example.xml, where Tomcat will automatically pick it up. Tomcat deletes the file on undeploy (which happens automatically if the configuration is invalid).
Repeat the above steps with different installation directories to run multiple instances of Solr side-by-side.
If Tomcat is not already running, start it with service tomcat6 start or$CATALINA_HOME/bin/startup.sh run. The Solr admin should be available athttp://<host>:8080/solr-example/admin.
If you are sure that you will only ever run one instance of Solr, you can do away with the Context fragment by placing the .war in$CATALINA_HOME/webapps/solr-example.war and setting the Solr home through a global environment variable prior to starting Tomcat:
export JAVA_OPTS="$JAVA_OPTS -Dsolr.solr.home=/opt/solr/example"
$CATALINA_HOME/conf/tomcat-users.xml may be missing the correct user line.
The Context fragment may be invalid. Examine $CATALINA_HOME/tomcat6/logs/catalina.out.
View $CATALINA_HOME/logs/catalina.out for a better view of the exceptions. Probably caused by an incorrect path insolrconfig.xml or the Context fragment, or by an unclean build (runant clean and rebuild the source).
If, when installing Solr 3.5, you get an HTTP 500 error and the exception message begins with
org.apache.solr.common.SolrException: Error loading class 'solr.VelocityResponseWriter' at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:389)...
the problem is caused by incorrect <lib> locations in $SOLR_HOME/conf/solrconfig.xml and can be fixed by reading through this note in the mailing list archive:http://mail-archives.apache.org/mod_mbox/lucene-solr-user/201112.mbox/%3C7FA7F0B0-935A-4D01-A389-DB3B7EDA0464@gmail.com%3E
中告诉我们,要在使用tomcat6.0时避免这个错误,要么注释 <queryResponseWriter name="velocity" class="solr.VelocityResponseWriter" enable="${solr.velocity.enabled:true}"/>,要么将${solr.velocity.enabled:true}"/修改为${solr.velocity.enabled:false}"/,要么就得将solrconfig.xml中的<lib dir="../../contrib/extraction/lib" /><lib dir="../../contrib/clustering/lib" />这些相对目录的地址调整为正确的(因为大多数情况下我们都是从example\solr下copy的solrconfig.xml,因此里面的目录位置肯定与实际位置不相符合),修改的时候一定要注意dir="../../contrib/extraction/lib"这个地址的相对位置是对于$SOLR_HOME/conf/来说的,而不是$SOLR_HOME/conf/solrconfig.xml
For information about controlling JDK Logging (aka: java.util logging) in Tomcat, please consult the Tomcat docs...http://tomcat.apache.org/tomcat-6.0-doc/logging.html
If you are going to query Solr using international characters (>127) using HTTP-GET, you must configure Tomcat to conform to the URI standard by accepting percent-encoded UTF-8.
Edit Tomcat's conf/server.xml and add the following attribute to the correct Connector element: URIEncoding="UTF-8".
<Server ...> <Service ...> <Connector ... URIEncoding="UTF-8"/> ... </Connector> </Service></Server>
This is only an issue when sending non-ascii characters in a query request... no configuration is needed for Solr/Tomcat to return non-ascii chars in a response, or accept non-ascii chars in an HTTP-POST body.
A Tomcat context fragments can be used to configure the JNDI property needed to specify your Solr Home directory.
Just put a context fragment file under $CATALINA_HOME/conf/Catalina/localhost that looks something like this...
$ cat /tomcat55/conf/Catalina/localhost/solr.xml
<Context docBase="/some/path/solr.war" debug="0" crossContext="true" > <Environment name="solr/home" type="java.lang.String" value="/my/solr/home" override="true" /></Context>
A few things to keep in mind:
If you try to submit too long a GET query to Solr, then Tomcat will reject your HTTP request on the grounds that the HTTP header is too large; symptoms may include an HTTP 400 Bad Request error or (if you execute the query in a web browser) a blank browser window.
If you need to enable longer queries, you can set the maxHttpHeaderSize attribute on the HTTP Connector element in your server.xml file. The default value is 4K. (Seehttp://tomcat.apache.org/tomcat-5.5-doc/config/http.html)
Tomcat context fragments make configuring multiple Solr webapps (with JNDI) in a single Tomcat server easy.
Just follow the previous instructions for "Configuring Solr Home with JNDI" to create a seperate context fragment file under $CATALINA_HOME/conf/Catalina/localhost for each solr webapp you want to run:
$ cat /tomcat55/conf/Catalina/localhost/solr1.xml
<Context docBase="/some/path/solr.war" debug="0" crossContext="true" > <Environment name="solr/home" type="java.lang.String" value="/some/path/solr1home" override="true" /></Context>
$ cat /tomcat55/conf/Catalina/localhost/solr2.xml
<Context docBase="f:/solr.war" debug="0" crossContext="true" > <Environment name="solr/home" type="java.lang.String" value="/some/path/solr2home" override="true" /></Context>
Don't put anything related to Solr under the webapps directory.
The solr home directories are configured via JNDI in the context fragment, and in the examples above will be/some/path/solr1home and/some/path/solr2home The URLs to the two webapps will behttp://host:port/solr1 andhttp://host:port/solr2
Download and install Tomcat for Windows using the MSI installer. Install it with the tcnative.dll file. Say you installed it in c:\tomcat\
Check if Tomcat is installed correctly by going to http://localhost:8080/
* Note: For Tomcat 7 and Solr3.4(last version on 2011-09-23), the above option on setenv.bat may not work, so you could not use it and put this code fragment
on $CATALINA_HOME/conf/Catalina/localhost/solr.xml
<?xml version="1.0" encoding="UTF-8"?><Context docBase="C:\apache-tomcat-7.0.21\webapps\solr.war" debug="0" crossContext="true" > <Environment name="solr/home" type="java.lang.String" value="C:\solr" override="true" /></Context>
Go to the solr admin page to verify that the installation is working. It will be athttp://localhost:8080/solr/admin
Download and install Tomcat for Windows using the MSI installer. Install it with the tcnative.dll file. Say you installed it in c:\tomcat\
Check if Tomcat is installed correctly by going to http://localhost:8080/
<Context docBase="c:\tomcat\lib\solr.war" debug="0" crossContext="true" > <Environment name="solr/home" type="java.lang.String" value="c:\web\solr1" override="true" /></Context>
<Context docBase="c:\tomcat\lib\solr.war" debug="0" crossContext="true" > <Environment name="solr/home" type="java.lang.String" value="c:\web\solr2" override="true" /></Context>
Go to the solr admin pages for the 2 webapps to verify that the installation is working. It will be athttp://localhost:8080/solr1/admin andhttp://localhost:8080/solr2/admin
The MSI installer that installs Tomcat as a Windows service isn't prepared to support 64-bit Windows out of the box. There are some straightforward workarounds, though. Seehttp://stackoverflow.com/questions/211446/how-to-run-tomcat-6-on-winxp-64-bit
Indicate how to index in tomcat (rather than built-in jetty support via start.jar).
http://www.ibm.com/developerworks/java/library/j-solr1/
It's possible that you get an error related to the following:
SEVERE: Exception starting filter SolrRequestFilterjava.lang.NoClassDefFoundError: Could not initialize class org.apache.solr.core.SolrConfig at org.apache.solr.servlet.SolrDispatchFilter.init(SolrDispatchFilter.java:76).........Caused by: java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: No XPathFctory implementation found for the object model: http://java.sun.com/jaxp/xpath/dom at javax.xml.xpath.XPathFactory.newInstance(Unknown Source)
This is due to your tomcat instance not having the xalan jar file in the classpath. It took me some digging to find this, and thought it might be useful for others. The location varies from distribution to distribution, but I essentially just added (via a symlink) the jar file to the shared/lib directory under the tomcat directory.
SolrTomcat (last edited 2012-03-05 14:22:49 byMat Jaggard)