设为首页 收藏本站
查看: 164717|回复: 0

[经验分享] Solr with Apache Tomcat

[复制链接]

尚未签到

发表于 2015-11-12 10:05:47 | 显示全部楼层 |阅读模式
Solr Wiki
Login
SolrTomcat


  • FrontPage
  • RecentChanges
  • FindPage
  • HelpContents
  • SolrTomcat


  • Immutable Page
  • Info





Solr with Apache Tomcat


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


  • Solr with Apache Tomcat

    • Simple Example Install

      • Installing Tomcat 6
      • Building Solr
      • Installing Solr instances under Tomcat
      • Single Solr Instance
      • Troubleshooting

        • Login to Tomcat Management page does not work
        • Tomcat Manager does not list Solr
        • Exceptions when visiting Solr admin
        • HTTP 500 error
        • 关于这个问题的补充说明




    • Optional Configuration

      • Logging
      • URI Charset Config
      • Configuring Solr Home with JNDI
      • Enabling Longer Query Requests


    • Multiple Solr Webapps
    • Tomcat on Windows

      • Single Solr app
      • Multiple Solr apps
      • 64-bit Note


    • //!\\ TODO //!\\
    • External Resources
    • Troubleshooting Errors






Simple Example Install




Installing Tomcat 6


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=&quot;manager&quot;/>
<role rolename=&quot;admin&quot;/>
<user username=&quot;tomcat&quot; password=&quot;tomcat&quot; roles=&quot;manager,admin&quot;/>

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. Use
chkconfig to enable the tomcat6 service to start on boot.


Building Solr


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 the
Solr tutorial by running
ant example. Change to the 'example' directory, runjava -jar start.jar and visit
localhost:8983/solr/admin to test that the example works with the Jetty container.


Installing Solr instances under Tomcat


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 as
solr.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=&quot;$JAVA_OPTS -Dsolr.data.dir=/opt/solr/example/solr/data&quot;

Create a Tomcat Context fragment to point docBase to the$SOLR_HOME/solr.war file and
solr/home to $SOLR_HOME:


<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>
<Context docBase=&quot;/opt/solr/example/solr/solr.war&quot; debug=&quot;0&quot; crossContext=&quot;true&quot;>
<Environment name=&quot;solr/home&quot; type=&quot;java.lang.String&quot; value=&quot;/opt/solr/example/solr&quot; override=&quot;true&quot;/>
</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.



Single Solr Instance


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=&quot;$JAVA_OPTS -Dsolr.solr.home=/opt/solr/example&quot;



Troubleshooting




Login to Tomcat Management page does not work


$CATALINA_HOME/conf/tomcat-users.xml may be missing the correct user line.


Tomcat Manager does not list Solr


The Context fragment may be invalid. Examine $CATALINA_HOME/tomcat6/logs/catalina.out.


Exceptions when visiting Solr admin


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 (run
ant clean and rebuild the source).


HTTP 500 error


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


关于这个问题的补充说明




  • http://mail-archives.apache.org/mod_mbox/lucene-solr-user/201112.mbox/%3C7FA7F0B0-935A-4D01-A389-DB3B7EDA0464@gmail.com%3E

中告诉我们,要在使用tomcat6.0时避免这个错误,要么注释 <queryResponseWriter name=&quot;velocity&quot; class=&quot;solr.VelocityResponseWriter&quot; enable=&quot;${solr.velocity.enabled:true}&quot;/>,要么将${solr.velocity.enabled:true}&quot;/修改为${solr.velocity.enabled:false}&quot;/,要么就得将solrconfig.xml中的<lib
dir=&quot;../../contrib/extraction/lib&quot; /><lib dir=&quot;../../contrib/clustering/lib&quot; />这些相对目录的地址调整为正确的(因为大多数情况下我们都是从example\solr下copy的solrconfig.xml,因此里面的目录位置肯定与实际位置不相符合),修改的时候一定要注意dir=&quot;../../contrib/extraction/lib&quot;这个地址的相对位置是对于$SOLR_HOME/conf/来说的,而不是$SOLR_HOME/conf/solrconfig.xml


Optional Configuration




