Tomcat安装和配置自行解决。官方网站:https://lucene.apache.org/solr/ 。
本人下载了solr-4.10.4版本,下载解压后打开example目录,内有示例程序,参照其README.txt可以直接实用jetty运行,用工具导入数据。
运行,打开命令窗口,在该目录下执行:
java -jar start.jar
然后访问:http://localhost:8983/solr/
示例数据在exampledocs目录下,进入该目录,执行:
java -jar post.jar *.xml
即可完成导入数据,详细参考自带文档。
如果需要在Tomcat运行,首先,拷贝出webapps内solr.war到Tomcat应用目录,这里实用了Tomcat7版本。
需要注意的是,首先是配置Solr的Home目录,打开web.xml文件:
官方默认注释掉了该部分,打开,修改为:
<!-- People who want to hardcode their "Solr Home" directly into the
WAR File can set the JNDI property here...
-->
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>D:\tomcat\solr-4.10.4\example\solr</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
这里实用的就是Solr自带的Home目录,这个目录可以更换位置。
再者,在Tomcat行跑,需要增加两个Jar包:
commons-logging-1.2.jar
slf4j-api-1.7.6.jar
否则会报错:
严重: Exception starting filter SolrRequestFilter
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/SolrLogging
at org.apache.solr.servlet.CheckLoggingConfiguration.check(CheckLoggingConfiguration.java:28)
at org.apache.solr.servlet.BaseSolrFilter.<clinit>(BaseSolrFilter.java:31)
和
三月 11, 2016 2:28:42 下午 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter SolrRequestFilter
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.http.impl.client.CloseableHttpClient.<init>(CloseableHttpClient.java:60)
at org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:271)
at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:127)
这种问题不多解释。
然后运行Tomcat,打开地址:http://localhost:8080/solr/#/
如下图所示,安装成功。
结束