操做系統:Ubuntu html
Solr:solr-4.7.2.tgz java
Tomcat:apache-tomcat-7.0.50.tar.gz node
Zookeeper:zookeeper-3.4.6.tar.gz web
三臺機器ip:192.168.239.135 shell
192.168.239.136 apache
192.168.239.137 bootstrap
3個tomcat,3個zookeeper tomcat
/home/sun/solrcloud app
--tomcat //tomcat目錄 curl
--solrhome //solrhome
--lib
--solr-lib //zkcli 須要的jar包
--config //solr配置文件
--zookeeper-3.4.6 //zookeeper目錄
--solr-4.7.2 //solr解壓目錄
--data
--zookeeper
--data //zk 數據存放目錄
1. 配置etc/hosts,若是都用下面都用ip,能夠不配置
2. 將zookeeper-3.4.6.tar.gz, apache-tomcat-7.0.50.tar.gz, solr-4.7.2.tgz,解壓到/home/sun/solrcloud,解壓後apache-tomcat-7.0.50被重命名爲tomcat
3. Zookeeper配置
1)修改配置文件
cp /home/sun/solrcloud/zookeeper-3.4.6/conf/zoo_sample.cfg zoo.cfg
vi /home/sun/solrcloud/zookeeper-3.4.6/conf/zoo.cfg
The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/home/sun/solrcloud/data/zookeeper/data # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1 server.1=192.168.239.135:2888:3888 server.2=192.168.239.136:2888:3888 server.3=192.168.239.137:2888:3888
3) 每一個zookeeper建立id
135:cat 1>/home/sun/solrcloud/data/zookeeper/data/myid
136: cat 2>/home/sun/solrcloud/data/zookeeper/data/myid
137: cat 3>/home/sun/solrcloud/data/zookeeper/data/myid
4)啓動zookeeper
zookeeper-3.4.6/bin/zkServer.sh start
5)驗證zookeeper狀態
zookeeper-3.4.6/bin/zkServer.sh status
4. Solr配置
1)將solr部署到tomcat
cp /home/sun/solrcloud/solr-4.7.2/example/webapps/solr.war /home/sun/solrcloud/tomcat/webapps/solr/ jar –xvf /home/sun/solrcloud/tomcat/webapps/solr.war rm –f /home/sun/solrcloud/tomcat/webapps/solr.war cp /home/sun/solrcloud/solr-4.7.2/example/lib/ext/* /home/sun/solrcloud/tomcat/webapps/solr/WEB-INF/lib/ cp /home/sun/solrcloud/solr-4.7.2/example/resources/log4j.properties /home/sun/solrcloud/tomcat/lib/
2)設置solrcloud配置文件,ZkCLI使用jar包
cp /home/sun/solrcloud/tomcat/webapps/solr/WEB-INF/lib/* /home/sun/solrcloud/lib/solr-lib/ cp -r /home/sun/solrcloud/solr-4.7.2/example/solr/collections/conf /home/sun/solrcloud/lib/config3) 經過 bootstrap 設置 solrhome
java -classpath .:/home/sun/solrcloud/lib/solr-lib/* org.apache.solr.cloud.ZkCLI -zkhost 192.168.239.135:2181,192.168.239.136:2181,192.168.239.137:2181 -cmd bootstrap -solrhome /home/sun/solrcloud/solrhome
4)上傳配置文件
java -classpath .:/home/sun/solrcloud/lib/solr-lib/* org.apache.solr.cloud.ZkCLI -cmd upconfig -zkhost 192.168.239.135:2181,192.168.239.136:2181,192.168.239.137:2181 -confdir /home/sun/solrcloud/lib/config/ -confname myconf
java -classpath .:/home/sun/solrcloud/lib/solr-lib/* org.apache.solr.cloud.ZkCLI -zkhost 192.168.239.135:2181,192.168.239.136:2181,192.168.239.137:2181 -cmd linkconfig -collection mycollection -confname myconf
6)tomcat設置
catalina.sh添加這句:
JAVA_OPTS="-Dsolr.solr.home=/home/sun/solrcloud/solrhome -DzkHost=192.168.239.135:2181,192.168.239.136:2181,192.168.239.137:2181"
<?xml version="1.0" encoding="UTF-8" ?> <solr persistent="true" sharedLib="lib"> <cores adminPath="/admin/cores" zkClientTimeout="20000" hostPort="8080" hostContext="solr"> </cores> </solr>
<?xml version="1.0" encoding="UTF-8"?> <Context docBase="/home/sun/solrcloud/tomcat/webapps/solr" debug="0" crossContext="true"> <Environment name="solr/home" type="java.lang.String" value="/home/sun/solrcloud/solrhome" override="true"/> </Context>
10)啓動tomcat
5.建立collection
1)新建一個三個shard的collection,replicationFactor爲1,即每一個shard一個副本
curl 'http://192.168.239.135:8080/solr/admin/collections?action=CREATE&name=mycollection&numShards=3&replicationFactor=1'
shard1在135,136上創建副本
curl 'http://192.168.239.135:8080/solr/admin/cores?action=CREATE&collection=mycollection&name=mycollection_shard1_replication2&shard=shard1' curl 'http://192.168.239.136:8080/solr/admin/cores?action=CREATE&collection=mycollection&name=mycollection_shard1_replication3&shard=shard1'
shard2,shard3相似
最後結果如圖:
6.建立過程遇到的錯誤
1) curl 'http://192.168.239.135:8080/solr/admin/collections?action=CREATE&name=mycollection&numShards=5&replicationFactor=1'
錯誤信息:
org.apache.solr.common.SolrException:
Cannot create collection mycollection. Value of maxShardsPerNode is 1, and the number of live nodes is 3. This allows a maximum of 3 to be created.
Value of numShards is 5 and value of replicationFactor is 1. This requires 5 shards to be created (higher than the allowed number)
緣由:當前節點數爲3,每一個節點上默認最大shard數爲1,能夠再連接中加入參數,maxShardsPerNode指定每一個節點上的shard數量。2)新建collection報錯
錯誤信息:
解決方法:不執行linkconfig操做。