solr5.2.1+tomcat8.0.23+zookeeper3.4.6 安装与配置
jopen
9年前
提示:
1.本文中用到的solr,tomcat,zk都是相对于此博客最新的版本,solr的每个大版本的变更都无法完美的向前兼容,所以这次的solr5和solr4也是一样。
2.本次是在一台机器上部署3个zk,4个tomcat,所以端口会有相应的改变(俗称伪集群)
- 首先下载相应的包zookeeper-3.5.0-alpha.tar.gz,apache-tomcat-8.0.23.tar.gz,solr-5.2.1.tgz
- 创建目录结构,我是按照如下的目录结构组织,大家可以按照自己的喜好
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
- zk的相应操作
1.进入zk的conf目录
/Users/chaney/solrcloud/service1/zookeeper-3.5.0-alpha/conf
2.新建zoo.cfg并编辑此文件,文件内容如下(或者将zoo_sample.cfg改为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
3.分别启动三台zk
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)
- tomcat相应的操作
1.解压solr(任意目录)
2.将解压后的solr.war拷贝到tomcat的webapps下面
chensideMacBook-Pro:webapps chaney$ cp /Users/chaney/solr/server/webapps/solr.war /Users/chaney/solrcloud/tomcat1/webapps
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/
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>
chensideMacBook-Pro:classes chaney$ cp /Users/chaney/solr/server/resources/log4j.properties /Users/chaney/solrcloud/tomcat1/webapps/solr/WEB-INF/classes/(classes文件夹需要新建)
- solr_home的操作
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/
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.cfg
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分发到各个机器)
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.txt
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
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
来自:http://my.oschina.net/u/942651/blog/485783