<?xml version="1.0" encoding="utf-8"?>
<Context docBase="../../../webapps/solr.war" debug="0" crossContext="true">
<Environment name="solr/home" type="java.lang.String" value="D:/projects/search-engine/solrcloudv47/solrCloudA" override="true"/>
</Context>
备注:
apache-tomcat-7.0.20-solrcloudA:solr/home的value为D:/projects/search-engine/solrcloudv47/solrCloudA;
apache-tomcat-7.0.20-solrcloudB:solr/home的value为D:/projects/search-engine/solrcloudv47/solrCloudB;
apache-tomcat-7.0.20-solrcloudC:solr/home的value为D:/projects/search-engine/solrcloudv47/solrCloudc;
2. 修改<Tomcat.home>/conf/Server.xml文件中端口:
apache-tomcat-7.0.20-solrcloudA:
<Server port="7005" shutdown="SHUTDOWN">
<Connector port="7080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="7443" />
<Connector port="7009" protocol="AJP/1.3" redirectPort="7443" />
apache-tomcat-7.0.20-solrcloudB:
<Server port="8005" shutdown="SHUTDOWN">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
-------------------------------------------------------------------------------------------------------------------------------------------------
solrcloud的安装及配置
-------------------------------------------------------------------------------------------------------------------------------------------------
1. 创建Solrcloud相关目录
在D:\projects\search-engine\solrcloudv47下创建solrcloudA|solrcloudB|solrcloudC目录:
以solrCloudA为例,在solrCloudA下创建collection1和lib目录,在collections1下建立conf和data目录,
solrcloundB和solrCloudC也建立同样目录结构
2. solr基本配置:
a) 下载的SOLR的压缩包解压缩,将solr-4.7.0\example\webapps\solr.war解开,
b) 将solr-4.7.0\example\webapps\solr\WEB-INF\lib和solr-4.7.0\example\lib\ext中的jar文件
拷贝到solr-4.7.0\example\webapps\solr\WEB-INF\lib中;
c) 然后传到服务器的Tomcat下的webapps目录下。
d) 将solr-4.7.0\example\webapps\solr\WEB-INF\lib和solr-4.7.0\example\lib\ext下面的jar文件都拷贝到指定目录solrcloudA/lib/中。
e) 将solr-4.7.0\contrib目录下的jar文件拷贝到指定目录solrcloudA/lib/中。
f) 将solr-4.7.0\dist目录下的jar文件拷贝到指定目录solrcloudA/lib/中。
3. 创建solr文件(参见附件):
在<solr.home>下建立slor文件,如solrcloudA,则是在solrcloudA目录下建立,即:solrcloudA/solr.xml
在solrcloudB和solrcloudC中也建立solr.xml文件。
该文件中指定了ZooKeeper的相关配置,以及Solr Core的配置内容:
<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="true">
<cores defaultCoreName="collection1" host="${host:}" adminPath="/admin/cores" zkClientTimeout="${zkClientTimeout:15000}" hostPort="8080" hostContext="${hostContext:solr}">
</cores>
</solr>
注意:hostPort在solrcloudA中为7080;在solrCloudB中为8080;在solrCloudC中为9080;
这里,我们并没有配置任何的core元素,这个等到整个配置安装完成之后,通过SOLR提供的REST接口,来实现Collection以及Shard的创建,从而来更新这些配置文件。
------------------------------------------------------------------------------------------------------------------------------------------------
Zookeeper管理监控配置文件
------------------------------------------------------------------------------------------------------------------------------------------------
1、上solr配置文件到Zookeeper
java -classpath .;D:/projects/search-engine/solrcloudv47/solrCloudA/lib/* org.apache.solr.cloud.ZkCLI -cmd upconfig -zkhost 127.0.0.1:2181,127.0.0.1:2281,127.0.0.1:2381 -confdir D:/projects/search-engine/solrcloudv47/solrCloudA/collection1/conf -confname testconf
2、把将上传到zookeeper上的配置文件和目标collection联系起来
java -classpath .;D:/projects/search-engine/solrcloudv47/solrCloudA/lib/* org.apache.solr.cloud.ZkCLI -cmd linkconfig -collection collection1 -confname testconf -zkhost 127.0.0.1:2181,127.0.0.1:2281,127.0.0.1:2381
-confname 与第一个命令中的-confname一致
3、检查zookeeper上的存储情况:
D:\appservers\hadoop\zookeeper\zookeeperv3.4.6\zookeeperA\bin>zkCli -server localhost:2181
其中的命令为:ls / ls /configs ls /configs/testconf
-------------------------------------------------------------------------------------------------------------------------------------------------
Tomcat 配置修改
-------------------------------------------------------------------------------------------------------------------------------------------------
1、修改bin/catalina.bat
分别在apache-tomcat-7.0.20-solrcloudA
apache-tomcat-7.0.20-solrcloudB
apache-tomcat-7.0.20-solrcloudC中设置:
set JAVA_OPTS=%JAVA_OPTS% -DzkHost=127.0.0.1:2181,127.0.0.1:2281,127.0.0.1:2381
这就是solr和zookeeper交互的地方。
2、启动Tomcat
分别在apache-tomcat-7.0.20-solrcloudA
apache-tomcat-7.0.20-solrcloudB
apache-tomcat-7.0.20-solrcloudC中启动 tomcat:
bin/statup.bat
3、查看zookeeper中的数据状态
D:\appservers\hadoop\zookeeper\zookeeperv3.4.6\zookeeperA\bin>zkCli -server localhost:2181
ls /live_nodes 中可以看出存在3个活跃节点。
4、访问solr,多出Cloud菜单
6、创建collectoin、shard、replication
参数说明:
name 待创建Collection的名称
numShards 分片的数量
replicationFactor 复制副本的数量
如果成功,响应内容如下:
7、查看zookeeper中的数据状态
D:\appservers\hadoop\zookeeper\zookeeperv3.4.6\zookeeperA\bin>zkCli -server localhost:2181
8、访问solr
9、查看<solr.home>/solr.xml, solr.xml的内容已自动发生了变化
D:\projects\search-engine\solrcloudv47\solrCloudA>type solr.xml
<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="true">
<cores defaultCoreName="collection1" host="${host:}" adminPath="/admin/cores" zkClientTimeout="${zkClientTimeout:15000}" hostPort="9080" hostContext="${hostContext:solr}">
<core numShards="3" name="testcollection_shard3_replica1" instanceDir="testcollection_shard3_replica1" shard="shard3" collection="testcollection" coreNodeName="192.168.56.1:9080_solr_testcollection_shard3_replica1"/>
</cores>
</solr>
10、创建Replication
创建shard3的replication
http://localhost:8080/solr/admin/cores?action=CREATE&collection=testcollection&name=testcollection_shard3_replica2&shard=shard3
http://localhost:9080/solr/admin/cores?action=CREATE&collection=testcollection&name=testcollection_shard3_replica3&shard=shard3
创建Shard2的replication
http://localhost:7080/solr/admin/cores?action=CREATE&collection=testcollection&name=testcollection_shard2_replica2&shard=shard2
http://localhost:8080/solr/admin/cores?action=CREATE&collection=testcollection&name=testcollection_shard2_replica3&shard=shard2
创建Shard1的replication
http://localhost:7080/solr/admin/cores?action=CREATE&collection=testcollection&name=testcollection_shard1_replica2&shard=shard1
http://localhost:9080/solr/admin/cores?action=CREATE&collection=testcollection&name=testcollection_shard1_replica3&shard=shard1
------------------------------------------------
索引数据
------------------------------------------------
cd D:\projects\framework_refrence\searchEngine\solr\solr-4.7.0\solr-4.7.0\example\exampledocs
java -Durl=http://localhost:7080/solr/testcollection/update -jar post.jar *.xml
备注:
----------------------
如果要修改solr的data目录的位置,可以在<solr.home>/conf目录下建立solrcore.properties文件,在
solrcore.properties文件中加入如下内容
solr.data.dir=/home/hadoop/applications/storage/cloud/data
---------------------- org.apache.solr.cloud.ZkCLI的使用--------------------------
查看命令帮助:
java -classpath .;D:/projects/search-engine/solrcloudv47/solrCloudA/lib/* org.apache.solr.cloud.ZkCLI -cmd help -zkhost 127.0.0.1:2181,127.0.0.1:2281,127.0.0.1:2381
删除已有configs:
java -classpath .;D:/projects/search-engine/solrcloudv47/solrCloudA/lib/* org.apache.solr.cloud.ZkCLI -cmd clear /configs -zkhost 127.0.0.1:2181,127.0.0.1:2281,127.0.0.1:2381
------------------------删除collectoin----------------------------------------------
----------------------------删除索引------------------------------------------------------------
http://localhost:8080/solr/testcollection/update?stream.body=%3Cdelete%3E%3Cquery%3E*:*%3C/query%3E%3C/delete%3E&stream.contentType=text/xml;charset=utf-8&commit=true
参考: