Solr服务安装(Windows)

来源:互联网 发布:单片机串口通讯程序 编辑:程序博客网 时间:2024/06/06 01:42


Solr是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口。用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文件,生成索引;也可以通过Http Get操作提出查找请求,并得到XML格式的返回结果。

资源准备

jdk1.7.0_60-x64、apache-tomcat-7.0.55、solr-4.10.2。相关资源下载地址:http://pan.baidu.com/s/1bnCVGTp

提示:Solr是运行在某servlet容器(Tomcat、Jboss、Jetty等)中的web服务,而此版本官方教程——solr-4.10.2/docs/tutorial.html中的实例是基于Jetty容器描述的,此文主要是想将教程中的example实例运行在Tomcat容器里。根文件目录如下:

根文件目录

部署Solr服务

将solr-4.10.2/dlist/solr-4.10.2.war解压到apache-tomcat-7.0.55/webapps下,并将solr-4.10.2文件夹重命名为solr。

指定solr.home

将solr-4.10.2/example/solr/*放到solr/home文件夹下。solr/home文件目录如下:

solr文件目录


指定solr.home的方式有多种:通过JAVA_OPTS设置Tomcat的运行环境变量。

  • JAVA_OPTS(start-solr-4.10.2.bat批处理文件)
    <span style="font-size:18px;">set CURRENT_DIR=%CD%set JAVA_HOME=%CURRENT_DIR%\jdk1.7.0_60-x64CD %CURRENT_DIR%\apache-tomcat-7.0.55\binset JAVA_OPTS=-Dsolr.solr.home=%CURRENT_DIR%\solr\home -Dsolr.log=%CURRENT_DIR%\solr\home\logscall startup.bat start</span>

运行Solr服务及问题解决

依据实际出现顺序

  • 问题01:日志异常

    异常现象

    <span style="font-size:18px;">java.lang.NoClassDefFoundError: Failed to initialize Apache Solr: Could not find necessary SLF4j logging jars. If using Jetty, the SLF4j logging jars need to go in the jetty lib/ext directory. For other containers, the corresponding directory should be used. For more information, see: http://wiki.apache.org/solr/SolrLoggingat org.apache.solr.servlet.CheckLoggingConfiguration.check(CheckLoggingConfiguration.java:28)at org.apache.solr.servlet.BaseSolrFilter.<clinit>(BaseSolrFilter.java:31)at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)at java.lang.reflect.Constructor.newInstance(Constructor.java:526)at java.lang.Class.newInstance(Class.java:374)</clinit></span>

    异常分析

    缺少日志相关JAR包。Solr从V4.3开始将日志相关JAR包与WAR包分离。可以访问提示链接:http://wiki.apache.org/solr/SolrLogging,获得更多信息。

    解决方案

    将solr-4.10.2/example/lib/ext下的*.jar以及solr-4.10.2/example/resources/log4j.properties文件复制到apache-tomcat-7.0.55/lib下。

  • 问题02:JAR包未找到警告

    异常现象

    <span style="font-size:18px;">WARN  - 2015-05-22 12:58:58.509; org.apache.solr.core.SolrResourceLoader; Can't find (or read) directory to add to classloader: ../../../contrib/extraction/lib (resolved as: D:\Applications\solr\home\collection1\..\..\..\contrib\extraction\lib).WARN  - 2015-05-22 12:58:58.510; org.apache.solr.core.SolrResourceLoader; Can't find (or read) directory to add to classloader: ../../../dist/ (resolved as: D:\Applications\solr\home\collection1\..\..\..\dist).WARN  - 2015-05-22 12:58:58.510; org.apache.solr.core.SolrResourceLoader; Can't find (or read) directory to add to classloader: ../../../contrib/clustering/lib/ (resolved as: D:\Applications\solr\home\collection1\..\..\..\contrib\clustering\lib).WARN  - 2015-05-22 12:58:58.511; org.apache.solr.core.SolrResourceLoader; Can't find (or read) directory to add to classloader: ../../../dist/ (resolved as: D:\Applications\solr\home\collection1\..\..\..\dist).WARN  - 2015-05-22 12:58:58.511; org.apache.solr.core.SolrResourceLoader; Can't find (or read) directory to add to classloader: ../../../contrib/langid/lib/ (resolved as: D:\Applications\solr\home\collection1\..\..\..\contrib\langid\lib).WARN  - 2015-05-22 12:58:58.512; org.apache.solr.core.SolrResourceLoader; Can't find (or read) directory to add to classloader: ../../../dist/ (resolved as: D:\Applications\solr\home\collection1\..\..\..\dist).WARN  - 2015-05-22 12:58:58.513; org.apache.solr.core.SolrResourceLoader; Can't find (or read) directory to add to classloader: ../../../contrib/velocity/lib (resolved as: D:\Applications\solr\home\collection1\..\..\..\contrib\velocity\lib).WARN  - 2015-05-22 12:58:58.514; org.apache.solr.core.SolrResourceLoader; Can't find (or read) directory to add to classloader: ../../../dist/ (resolved as: D:\Applications\solr\home\collection1\..\..\..\dist).</span>

    异常分析

    在solr/home/collection1/conf/solrconfig.xml配置中要求引入一下JAR包:


    解决方案

    将solr-4.10.2/contrib文件夹和solr-4.10.2/dist文件夹复制到solr文件夹下。将solrconfig.xml文件中的../../../替换为../../。

运行成功

访问路径一下路径:http://localhost:8080/solr,看是否成功?!

Best Wishes For You!

0 0
原创粉丝点击