首页 > 编程开发 > 全文搜索 > solr

(根据此法在办公室机器上成功安装了Solr)

2014-08-29 06:30:15| 发布: | 浏览: 123790

1 http://wiki.apache.org/solr/SolrTomcat

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

SolrTomcat

Solr with Apache Tomcat

Solr runs fine with [WWW] Tomcat, see the instructions in the generic Solr installation page for general info before consulting this page.

  1. Solr with Apache Tomcat
    1. Simple Example Install
    2. Optional Configuration
      1. Logging
      2. URI Charset Config
      3. Configuring Solr Home with JNDI
    3. Multiple Solr Webapps
    4. Tomcat on Windows
      1. Single Solr app
      2. Multiple Solr apps
    5. External Resources
    6. Troubleshooting Errors

 

Simple Example Install

People have occasionally reported problems getting Solr to work with Tomcat -- usually as a result of confusion stemming from the multitudes of ways tomcat can be installed and configured (particularly if tomcat is installed by some package management system designed for the specific OS).

These steps illustrate the minimal possible steps needed to install both Tomcat and Solr from scratch by relying on the default "Solr Home Dir" ...

#if you copy this to a shell script, make sure to run dos2unix on it to ensure correct line-endings
mkdir solr-tomcat
cd solr-tomcat/
TOMCAT_VER=6.0.20
wget http://mirrors.ibiblio.org/pub/mirrors/apache/tomcat/tomcat-6/v$TOMCAT_VER/bin/apache-tomcat-$TOMCAT_VER.zip
#find the latest nightly solr build
NIGHTLY=`wget -O - http://people.apache.org/builds/lucene/solr/nightly/ | grep '.zip' | sed 's/.*\(solr-20..-..-..\.zip\).*/\1/' | tail -1`
wget http://people.apache.org/builds/lucene/solr/nightly/$NIGHTLY
unzip apache-tomcat-$TOMCAT_VER.zip
unzip $NIGHTLY
cp apache-solr-nightly/dist/apache-solr-nightly.war apache-tomcat-$TOMCAT_VER/webapps/solr.war
cp -r apache-solr-nightly/example/solr .
chmod a+x apache-tomcat-$TOMCAT_VER/bin/*
./apache-tomcat-$TOMCAT_VER/bin/startup.sh
echo "Now browse to http://localhost:8080/solr/admin/"
#Note that the startup.sh script is run from the directory containing your solr home ./solr
#since the solr webapp looks for $CWD/solr by default.
#You can use JNDI or a System property to configure the solr home directory (described below)
#If you want to run the startup.sh from a different working directory.

In addition to using the default behavior of relying on the Solr Home being in the current working directory (./solr) you can alternately add the solr.solr.home system property to your JVM settings before starting Tomcat...

export JAVA_OPTS="$JAVA_OPTS -Dsolr.solr.home=/my/custom/solr/home/dir/"

...or use a Context file to configure the Solr Home using JNDI (see below)

(Note that the Solr home directory can't just be a empty folder. If you do that, you may get random cryptic messages from your servlet container and/or Solr. For an example proper Solr home directory look at "example/solr/" in the Solr download package.)

Optional Configuration

Logging

For information about controlling JDK Logging (aka: java.util logging) in Tomcat, please consult the Tomcat docs... [WWW] http://tomcat.apache.org/tomcat-6.0-doc/logging.html

URI Charset Config

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.

Configuring Solr Home with JNDI

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:

  • The "conf/Catalina/localhost" directory may not exist by default in your installation. You may have to create it.

  • "/some/path/solr.war" is the absolute path to where ever you want to keep the Solr war using the appropriate syntax for your Operating System. In Tomcat 5.5 and later, the war file must be stored outside of the webapps directory for this to work. Otherwise, this entire Context element is ignored.

  • "/my/solr/home" should be to where you have createed your Solr Home directory, using the appropriate syntax for your Operating System.

  • Prior to Tomcat 5.5, a "path" attribute was required for Context elements (starting with 5.5, the path attribute must not be used except when statically defining a Context in server.xml, as it will be inferred from the Context fragment filename.

 

Multiple Solr Webapps

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 be http://host:port/solr1 and http://host:port/solr2

Tomcat on Windows

Single Solr app

  • Download and install [WWW] 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 [WWW] http://localhost:8080/

  • Change the c:\tomcat\conf\server.xml file to add the URIEncoding Connector element as shown above.

  • Download and unzip the Solr distribution zip file into (say) c:\temp\solrZip\

  • Make a directory called solr where you intend the application server to function, say c:\web\solr\

  • Copy the contents of the example\solr directory c:\temp\solrZip\example\solr\ to c:\web\solr\

  • Stop the Tomcat service

  • Copy the *solr*.war file from c:\temp\solrZip\dist\ to the Tomcat webapps directory c:\tomcat\webapps\

  • Rename the *solr*.war file solr.war

  • Use the system tray icon to configure Tomcat to start with the following Java option: -Dsolr.solr.home=c:\web\solr

  • Start the Tomcat service

  • Go to the solr admin page to verify that the installation is working. It will be at [WWW] http://localhost:8080/solr/admin

Multiple Solr apps

  • Download and install [WWW] 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 [WWW] http://localhost:8080/

  • Change the c:\tomcat\conf\server.xml file to add the URIEncoding Connector element as shown above.

  • Download and unzip the Solr distribution zip file into (say) c:\temp\solrZip\

  • Say you need two apps in c:\web\solr1 and c:\web\solr2; create these two directories

  • Copy the contents of the example\solr directory c:\temp\solrZip\example\solr\ to c:\web\solr1\ and to c:\web\solr2\

  • Stop the Tomcat service

  • Copy the *solr*.war file from c:\temp\solrZip\dist\ to the Tomcat lib directory c:\tomcat\lib\

  • Rename the *solr*.war file solr.war

  • Make a new text file in c:\tomcat\conf\Catalina\localhost called solr1.xml with the following code fragment

    <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>
    
  • Make a new text file in c:\tomcat\conf\Catalina\localhost called solr2.xml with the following code fragment

    <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>
    
  • Start the Tomcat service

  • Go to the solr admin pages for the 2 webapps to verify that the installation is working. It will be at [WWW] http://localhost:8080/solr1/admin and [WWW] http://localhost:8080/solr2/admin

External Resources

[WWW] http://www.ibm.com/developerworks/java/library/j-solr1/

Troubleshooting Errors

It's possible that you get an error related to the following:

SEVERE: Exception starting filter SolrRequestFilter
java.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.x
path.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.

last edited 2009-06-07 18:42:38 by YonikSeeley


转自:http://www.cnblogs.com/cy163/archive/2009/09/16/1568095
如非特别注明,本站内容均为领悟书生原创,转载请务必注明作者和原始出处。
本文地址:http://www.656463.com/article/zUnaAf.htm

相关专题

  • solr教程

    solr教程

    Solr采用Lucene搜索库为核心,提供全文索引和搜索开源企业平台,提供REST的HTTP/XML和JSON的API。