1.建立solrcloud文件夹
chensideMacBook-Pro:solrcloud chaney$ pwd /Users/chaney/solrcloud
2.solrcloud下面目录结构为
chensideMacBook-Pro:solrcloud chaney$ ls service1 service2 service3 tomcat1 tomcat2 tomcat3 tomcat4
3.service中是zk的目录,三个目录结构一样,目录结构为
chensideMacBook-Pro:service1 chaney$ ls data datalog logs zookeeper-3.5.0-alpha
1.进入zk的conf目录
/Users/chaney/solrcloud/service1/zookeeper-3.5.0-alpha/conf
2.在data目录新建myid文件,并写入值
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(任意目录)
2.将解压后的solr.war拷贝到tomcat的webapps下面
chensideMacBook-Pro:webapps chaney$ cp /Users/chaney/solr/server/webapps/solr.war /Users/chaney/solrcloud/tomcat1/webapps
3.解压solr.war
4.将solr中的jar包拷贝到tomcat下面
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
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