1.創建solrcloud文件夾 html
chensideMacBook-Pro:solrcloud chaney$ pwd /Users/chaney/solrcloud
2.solrcloud下面目錄結構爲 java
chensideMacBook-Pro:solrcloud chaney$ ls service1 service2 service3 tomcat1 tomcat2 tomcat3 tomcat4
3.service中是zk的目錄,三個目錄結構同樣,目錄結構爲 web
chensideMacBook-Pro:service1 chaney$ ls data datalog logs zookeeper-3.5.0-alpha
1.進入zk的conf目錄
shell
/Users/chaney/solrcloud/service1/zookeeper-3.5.0-alpha/conf
2.在data目錄新建myid文件,並寫入值 apache
chensideMacBook-Pro:data chaney$ echo 1 > myid(每一個zk數字不同,根據本身喜愛配置,在下一步配置zoo.cfg會用到)
initLimit=5 syncLimit=2 clientPort=2181(因爲在同一臺機器上面部署因此每一個service的clientPort不能同樣) tickTime=2000 dataDir=/Users/chaney/solrcloud/service1/data dataLogDir=/Users/chaney/solrcloud/service1/datalog server.1=localhost:2888:3888(此處也同樣,端口號不能同樣) server.2=localhost:2889:3889 server.3=localhost:2890:3890
chensideMacBook-Pro:solrcloud chaney$ sh service2/zookeeper-3.5.0-alpha/bin/zkServer.sh start(啓動) Using config: /Users/chaney/solrcloud/service2/zookeeper-3.5.0-alpha/bin/../conf/zoo.cfg -n Starting zookeeper ... STARTED chensideMacBook-Pro:solrcloud chaney$ sh service2/zookeeper-3.5.0-alpha/bin/zkServer.sh status(查看狀態) JMX enabled by default Using config: /Users/chaney/solrcloud/service2/zookeeper-3.5.0-alpha/bin/../conf/zoo.cfg Client port found: 2182(跟service1不同) Mode: leader(說明service2是leader)
1.解壓solr(任意目錄) json
2.將解壓後的solr.war拷貝到tomcat的webapps下面 bootstrap
chensideMacBook-Pro:webapps chaney$ cp /Users/chaney/solr/server/webapps/solr.war /Users/chaney/solrcloud/tomcat1/webapps
3.解壓solr.war tomcat
4.將solr中的jar包拷貝到tomcat下面 app
chensideMacBook-Pro:WEB-INF chaney$ cp -r /Users/chaney/solr/server/lib/ext/* /Users/chaney/solrcloud/tomcat1/webapps/solr/WEB-INF/lib/5.編輯tomcat中solr項目的web.xml文件, 找到env-entry節點,編輯爲如下內容
chensideMacBook-Pro:WEB-INF chaney$ pwd /Users/chaney/solrcloud/tomcat1/webapps/solr/WEB-INF chensideMacBook-Pro:WEB-INF chaney$ vi web.xml
<env-entry> <env-entry-name>solr/home</env-entry-name> <env-entry-value>/Users/chaney/solr_home</env-entry-value>(solr的用戶目錄,用於存儲索引等,接下來會介紹,每一個tomcat須要不同的路徑) <env-entry-type>java.lang.String</env-entry-type> </env-entry>6.將solr解壓中的log4j文件拷貝到tomcat中(solr5將日誌抽離了出來,上面的第4步也包含log的一些jar)
chensideMacBook-Pro:classes chaney$ cp /Users/chaney/solr/server/resources/log4j.properties /Users/chaney/solrcloud/tomcat1/webapps/solr/WEB-INF/classes/(classes文件夾須要新建)
1.針對四個tomcat(每個tomcat跑一個solr)新建四個solr_home
webapp
drwxr-xr-x 9 chaney staff 306 7 29 17:27 solr_home/ drwxr-xr-x 8 chaney staff 272 7 29 17:27 solr_home2/ drwxr-xr-x 9 chaney staff 306 7 29 17:27 solr_home3/ drwxr-xr-x 8 chaney staff 272 7 29 17:27 solr_home4/2.將解壓後的solr中文件拷貝到solr_home
cp -r /Users/chaney/solr/server/solr/* /Users/chaney/solr_home/
拷貝後的內容以下:
chensideMacBook-Pro:solr_home2 chaney$ ll total 24 drwxr-xr-x 8 chaney staff 272 7 29 17:27 ./ drwxr-xr-x@ 47 chaney staff 1598 7 30 11:20 ../ -rw-r--r--@ 1 chaney staff 3037 7 29 13:22 README.txt drwxr-xr-x@ 5 chaney staff 170 7 29 13:22 configsets/ -rw-r--r--@ 1 chaney staff 1887 7 29 13:26 solr.xml -rw-r--r--@ 1 chaney staff 501 7 29 13:22 zoo.cfg3.修改solr.xml
chensideMacBook-Pro:solr_home chaney$ pwd /Users/chaney/solr_home chensideMacBook-Pro:solr_home chaney$ vi solr.xml改爲以下內容:
<solr> <solrcloud> <str name="host">${host:}</str> <int name="hostPort">${jetty.port:9091}</int>(修改爲你當前的tomcat的運行端口,每一個solr_home對應的tomcat端口不同,固然是在僞集羣的狀況下,若是你是多臺機器的話請忽略) <str name="hostContext">${hostContext:solr}</str> <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool> <int name="zkClientTimeout">${zkClientTimeout:30000}</int> <int name="distribUpdateSoTimeout">${distribUpdateSoTimeout:600000}</int> <int name="distribUpdateConnTimeout">${distribUpdateConnTimeout:60000}</int> </solrcloud> <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory"> <int name="socketTimeout">${socketTimeout:600000}</int> <int name="connTimeout">${connTimeout:60000}</int> </shardHandlerFactory> </solr>
4.新建配置文件目錄(用於zk的集羣配置管理),我是直接在solr_home中新建一個collection1文件夾,以下
chensideMacBook-Pro:collection1 chaney$ pwd /Users/chaney/solr_home/collection1(此文件夾只須要建一個,不須要在每一個機器上建,他會經過zk分發到各個機器)5.拷貝solr解壓後的配置文件到collection1中
chensideMacBook-Pro:collection1 chaney$ cp -r /Users/chaney/solr/server/solr/configsets/basic_configs/* /Users/chaney/solr_home/collection1/
拷貝後的內容以下:
chensideMacBook-Pro:collection1 chaney$ ls conf chensideMacBook-Pro:collection1 chaney$ cd conf/ chensideMacBook-Pro:conf chaney$ ls _rest_managed.json lang schema.xml stopwords.txt currency.xml protwords.txt solrconfig.xml synonyms.txt6.修改tomcat的文件catalina.sh文件
chensideMacBook-Pro:bin chaney$ pwd /Users/chaney/solrcloud/tomcat1/bin chensideMacBook-Pro:bin chaney$ vi catalina.sh加入以下內容:
JAVA_OPTS="$JAVA_OPTS -DzkHost=localhost:2181,localhost:2182,localhost:2183 -Dbootstrap_confdir=/Users/chaney/solr_home/collection1/conf -Dcollection.configName=myconf在其餘的tomcat中只須要加入如下內容:
JAVA_OPTS="$JAVA_OPTS -DzkHost=localhost:2181,localhost:2182,localhost:2183
1.依次啓動zk和tomcat,開始啓動zk的時候會有各類報錯,不要緊,由於zk是2n+1的機制,當你依次啓動好了就能夠了。
2.訪問http://localhost:9091/solr/,按照正常狀況來講應該出現如下的界面 3.建立一個solr的collection
http://localhost:9091/solr/admin/collections?action=CREATE&name=eSearch&numShards=3&replicationFactor=3&maxShardsPerNode=3&collection.configName=myconf
按照正常狀況應該出現如下界面
cloud中tree目錄以下圖
http://localhost:9092/solr/admin/collections?action=DELETE&name=eSearch