甜思思 发表于 2015-11-21 14:41:57

solrCloud+tomcat+zookeeper配置

  一、环境准备:
  Solr版本:4.7.0
  下载地址:http://www.apache.org/dyn/closer.cgi/lucene/solr/4.7.0
  
  Tomcat版本:6.0.39
  下载地址:http://tomcat.apache.org/download-60.cgi
  
  ZooKeeer版本:3.4.6
  下载地址:http://www.apache.org/dyn/closer.cgi/zookeeper/
  
  二、配置
  实验环境:
  Windows XP SP3、JDK 1.6.0_10-rc2
  环境规划:
  Solr:2个solr服务;单collection,2个shard。每个shard一个reception。
  ZooKeeper:单个ZooKeeper服务。
  
  1、配置ZooKeeper
  在D盘根目录建立一个ZooKeeper文件夹。
  把下载的ZooKeeper发布包解压D:\ZooKeeper,重命名为server1。
  在D:\ZooKeeper\server1目录下新建一个data文件夹。
  D:\ZooKeeper\server1\conf下面的zoo_sample.cfg文件改名为zoo.cfg。
  修改zoo.cfg配置文件dataDir=/tmp/zookeeper改为dataDir=D:\\ZooKeeper\\server1\\data。
  完成上面操作,便完成了ZooKeeper的配置了。
  进入D:\ZooKeeper\server1\bin,双击zkServer.cmd便可以启动ZooKeeper。
  
  2、配置solr+tomcat
  在D盘新建一个tomcat文件夹。
  在D盘新建一个solr_home文件夹。
  在D:\solr_home新建solr1、solr2文件夹。
  
  2.1配置第一个solr
  把下载的tomcat发布包解压到D:\tomcat,重命名为tomcat6.0.39_solr_01。
  把solr发布包下的solr-4.7.0\dist\solr-4.7.0.war
  复制到D:\tomcat\tomcat6.0.39_solr_01\webapps下面。
  把D:\tomcat\tomcat6.0.39_solr_01\webapps\solr-4.7.0.war解压到
  D:\tomcat\tomcat6.0.39_solr_01\webapps下面,重命名solr-4.7.0为solr。
  删除D:\tomcat\tomcat6.0.39_solr_01\webapps\solr-4.7.0.war。
  
  在D:\tomcat\tomcat6.0.39_solr_01\webapps\solr\WEB-INF\lib中加入下面4个jar包。
  1)commons-logging-1.1.jar
  2)slf4j-log4j12-1.6.6.jar
  3)slf4j-api-1.6.6.jar
  4)dom4j-1.6.1.jar
  修改D:\tomcat\tomcat6.0.39_solr_01\webapps\solr\WEB-INF\web.xml中

<!--
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/put/your/solr/home/here</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
-->

  改为:
  <env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>D:\\solr_home\\solr1</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>



  修改D:\tomcat\tomcat6.0.39_solr_01\bin\catalina.bat,在第二行加入如下这段配置:

set &quot;JAVA_OPTS=-server -Xmx1024m -Xms256m -DzkHost=127.0.0.1:2181 -Dbootstrap_conf=true-DnumShards=2&quot;
  -DzkHost来指定zookeeper地址
  zookeeper是集群,应该写成 -DzkHost=localhost:9983,localhost:8574,localhost:9900
  bootstrap_conf=true将会上传你在web.xml里面solr/home里配置的数据目录下面solr.xml里面配置的所有的solrcore到zookeeper,也就是所有的core将被集群管理
  -DnumShards=2是指定我的集群分为两个shard
  
  把solr发布包\solr-4.7.0\example\solr下所有文件复制到D:\solr_home\solr1下面。
  修改D:\solr_home\solr1\solr.xml中

<int name=&quot;hostPort&quot;>${jetty.port:8983}</int>
  改为:

<int name=&quot;hostPort&quot;>${jetty.port:8080}</int>
  修改D:\solr_home\solr1\collection1\conf\solrconfig.xml中

<lib dir=&quot;../../../contrib/extraction/lib&quot; regex=&quot;.*\.jar&quot; />
<lib dir=&quot;../../../dist/&quot; regex=&quot;solr-cell-\d.*\.jar&quot; />
<lib dir=&quot;../../../contrib/clustering/lib/&quot; regex=&quot;.*\.jar&quot; />
<lib dir=&quot;../../../dist/&quot; regex=&quot;solr-clustering-\d.*\.jar&quot; />
<lib dir=&quot;../../../contrib/langid/lib/&quot; regex=&quot;.*\.jar&quot; />
<lib dir=&quot;../../../dist/&quot; regex=&quot;solr-langid-\d.*\.jar&quot; />
<lib dir=&quot;../../../contrib/velocity/lib&quot; regex=&quot;.*\.jar&quot; />
<lib dir=&quot;../../../dist/&quot; regex=&quot;solr-velocity-\d.*\.jar&quot; />

  改为

    <!--