Logging


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


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=&quot;UTF-8&quot;.


<Server ...>
<Service ...>
<Connector ... URIEncoding=&quot;UTF-8&quot;/>
...
</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=&quot;/some/path/solr.war&quot; debug=&quot;0&quot; crossContext=&quot;true&quot; >
<Environment name=&quot;solr/home&quot; type=&quot;java.lang.String&quot; value=&quot;/my/solr/home&quot; override=&quot;true&quot; />
</Context>

A few things to keep in mind:



  • The &quot;conf/Catalina/localhost&quot; directory may not exist by default in your installation. You may have to create it.
  • &quot;/some/path/solr.war&quot; 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.
  • &quot;/my/solr/home&quot; should be to where you have created your Solr Home directory, using the appropriate syntax for your Operating System.
  • Prior to Tomcat 5.5, a &quot;path&quot; 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.



Enabling Longer Query Requests


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)



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 &quot;Configuring Solr Home with JNDI&quot; 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=&quot;/some/path/solr.war&quot; debug=&quot;0&quot; crossContext=&quot;true&quot; >
<Environment name=&quot;solr/home&quot; type=&quot;java.lang.String&quot; value=&quot;/some/path/solr1home&quot; override=&quot;true&quot; />
</Context>

$ cat /tomcat55/conf/Catalina/localhost/solr2.xml



<Context docBase=&quot;f:/solr.war&quot; debug=&quot;0&quot; crossContext=&quot;true&quot; >
<Environment name=&quot;solr/home&quot; type=&quot;java.lang.String&quot; value=&quot;/some/path/solr2home&quot; override=&quot;true&quot; />
</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 and
http://host:port/solr2


Tomcat on Windows




Single Solr app




  • 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/
  • 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 the &quot;solr home&quot; directory called, 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
  • Configure Tomcat to recognize the solr home directory you created, by adding the Java Options -Dsolr.solr.home=c:\web\solr and -Dsolr.velocity.enabled=false

    • either use the system tray icon to add the java option
    • or manually edit the environment script c:\tomcat\bin\setenv.bat and add it to JAVA_OPTS



  • * 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=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
    <Context docBase=&quot;C:\apache-tomcat-7.0.21\webapps\solr.war&quot; debug=&quot;0&quot; crossContext=&quot;true&quot; >
    <Environment name=&quot;solr/home&quot; type=&quot;java.lang.String&quot; value=&quot;C:\solr&quot; override=&quot;true&quot; />
    </Context>
  • Start the Tomcat service

  • Go to the solr admin page to verify that the installation is working. It will be athttp://localhost:8080/solr/admin



Multiple Solr apps




  • 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/
  • 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=&quot;c:\tomcat\lib\solr.war&quot; debug=&quot;0&quot; crossContext=&quot;true&quot; >
    <Environment name=&quot;solr/home&quot; type=&quot;java.lang.String&quot; value=&quot;c:\web\solr1&quot; override=&quot;true&quot; />
    </Context>
  • Make a new text file in c:\tomcat\conf\Catalina\localhost called solr2.xml with the following code fragment
    <Context docBase=&quot;c:\tomcat\lib\solr.war&quot; debug=&quot;0&quot; crossContext=&quot;true&quot; >
    <Environment name=&quot;solr/home&quot; type=&quot;java.lang.String&quot; value=&quot;c:\web\solr2&quot; override=&quot;true&quot; />
    </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 athttp://localhost:8080/solr1/admin andhttp://localhost:8080/solr2/admin



64-bit Note


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


//!\\ TODO //!\\


Indicate how to index in tomcat (rather than built-in jetty support via start.jar).


External Resources


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.

SolrTomcat (last edited 2012-03-05 14:22:49 byMat
Jaggard)


  • Immutable Page
  • Info



  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-138215-1-1.html 上篇帖子: SEVERE: org.apache.solr.common.SolrException: undefined field text 下篇帖子: Nutch-1.3中没了自带的搜索war文件,Nutch爬取与Solr搜索结合
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则  允许回帖邮件提醒楼主

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 在线客服QQ:点击这里给我发消息


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud bjyun

快速回复 返回顶部 返回列表