solr部署在tomcat下,solr集群依赖tomcat集群和zookeeper集群;
zookeeper:1.对象注册和发放中心,实现异步调用。
2.配置中心。(solrConfig.xml,schame.xml)
linux下配置solrCloud:
环境准备:
1.zookeeper集群配置:mv zoo_sample.cfg zoo.cfg
修改其配置:
交互地址
zookeeper目录下创建目录data和log,data内创建文件myid,内容为server编号;
启动:./zookeeper7/bin/zkServer.sh start
重启:./zookeeper7/bin/zkServer.sh restart
停止:./zookeeper7/bin/zkServer.sh stop
查看状态:
tomcat集群配置:
配置每个tomcat的catalina.sh,
配置每个tomcat的server.xml,
配置每个solr仓库的solr.xml,
把仓库核心配置上传到zookeeper注册中心(上传任意一个即可):
/home/hadoop/singleSolr/solr-4.10.3/example/scripts/cloud-scripts/zkcli.sh -zkhost 192.168.74.132:2187,192.168.74.132:2188,192.168.74.132:2189 -cmd upconfig -confdir /home/hadoop/clusterSolr/solr1/item/conf -confname myconf
登录zookeeper查看上传的配置文件:
/home/hadoop/clusterSolr/zookeeper9/bin/zkCli.sh -server 192.168.74.132:2187
/home/hadoop/clusterSolr/zookeeper9/bin/zkCli.sh -server 192.168.74.132:2188
/home/hadoop/clusterSolr/zookeeper9/bin/zkCli.sh -server 192.168.74.132:2189
ls /configs/myconf
启动4台tomcat服务:sh tomcat1/bin/startup.sh
solr页面查看:
集群分片:
登录zookeeper集群:
命令:./zkCli.sh -server 192.168.66.66:2182
solr集群分片命令:
http://192.168.74.132:8081/solr/admin/collections? action=CREATE&name=products&numShards=2&replicationFactor=2&maxShardsPerNode=8&property.schema=schema.xml&property.config=solrconfig.xml
删除旧solrCloud集群分片:
http://192.168.66.66:9000/solr/admin/collections?action=DELETE&name=item
(模拟多台服务器)
在solr.xml中配置集群对象:
<!-- 把集群对象交给spirng管理 -->
<bean class="org.apache.solr.client.solrj.impl.CloudSolrServer">
<constructor-arg name="zkHost"
value="192.168.66.66:2182,192.168.66.66:2183,192.168.66.66:2184"></constructor-arg>
<property name="defaultCollection" value="item"></property>
</bean>
在搜索的dao中注入集群进行搜索: