如何修复Solr异常: 找不到必要的SLF4j日志记录jar包?

17

我在Ubuntu 12.04上安装Solr 4.3时遇到了大问题。首先,我安装了Tomcat。我可以通过localhost:8080在浏览器中访问Tomcat。在“Tomcat Web Application Manager”中,我尝试通过2solr.war文件安装Solr 4.3。该文件已被上传和部署。但是我无法启动它。“失败 - 应用程序在/context路径/solr无法启动”。

日志文件( localhost.log )如下:

07.05.2013 11:05:36 org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: start: Starting web application at '/solr'
07.05.2013 11:05:36 org.apache.catalina.core.StandardContext filterStart
SCHWERWIEGEND: Exception starting filter SolrRequestFilter
org.apache.solr.common.SolrException: 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/SolrLogging
    at org.apache.solr.servlet.SolrDispatchFilter.<init>(SolrDispatchFilter.java:105)
    ... 33 more
07.05.2013 11:05:36 org.apache.catalina.core.ApplicationContext log
INFO: HTMLManager: list: Listing contexts for virtual host 'localhost'
07.05.2013 11:05:36 org.apache.catalina.core.StandardContext filterStart
SCHWERWIEGEND: Exception starting filter SolrRequestFilter
org.apache.solr.common.SolrException: 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/SolrLogging
    at org.apache.solr.servlet.SolrDispatchFilter.<init>(SolrDispatchFilter.java:105)
    ... 21 more

catalina.....log

07.05.2013 11:05:36 org.apache.catalina.core.StandardContext start
SCHWERWIEGEND: Error filterStart
07.05.2013 11:05:36 org.apache.catalina.core.StandardContext start
SCHWERWIEGEND: Context [/solr] startup failed due to previous errors
07.05.2013 11:05:36 org.apache.catalina.startup.HostConfig checkResources
INFO: Reloading context [/solr]
07.05.2013 11:05:36 org.apache.catalina.core.StandardContext stop
INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/solr] has not been started
07.05.2013 11:05:36 org.apache.catalina.core.StandardContext start
SCHWERWIEGEND: Error filterStart
07.05.2013 11:05:36 org.apache.catalina.core.StandardContext start
SCHWERWIEGEND: Context [/solr] startup failed due to previous errors

有人可以帮助我并告诉我该怎么做吗?

3个回答

29

根据日志所示 - 无法找到必要的SLF4j日志记录JAR文件。

您缺少slf4j JAR文件。

slf4j JAR 文件放置在 $CATALINA_BASE/lib 文件夹中。更多信息请参见此处


10
更具体地说,http://wiki.apache.org/solr/SolrLogging:要在例如Tomcat中获得与示例Jetty服务器相同的日志记录设置,您需要执行以下操作:
  1. 将solr/example/lib/ext中的jar复制到tomcat/lib以设置SLF4J
  2. 将solr/example/resources/log4j.properties中的日志配置复制到某个位置(例如tomcat/lib),并编辑文件以设置首选日志目标
  3. 可选地,如果您没有将log4j.properties放置在类路径上,请设置java选项-Dlog4j.configuration=file:///path/to/log4j.properties