<lib dir=&quot;../../../contrib/extraction/lib&quot; regex=&quot;.*\.jar&quot; />
<lib dir=&quot;../../../dist/&quot; regex=&quot;solr-cell-\d.*\.jar&quot; />
<lib dir=&quot;../../../contrib/clustering/lib/&quot; regex=&quot;.*\.jar&quot; />
<lib dir=&quot;../../../dist/&quot; regex=&quot;solr-clustering-\d.*\.jar&quot; />
<lib dir=&quot;../../../contrib/langid/lib/&quot; regex=&quot;.*\.jar&quot; />
<lib dir=&quot;../../../dist/&quot; regex=&quot;solr-langid-\d.*\.jar&quot; />
<lib dir=&quot;../../../contrib/velocity/lib&quot; regex=&quot;.*\.jar&quot; />
<lib dir=&quot;../../../dist/&quot; regex=&quot;solr-velocity-\d.*\.jar&quot; />
-->

  2.2配置第二个solr
  把下载的tomcat发布包解压到D:\tomcat,重命名为tomcat6.0.39_solr_02。
  把solr发布包下的solr-4.7.0\dist\solr-4.7.0.war
  复制到D:\tomcat\tomcat6.0.39_solr_02\webapps下面。
  把D:\tomcat\tomcat6.0.39_solr_02\webapps\solr-4.7.0.war解压到
  D:\tomcat\tomcat6.0.39_solr_02\webapps下面,重命名solr-4.7.0为solr。
  删除D:\tomcat\tomcat6.0.39_solr_02\webapps\solr-4.7.0.war。
  
  在D:\tomcat\tomcat6.0.39_solr_02\webapps\solr\WEB-INF\lib中加入下面4个jar包。
  1)commons-logging-1.1.jar
  2)slf4j-log4j12-1.6.6.jar
  3)slf4j-api-1.6.6.jar
  4)dom4j-1.6.1.jar
  修改D:\tomcat\tomcat6.0.39_solr_02\webapps\solr\WEB-INF\web.xml中

<!--
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/put/your/solr/home/here</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
-->

  改为:

<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>D:\\solr_home\\solr2</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>

修改D:\tomcat\tomcat6.0.39_solr_02\bin\catalina.bat,在第二行加入如下这段配置:  set &quot;JAVA_OPTS=-server -Xmx1024m -Xms256m-DzkHost=127.0.0.1:2181-DnumShards=2&quot;


  把solr发布包\solr-4.7.0\example\solr下所有文件复制到D:\solr_home\solr2下面。
  
  修改D:\solr_home\solr1\solr.xml中

<int name=&quot;hostPort&quot;>${jetty.port:8983}</int>
  改为:

<int name=&quot;hostPort&quot;>${jetty.port:8180}</int>
  修改D:\solr_home\solr1\collection1\conf\solrconfig.xml中

    <lib dir=&quot;../../../contrib/extraction/lib&quot; regex=&quot;.*\.jar&quot; />
<lib dir=&quot;../../../dist/&quot; regex=&quot;solr-cell-\d.*\.jar&quot; />
<lib dir=&quot;../../../contrib/clustering/lib/&quot; regex=&quot;.*\.jar&quot; />
<lib dir=&quot;../../../dist/&quot; regex=&quot;solr-clustering-\d.*\.jar&quot; />
<lib dir=&quot;../../../contrib/langid/lib/&quot; regex=&quot;.*\.jar&quot; />
<lib dir=&quot;../../../dist/&quot; regex=&quot;solr-langid-\d.*\.jar&quot; />
<lib dir=&quot;../../../contrib/velocity/lib&quot; regex=&quot;.*\.jar&quot; />
<lib dir=&quot;../../../dist/&quot; regex=&quot;solr-velocity-\d.*\.jar&quot; />

  改为

<!--
<lib dir=&quot;../../../contrib/extraction/lib&quot; regex=&quot;.*\.jar&quot; />
<lib dir=&quot;../../../dist/&quot; regex=&quot;solr-cell-\d.*\.jar&quot; />
<lib dir=&quot;../../../contrib/clustering/lib/&quot; regex=&quot;.*\.jar&quot; />
<lib dir=&quot;../../../dist/&quot; regex=&quot;solr-clustering-\d.*\.jar&quot; />
<lib dir=&quot;../../../contrib/langid/lib/&quot; regex=&quot;.*\.jar&quot; />
<lib dir=&quot;../../../dist/&quot; regex=&quot;solr-langid-\d.*\.jar&quot; />
<lib dir=&quot;../../../contrib/velocity/lib&quot; regex=&quot;.*\.jar&quot; />
<lib dir=&quot;../../../dist/&quot; regex=&quot;solr-velocity-\d.*\.jar&quot; />
-->

  修改D:\tomcat\tomcat6.0.39_solr_02\conf\server.xml各端口,避免和solr1的tomcat端口冲突。
  1)8005改为8105。
  2)8080改为8180。
  3)8443改为8583。
  4)8009改为8109。
  
  
  启动2个tomcat,在浏览器输入地址
  http://localhost:8080/solr/#/~cloud
  或者
  http://localhost:8180/solr/#/~cloud
  便可以看到如下图solr集群服务了。




  
  参考文献:
  http://my.oschina.net/132722/blog/142096
  http://blog.iyunv.com/shirdrn/article/details/9718387
页: [1]
查看完整版本: solrCloud+tomcat+zookeeper配置