環境搭建
一.zookeeper
參考:http://blog.chinaunix.net/uid-25135004-id-4214399.html
現有4台機器 10.14.2.201 10.14.2.202 10.14.2.203 10.14.2.204 安裝zookeeper集群 在所有機器上進行 1、下載安裝包解壓 tar xvf zookeeper-3.4.5.tar.gz -C /export/ cd /export/ ln -s zookeeper-3.4.5 zookeeper 2、設置環境變量 vim /etc/profile #Set ZooKeeper Enviroment export ZOOKEEPER_HOME=/export/zookeeper export PATH=$PATH:$ZOOKEEPER_HOME/bin 3、加載環境變量 source /etc/profile 4、配置zookeeper cd /export/zookeeper/conf cp zoo_sample.cfg zoo.cfg vim zoo.cfg tickTime=2000 initLimit=10 syncLimit=5 dataDir=/export/zookeeper/data dataLogDir=/export/zookeeper/log clientPort=2181 server.1=10.14.2.201:2888:3888 server.2=10.14.2.202:2888:3888 server.3=10.14.2.203:2888:3888 server.4=10.14.2.204:2888:3888 5、dataDir和日志目錄dataLogDir mkdir -p /export/zookeeper/data mkdir -p /export/zookeeper/log 6、在10.14.2.201上 在dataDir目錄下創建myid文件 echo 1 > /export/zookeeper/data/myid myid中的數字與zoo.cfg中的"server.數字=ip或者域名:port1:port2"相對應, 配置文件中10.14.2.201對應的server.數字是1 所以myid的數字應為1 7、在10.14.2.202上 在dataDir目錄下創建myid文件 echo 2 > /export/zookeeper/data/myid 8、在10.14.2.203上 在dataDir目錄下創建myid文件 echo 3 > /export/zookeeper/data/myid 9、在10.14.2.204上 在dataDir目錄下創建myid文件 echo 4 > /export/zookeeper/data/myid 在所用機器上執行 10、修改權限 chown hadoop.hadoop -R /export/zookeeper/ chown hadoop.hadoop -R /export/zookeeper 11、啟動zookeeper /export/zookeeper/bin/zkServer.sh start 12、觀察zookeeper狀態 1> 10.14.2.201 # /export/zookeeper/bin/zkServer.sh status JMX enabled by default Using config: /export/zookeeper/bin/../conf/zoo.cfg Mode: follower 2> 10.14.2.202 # /export/zookeeper/bin/zkServer.sh status JMX enabled by default Using config: /export/zookeeper/bin/../conf/zoo.cfg Mode: follower 3> 10.14.2.203 # /export/zookeeper/bin/zkServer.sh status JMX enabled by default Using config: /export/zookeeper/bin/../conf/zoo.cfg Mode: leader 4> 10.14.2.204 # /export/zookeeper/bin/zkServer.sh status JMX enabled by default Using config: /export/zookeeper/bin/../conf/zoo.cfg Mode: follower 13、此時zookeeper已安裝並啟動完畢
二.solrCloud
參考:http://lucien-zzy.iteye.com/blog/2002463
1.安裝tomcat,配置端口。部署solr.war,將solr\example\lib\ext下的jar拷貝到solr\WEB-INF\lib下。
2.創建
/home/solr/solrcloud
/home/solr/solrcloud/config-files (放置solr\example\solr\collection1\conf 下的所有文件)
/home/solr/solrcloud/solr-lib (放置solr\WEB-INF\lib下的所有jar包)
3.配置中文分詞器
4.創建solr數據目錄
/home/solr/solr-cores
生成solr.xml,如下:
<?xml version="1.0" encoding="UTF-8" ?> <solr persistent="true"> <logging enabled="true"> <watcher size="100" threshold="INFO" /> </logging> <cores defaultCoreName="collection1" adminPath="/admin/cores" host="${host:}" hostPort="8080" hostContext="${hostContext:solr}" zkClientTimeout="${zkClientTimeout:15000}"> </cores> </solr>
5.創建
tomcat/conf/Catalina
tomcat/conf/Catalina/localhost
並創建solr.xml
<?xml version="1.0" encoding="UTF-8"?> <Context docBase="/soft/apache-tomcat-7.0.37/webapps/solr" debug="0" crossContext="true"> <Environment name="solr/home" type="java.lang.String" value="/home/solr/solr-cores" override="true"/> </Context>
docBase根據實際情況配置;
solr/home為之前創建的目錄:/home/solr/solr-cores
6.修改tomcat/bin/cataina.sh 文件,在最上方加入:JAVA_OPTS="-DzkHost=master:2181,slave1:2181,slave2:2181",或直接使用ip。
將以上配置發布到集群其他機器上。
7.SolrCloud是通過ZooKeeper集群來保證配置文件的變更及時同步到各個節點上,所以,需要將配置文件上傳到ZooKeeper集群中。執行如下操作:
java -classpath .:/home/solr/solrcloud/solr-lib/* org.apache.solr.cloud.ZkCLI -cmd upconfig -zkhost 192.168.91.128:2181,192.168.91.129:2181,192.168.91.130:2181 -confdir /home/solr/solrcloud/config-files/ -confname myconf
-cmd upconfig:上傳配置文件
-confdir:配置文件的目錄
-confname:指定對應的名稱
java -classpath .:/home/solr/solrcloud/solr-lib/* org.apache.solr.cloud.ZkCLI -cmd linkconfig -collection collection1 -confname myconf -zkhost 192.168.91.128:2181,192.168.91.129:2181,192.168.91.130:2181
-cmd linkconfig:為指定collection"綁定"配置文件
-collection
-confname
8.檢查zookeeper的配置信息
zkCli.sh -server ip:port
ls /configs/myconf
ls /live_nodes
9.啟動tomcat,創建collection
curl 'http://192.168.91.128:8080/solr/admin/collections?action=CREATE&name=mycollection&numShards=3&replicationFactor=1'
action:CREATE
name:collection名稱
numShards:分片數量
replicationFactor:副本集數量
也可以通過zk查詢collection的情況:ls /collections/mycollection
-------------------------------
1.ZK CLI
ZooKeeper's Command Line Utility (CLI).
zkcli Parameters
|
Short |
Parameter Usage |
Meaning |
|---|---|---|
|
|
|
CLI Command to be executed: |
|
|
|
ZooKeeper host address. |
|
|
|
For |
|
|
|
For |
|
|
|
Display help text. |
|
|
|
For |
|
|
|
Run ZooKeeper internally by passing the Solr run port; only for clusters on one machine. |
|
|
|
For |
ZooKeeper CLI Examples
Below are some examples of using the zkcli CLI:
Uploading a Configuration Directory
java -classpath example/solr-webapp/WEB-INF/lib/* org.apache.solr.cloud.ZkCLI -cmd upconfig -zkhost 127.0.0.1:9983 -confdir example/solr/collection1/conf -confname conf1 -solrhome example/solr
Put arbitrary data into a new ZK file
java -classpath example/solr-webapp/WEB-INF/lib/* org.apache.solr.cloud.ZkCLI -zkhost 127.0.0.1:9983 -put /data.txt 'some data'
Put a local file into a new ZK file
java -classpath example/solr-webapp/WEB-INF/lib/* org.apache.solr.cloud.ZkCLI -zkhost 127.0.0.1:9983 -putfile /data.txt /some/local/file.txt
Linking a Collection to a Configuration Set
java -classpath example/solr-webapp/webapp/WEB-INF/lib/* org.apache.solr.cloud.ZkCLI -cmd linkconfig -zkhost 127.0.0.1:9983 -collection collection1 -confname conf1 -solrhome example/solr
Bootstrapping All the Configuration Directories in solr.xml
java -classpath example/solr-webapp/webapp/WEB-INF/lib/* org.apache.solr.cloud.ZkCLI -cmd bootstrap -zkhost 127.0.0.1:9983 -solrhome example/solr
Scripts
There are scripts in example/cloud-scripts that handle the classpath and class name for you if you are using Solr out of the box with Jetty. Commands then become:
sh zkcli.sh -cmd linkconfig -zkhost 127.0.0.1:9983 -collection collection1 -confname conf1 -solrhome example/solr
2.Managing collections via the collections API
CREATE---
http://localhost:8983/solr/admin/collections?action=CREATE&name=mycollection&numShards=3&replicationFactor=4
name:collection的名稱
numShards:指定分片數量(slices)
replicationFactor:副本數量
maxShardsPerNode:默認值為1,注意三個數值:numShards、replicationFactor、liveSolrNode,一個正常的solrCloud集群不容許同一個liveSolrNode上部署同一個shard的多個replic,因此當maxShardsPerNode=1時,numShards*replicationFactor>liveSolrNode時,報錯。因此正確時因滿足以下條件:
numShards*replicationFactor<liveSolrNode*maxShardsPerNode
createNodeSet:
collection.configName:指定該collection使用那份config,這份config必須存在於zk中。
DELETE---
http://localhost:8983/solr/admin/collections?action=DELETE&name=mycollection
RELOAD---
http://localhost:8983/solr/admin/collections?action=RELOAD&name=mycollection
SPLIT SHARD---
http://localhost:8983/solr/admin/collections?action=SPLITSHARD&collection=<collection_name>&shard=shardId
3.Creating cores via CoreAdmin
curl 'http://localhost:8983/solr/admin/cores?action=CREATE&name=mycore&collection=collection1&shard=shard2'
-------------------------------
Q1:Multiple schemas in the same SolrCloud ?
java -classpath .:/home/solrcloud/solr-lib/* org.apache.solr.cloud.ZkCLI -cmd upconfig -zkhost 10.200.51.190:2224,10.200.51.192:2224,10.200.51.194:2224 -confdir /home/solrcloud/fox-config-files/ -confname foxconf
指定配置文件,上傳到zk。
curl 'http://10.200.51.194:2223/solr/admin/collections?action=CREATE&name=fox4&numShards=1&replicationFactor=5&collection.configName=foxconf'
為創建的collection指定collection.configName。