- Ted
1
Solr在dist/solrj-lib/目录下分发相应的jar文件。只需复制它们:cp dist/solrj-lib/* /var/lib/tomcat7/lib(如果不存在,则创建“/lib”)。 - Capy
这个可以用,谢谢。不过,我想知道除了将这些文件复制到lib目录之外,是否有更好的方法来做到这一点。例如,我能否更改配置文件,以便tomcat知道在哪里找到它们? - Sriwantha Attanayake
@capy 运行得非常好。你应该提交作为另一种/后续答案。 - Nielsvh
2
你不需要复制JAR文件,可以在conf/catalina.properties中指向它们。 - reinierpost

1
如果您不想复制文件,可以修改CLASSPATH变量,以包含所有相关内容。
以下是一个示例:
cd /tmp
wget http://www.slf4j.org/dist/slf4j-1.6.6.zip
unzip slf4j-1.6.6.zip
mv slf4j-1.6.6/integration/lib slf4j
CLASSPATH="`find /tmp/slf4j/ -type f  | xargs echo | sed 's/ /:/g'`"

那会给你类似这样的东西:
# echo $CLASSPATH
/tmp/slf4j/slf4j-api-1.6.99.jar:/tmp/slf4j/slf4j-simple-1.6.99.jar:/tmp/slf4j/slf4j-simple-1.5.11.jar:/tmp/slf4j/slf4j-simple-1.4.2.jar:/tmp/slf4j/slf4j-api-1.5.11.jar:/tmp/slf4j/slf4j-simple-1.5.4-SNAPSHOT.jar:/tmp/slf4j/slf4j-nop-1.5.6.jar:/tmp/slf4j/slf4j-1.6.6.zip:/tmp/slf4j/slf4j-simple-1.5.0.jar:/tmp/slf4j/slf4j-api-2.0.99.jar

您可以在Tomcat的/etc/default/tomcat7(或在RHEL发行版上的/etc/tomcat7/tomcat7.conf)中设置变量CLASSPATH。因此,当Tomcat启动时,您将在catalina.out中看到类似于以下内容的输出:
SLF4J: Found binding in [jar:file:/tmp/slf4j/slf4j-nop-1.5.6.jar!/org/slf4j impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/tmp/slf4j/slf4j-simple-1.4.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/tmp/slf4j/slf4j-simple-1.5.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/tmp/slf4j/slf4j-simple-1.5.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/tmp/slf4j/slf4j-simple-1.5.4-SNAPSHOT.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/tmp/slf4j/slf4j-simple-1.6.99.jar!/org/slf4j/impl/StaticLoggerBinder.class]

我认为设置变量比复制内容更加清晰易懂,可以更好地维护您的系统。
如果您愿意,您可以使用slf4j包中的库(使用dpkg -L libslf4j-java / rpm -ql slf4j命令查找安装位置,并从/usr/share/java获取jar文件)。您还可以受益于能够使用系统工具(apt-get/yum)升级slf4j(以及通过CLASSPATH变量“包含”的其他库)。
希望这可以帮到您。
附注:如果您使用Debian/Ubuntu,则需要进行额外的步骤-您必须修改JAVA_OPTS以包含:
JAVA_OPTS="${JAVA_OPTS} -classpath ${CLASSPATH}"

为了使其起作用,似乎Debian / Ubuntu没有RHEL-based发行版中的config变量CLASSPATH。

/etc/default/tomcat7中设置CLASSPATH没有任何效果。 - reinierpost
谢谢,我已经更正了我的答案。希望现在可以工作了。 - Jakov Sosic

1

您需要按照日志文件中的提示进行操作:

<solr>/example/lib/ext/*.jar 中的 SLF4j 日志记录 jars 复制到 Tomcat Lib(例如 TOMCAT_HOME/lib, /usr/share/tomcat/lib)或 Webapp Lib 目录(例如 TOMCAT_HOME/webapps/solr/WEB-INF/lib)。这些 jars 将设置 SLF4Jlog4j

如果使用 Jetty,则需要将 SLF4j 日志记录 jars 放置在 jetty lib/ext 目录中。对于其他容器,应该使用相应的目录。有关更多信息,请参见:http://wiki.apache.org/solr/SolrLogging

换句话说,要使 Solr 在 Tomcat 中正常工作,您需要执行以下操作:

  1. Copy the SLF4j logging jars from <solr>/example/lib/ext/*.jar into Tomcat Lib (e.g. TOMCAT_HOME/lib, /usr/share/tomcat/lib) or Webapp Lib directory (e.g. TOMCAT_HOME/webapps/solr/WEB-INF/lib). These jars will set up SLF4J and log4j.

    For a Debian or Ubuntu server using the Tomcat package available from the OS vendor, this is likely to be /usr/share/tomcat6/lib or /usr/share/tomcat7/lib.

    For example:

    # cp -v /opt/solr-4.10.4/example/lib/ext/*.jar /usr/share/tomcat?/lib/
    

    or:

    # cp -v /opt/solr-4.10.4/example/lib/ext/*.jar /var/lib/tomcat7/webapps/solr/WEB-INF/lib/
    

    Alternatively set-up your CLASSPATH to point to your jar files.

  2. Copy the logging config from solr/example/resources/log4j.properties into a location on the classpath. Usually you can use the same location as the jar files above and edit the configuration file for your preferred log destination.

    Optionally, if you did not place log4j.properties on the classpath, set java option: -Dlog4j.configuration=file:///path/to/log4j.properties

  3. Restart Tomcat (e.g. sudo /etc/init.d/tomcat7 restart).

如果您仍然遇到问题,可以尝试使用-Dlog4j.debug=true启动服务器以查看更多详细信息。
请参见:在Jetty之外的其他容器中使用示例日志设置

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接