本文是在單機環境下模擬集群環境,進行solrcloud的配置安裝。
-------------------------------------------
所用環境及軟件:
------------------------------------------
1. Windows 7 64bit:
2. Jdk v1.7
3. Tomcat v7.0.20 下載地址: http://tomcat.apache.org/
4. Zookeepr v3.4.6 下載地址: http://zookeeper.apache.org/releases.html
5. Solr v4.7.0 下載地址: https://lucene.apache.org/solr/
-------------------------------------------------------------------------------------------------------------------------------------------------
zookeeper的集群安裝
-------------------------------------------------------------------------------------------------------------------------------------------------
1. 下載Zookeeper,解壓之;
2. 在D:\appservers\hadoop\zookeeper\zookeeperv3.4.6 建立如下目錄:

zookeeperA|zookeeperB|zookeeperC用於存放剛才解壓過的zookeeper,將剛才解壓過的zookpeer文件分別拷入這3個文件夾;

zookeeperA_data|zookeeperB_data|zookeeperC_data 用於存放數據快照及日志文件,並在此文件夾下建立data和logs目錄;

3.以zookeeperA為例,配置zoo.cfg文件
拷貝zookeeperA/conf/zoo_sample.cfg,並修改文件名為zoo.cfg;
修改zoo.cfg文件(參見附件):
tickTime=2000
initLimit=10
syncLimit=5
dataDir=D:/appservers/hadoop/zookeeper/zookeeperv3.4.6/zookeeperA_data/data
clientPort=2181
server.1=127.0.0.1:2788:3788
server.2=127.0.0.1:2888:3888
server.3=127.0.0.1:2988:3988
dataLogDir=D:/appservers/hadoop/zookeeper/zookeeperv3.4.6/zookeeperA_data/logs
參數說明:
tickTime:心跳時間,為了確保連接存在的,以毫秒為單位,最小超時時間為兩個心跳時間
initLimit:多少個心跳時間內,允許其他server連接並初始化數據,如果ZooKeeper管理的數據較大,則應相應增大這個值
clientPort:服務的監聽端口,
dataDir:用於存放內存數據庫快照的文件夾,同時用於集群的myid文件也存在這個文件夾里
(注意:一個配置文件只能包含一個dataDir字樣,即使它被注釋掉了。)
dataLogDir:用於單獨設置transaction log的目錄,transaction log分離可以避免和普通log還有快照的競爭
syncLimit:多少個tickTime內,允許follower同步,如果follower落后太多,則會被丟棄。
syncLimit:多少個tickTime內,允許follower同步,如果follower落后太多,則會被丟棄。
4. 修改ZookeeperB和zookeeperB中的zoo.cfg文件:
在ZookeeperB中clientPort=2281
在ZookeeperC中clientPort=2381
5. 創建myid文件:
ZookeeperA:在ZookeeperA_data/data中創建myid文件,文件內容為1。
ZookeeperB:在ZookeeperB_data/data中創建myid文件,文件內容為2。
ZookeeperC:在ZookeeperC_data/data中創建myid文件,文件內容為3。
6. 依次啟動Zookeeper:
zookeeperA | ZookeeperA/bin/zkServer |
zookeeperB | ZookeeperB/bin/zkServer |
zookeeperC | ZookeeperC/bin/zkServer |
依次啟動zookeeper,啟動第一台zookeeper后,你可以觀察bin下的zookeeper.out可以看到報錯,connection refused,沒有關系,
zookeeper需要等待其他另個節點的加入,全部啟動之后就正常了。
7. 客戶端連接zookeeper:(以ZookeeperA為例)
zookeeperA | ZookeeperA/bin/zkCli -server localhost:2181 [zk: localhost:2181(CONNECTED) 0] ls / [zookeeper] [zk: localhost:2181(CONNECTED) 1] |
configs:保存上傳的配置文件信息
clusterstate.json:集群狀態json
aliases:別名json
live_node:當solr服務器啟動的時候,會注冊到這里
overseer:保存shard信息
overseer_elect:節點選舉
collections:所有的collection
-----------------------------------------------------------------------------------------------------------------------------------------------
TomCat安裝及配置
-----------------------------------------------------------------------------------------------------------------------------------------------
在D:\appservers\apache-tomcat-7.0.20\apache-tomcat-7.0.20-test-solrcloud目錄中,創建如下目錄:
apache-tomcat-7.0.20-solrcloudA|apache-tomcat-7.0.20-solrcloudB|apache-tomcat-7.0.20-solrcloudC

1.創建solr.xml文件
在<Tomcat.home>/conf/catalina/localhost目錄下創建solr文件,文件內容為:
<?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" />
apache-tomcat-7.0.20-solrcloudC:
<Server port="9005" shutdown="SHUTDOWN">
<Connector port="9080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="9443" />
<Connector port="9009" protocol="AJP/1.3" redirectPort="9443" />
3.分別啟動這3個tomcat,測試是否能成功啟動。
-------------------------------------------------------------------------------------------------------------------------------------------------
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
參考:
附件列表