在 Tomcat 中无法让 DataImportHandler 为 Solr 工作

Cannot get DataImportHandler working for Solr in Tomcat

我正在尝试在 Tomcat 6 容器中将 DataImportHandler 添加到我在 CentOS 6 上安装的 Solr 4.10.2。目的是为 MySQL 数据库中的数据编制索引以使其可搜索。

因此我在 /var/www/solr 创建了一个 Solr-home 目录。在这个文件夹中我有结构

solr.xml
zoo.cfg
conf/
    data-config.xml  
    schema.xml
    solrconfig.xml
dist/
    ...
    solr-dataimporthandler-4.10.2.jar
    solr-dataimporthandler-extras-4.10.2.jar
    ...
lib/
     mysql-connector-java-5.1.34-bin.jar

如果我开始 Tomcat 我可以通过 http://127.0.0.1:8088/solr/. But if I go to http://127.0.0.1:8088/solr/dataimport 访问 Solr frontpage 我收到一条错误消息

"HTTP Status 404 - /solr/dataimport"
type: Status report
message: /solr/dataimport
description: The requested resource (/solr/dataimport) is not available.

为什么我无法让数据导入处理程序工作?我在其他主题中找不到答案。

我的配置 XML 文件包含以下内容:

solrconfig.xml

<requestHandler name="/dataimport"
        class="org.apache.solr.handler.dataimport.DataImportHandler">
        <lst name="defaults">
                <str name="config">/var/www/solr/conf/data-config.xml</str>
        </lst>
</requestHandler>

<lib dir="/var/www/solr/dist/" regex="solr-dataimporthandler-\d.*\.jar" />

编辑:

Tomcat 启动 Tomcat servlet 的日志 (var/log/tomcat6/catalina.out) 如下所示

    INFO: Server startup in 3722 ms
Jan 23, 2015 9:46:08 AM org.apache.coyote.http11.Http11Protocol pause
INFO: Pausing Coyote HTTP/1.1 on http-8080
Jan 23, 2015 9:46:09 AM org.apache.catalina.core.StandardService stop
INFO: Stopping service Catalina
Jan 23, 2015 9:46:09 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: A web application appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.
Jan 23, 2015 9:46:09 AM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: A web application created a ThreadLocal with key of type [org.apache.solr.schema.DateField.ThreadLocalDateFormat] (value [org.apache.solr.schema.DateField$ThreadLocalDateFormat@29215f06]) and a value of type [org.apache.solr.schema.DateField.ISO8601CanonicalDateFormat] (value [org.apache.solr.schema.DateField$ISO8601CanonicalDateFormat@6b2ed43a]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
Jan 23, 2015 9:46:09 AM org.apache.coyote.http11.Http11Protocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8080
Jan 23, 2015 9:46:11 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Jan 23, 2015 9:46:11 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jan 23, 2015 9:46:11 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 986 ms
Jan 23, 2015 9:46:11 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jan 23, 2015 9:46:11 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.24
Jan 23, 2015 9:46:11 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor manager.xml
Jan 23, 2015 9:46:12 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor host-manager.xml
Jan 23, 2015 9:46:12 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive solr.war
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/share/java/tomcat6/slf4j-log4j12-1.7.9.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/share/java/tomcat6/slf4j-jcl-1.7.9.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/share/java/tomcat6/slf4j-jdk14-1.7.9.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/share/java/tomcat6/slf4j-nop-1.7.9.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/share/java/tomcat6/slf4j-simple-1.7.9.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
0    [main] INFO  org.apache.solr.servlet.SolrDispatchFilter  – SolrDispatchFilter.init()
44   [main] INFO  org.apache.solr.core.SolrResourceLoader  – Using JNDI solr.home: /var/www/solr
50   [main] INFO  org.apache.solr.core.SolrResourceLoader  – new SolrResourceLoader for directory: '/var/www/solr/'
66   [main] INFO  org.apache.solr.core.SolrResourceLoader  – Adding 'file:/var/www/solr/lib/mysql-connector-java-5.1.34/' to classloader
68   [main] INFO  org.apache.solr.core.SolrResourceLoader  – Adding 'file:/var/www/solr/lib/mysql-connector-java-5.1.34-bin.jar' to classloader
619  [main] INFO  org.apache.solr.core.ConfigSolr  – Loading container configuration from /var/www/solr/solr.xml
876  [main] INFO  org.apache.solr.core.CoresLocator  – Config-defined core root directory: /var/www/solr
896  [main] INFO  org.apache.solr.core.CoreContainer  – New CoreContainer 580871917
897  [main] INFO  org.apache.solr.core.CoreContainer  – Loading cores into CoreContainer [instanceDir=/var/www/solr/]
922  [main] INFO  org.apache.solr.handler.component.HttpShardHandlerFactory  – Setting socketTimeout to: 0
923  [main] INFO  org.apache.solr.handler.component.HttpShardHandlerFactory  – Setting urlScheme to: null
935  [main] INFO  org.apache.solr.handler.component.HttpShardHandlerFactory  – Setting connTimeout to: 0
936  [main] INFO  org.apache.solr.handler.component.HttpShardHandlerFactory  – Setting maxConnectionsPerHost to: 20
937  [main] INFO  org.apache.solr.handler.component.HttpShardHandlerFactory  – Setting corePoolSize to: 0
939  [main] INFO  org.apache.solr.handler.component.HttpShardHandlerFactory  – Setting maximumPoolSize to: 2147483647
939  [main] INFO  org.apache.solr.handler.component.HttpShardHandlerFactory  – Setting maxThreadIdleTime to: 5
941  [main] INFO  org.apache.solr.handler.component.HttpShardHandlerFactory  – Setting sizeOfQueue to: -1
942  [main] INFO  org.apache.solr.handler.component.HttpShardHandlerFactory  – Setting fairnessPolicy to: false
1361 [main] INFO  org.apache.solr.update.UpdateShardHandler  – Creating UpdateShardHandler HTTP client with params: socketTimeout=0&connTimeout=0&retry=false
1368 [main] INFO  org.apache.solr.logging.LogWatcher  – SLF4J impl is org.slf4j.impl.Log4jLoggerFactory
1381 [main] INFO  org.apache.solr.logging.LogWatcher  – Registering Log Listener [Log4j (org.slf4j.impl.Log4jLoggerFactory)]
1385 [main] INFO  org.apache.solr.core.CoreContainer  – Host Name: 
1511 [main] INFO  org.apache.solr.core.CoresLocator  – Looking for core definitions underneath /var/www/solr
1544 [main] INFO  org.apache.solr.core.CoresLocator  – Found 0 core definitions
1550 [main] INFO  org.apache.solr.servlet.SolrDispatchFilter  – user.dir=/usr/share/tomcat6
1552 [main] INFO  org.apache.solr.servlet.SolrDispatchFilter  – SolrDispatchFilter.init() done
Jan 23, 2015 9:46:15 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory sample
Jan 23, 2015 9:46:15 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
Jan 23, 2015 9:46:16 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
Jan 23, 2015 9:46:16 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jan 23, 2015 9:46:16 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jan 23, 2015 9:46:16 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/61  config=null
Jan 23, 2015 9:46:16 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4791 ms

我认为您的正则表达式不匹配两个 DIH 相关的罐子。尝试将配置更改为:

<lib dir="/var/www/solr/dist/" regex="solr-dataimporthandler-.*\.jar" />

或者,作为替代方案,您可以尝试指定每个库的完整路径:

<lib path="/var/www/solr/dist/solr-dataimporthandler-4.10.2.jar" />  
<lib path="/var/www/solr/dist/solr-dataimporthandler-extras-4.10.2.jar" />  

更新 经过一些故障排除后,问题似乎是 Solr 无法自动检测内核,因此 solrconfig.xml 根本没有加载。 所以解决方案是将 core.properties 文件添加到核心文件夹。