Solr4:Tomcat7下面配置Solr

参考:http://wiki.apache.org/solr/SolrTomcat
注意,仅是参考,上述文章中的某些内容并不正确,或许在以后的版本中有所改变。

软件:apache-solr-4.0.0/apache-tomcat-7.0.34

1.安装,配置Tomcat7 

安装就是解压缩Tomcat包到指定目录即可,如:C:\tomcat7;此情况下$CATALINA_HOME即为C:\tomcat7。 

1.1配置管理权限

  修改$CATALINA_HOME/conf/tomcat-users.xml中如下内容:

  <role rolename="manager-gui"/>
  <user username="tomcat" password="tomcat" roles="manager-gui"/>

 如此设置后,启动Tomcat后即可以通过http://localhost:8080/manager/登录到Tomcat管理页面。
 1.2配置URI Charset(solr4.1版本之前需要做此配置)

  修改$CATALINA_HOME/conf/server.xml中如下内容:

  <Connector ... URIEncoding="UTF-8"/>
     ...
  </Connector>

2.设置SOLR_HOME目录
 在C盘创建solr目录,然后拷贝~/solr/example/solr目录下面的所有内容即可;此情况下$SOLR_HOME即为C:\solr
3.创建solr的WEB应用
 安装:
  解压缩~/solr/dist/apache-solr-4.0.0.war$CATALINA_HOME/webapps/solr目录下,可以用Winrar工具或者是其它工具。
 配置:
  修改$CATALINA_HOME/webapps/solr/WEB-INF/web.xml,启用<env-entry>属性,并将之设置为正确的值,本文为C:/solr,完整内容为: 

   <env-entry>
       <env-entry-name>solr/home</env-entry-name>
       <env-entry-value>C:/solr</env-entry-value>
       <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>

4.配置solrconfig.xml
 文件位于$SOLR_HOME/collection1/conf/solrconfig.xml,需要修改存放索引数据的<dataDir>属性值,因为solr默认为Jetty服务器,Jetty服务器使用相对目录路径,而Tomcat不行,所以需要把它改成绝对目录路径。

    <dataDir>${solr.data.dir:C:/solr/collection1/data}</dataDir> 

5.如果是Solr4.4版本,则需要手工拷贝相关jar包到服务器相关目录

To get the same logging setup in another container (Tomcat for example) as with the example Jetty server, you need to do the following

1.Copy the jars from solr/example/lib/ext into your container's main lib directory. These jars will set up SLF4J and log4j.

a.Exactly where this lib directory is highly variable. 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.

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. Edit the configuration file for your preferred log destination.

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

原文参考:

http://wiki.apache.org/solr/SolrLogging

6.到此,配置solr到Tomcat结束

启动Tomcat后,可以登录solr管理页面:http://localhost:8080/solr/

如果是Solr4.4以前的版本,在IE中打开后台管理界面是存在一些问题的,需要使用Firefox/Chrome之类的浏览器;在Solr4.4版本中貌似还是没有解决这个问题。

插入数据:
~/solr/example/exampledocs$ java -Durl=http://localhost:8080/solr/update -jar post.jar *.xml
查询数据:
通过http://localhost:8080/solr/#/collection1/query直接查询,或者参考上一篇文章。
清除索引:

java -Ddata=args -Durl=http://localhost:8080/solr/update -Dcommit=false -jar post.jar "<delete><query>*:*</query></delete>"
java -Durl=http://localhost:8080/solr/update -jar post.jar -

增、删、改、查也可以参考上篇文章。增加自定义中文分词请参考下篇文章。

转载自:http://www.cnblogs.com/nayitian/archive/2013/01/18/2866733.html

猜你喜欢

转载自lalanicer.iteye.com/blog/1953817