tomcat solrcloud zookeeper外部部署
以前写的文章solrcloud在tomcat下安装(三),zookeeper集成在tomcat中,耦合度太高,不利于扩展。每一次重启tomcat,就相当于重启zookeeper了一遍,造成zookeeper集群不稳定。现在就来谈谈zookeeper外部部署,tomcat注册到zookeeper上,实现solrcloud集群。
前期规划:3台机器,对应的ip为10.1.22.46,10.1.22.47,10.1.22.48.在这三台机器上分别安装zookeeper和tomcat。
一准备相关软件
1.首先下载solr4.3.1:http://www.apache.org/dyn/closer.cgi/lucene/solr/4.3.1下载solr4.3.1
2.下载tomcat7.0.42:http://tomcat.apache.org/download-70.cgi#7.0.42
3.下载zookeeper 3.4.5 版本:http://zookeeper.apache.org/releases.html#download
4.解压缩solr4.3.1,tomcat7.0.42,zookeeper 3.4.5.
二.安装zookeeper集群
在zookeeper解压缩目录下的conf目录把zoo_sample.cfg文件拷贝一份,更名为zoo.cfg.修改其内容,修改dataDir为你的目录,在增加server配置信息。
# 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/develop/xq/zookeeper/data/ # the port at which the clients will connect clientPort=2181 # # 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=10.1.22.46:2879:3879 server.2=10.1.22.48:2879:3879 server.3=10.1.22.47:2879:3879 |
在/home/develop/xq/zookeeper/data/目录新建myid文件,内容为1。
sudo sh -c 'echo "1" >> myid' |
以上为10.1.22.46的机器配置。
将zoo.cfg拷贝到10.1.22.47机器zookeeper解压缩目录下的conf目录下,/home/develop/xq/zookeeper/data/目录新建myid文件,内容为2.
将zoo.cfg拷贝到10.1.22.48机器zookeeper解压缩目录下的conf目录下,/home/develop/xq/zookeeper/data/目录新建myid文件,内容为3.
进入10.1.22.46机器zookeeper解压缩目录下的bin目录下,运行以下命令。
sh zkServer.sh start; |
在zookeeper解压缩目录下会生成zookeeper.out文件。可以查看zookeeper启动是否正常。
用同样的方法启动10.1.22.47,10.1.22.48的zookeeper。
用一下命令可以查看,当前zookeeper的状态。
-bash-3.2$ sh zkServer.sh status; JMX enabled by default Using config: /home/develop/xq/zookeeper/bin/../conf/zoo.cfg Mode: leader |
三.solrcloud集群搭建
1.解压缩solr4.3.1:
unzip solr-4.3.1.zip |
2.解压缩solr.war至tomcat/webapps下
unzip solr-4.3.1/example/webapps/solr.war -d tomcat/webapps/solr |
3.拷贝solr-4.3.1/example/lib/ext/下所有jar包至tomcat/webapps/solr/WEB-INF/lib/下,将solr-4.3.1/example/resources/log4j.properties拷贝到tomcat/webapps/solr/WEB-INF/classes下
cp solr-4.3.1/example/lib/ext/* tomcat/webapps/solr/WEB-INF/lib/ mdkir -p tomcat/webapps/solr/WEB-INF/classes/ cp solr-4.3.1/example/resources/log4j.properties tomcat/webapps/solr/WEB-INF/classes |
4.在任意一台机器上(10.1.22.46)新建SolrCloud配置文件目录:/home/develop/xq/solrcloud/config-files,将solr-4.3.1/example/solr/collection1/conf 目录拷贝到config-files目录下。
cp -r /home/develop/xq/solr-4.3.1/example/solr/collection1/conf/* /home/develop/xq/solrcloud/config-files |
在任意一台机器上(10.1.22.46)新建Solr Zk CLI库文件目录:/home/develop/xq/solrcloud/solr-lib,将第三步tomcat/webapps/solr/WEB-INF/lib/目录文件拷贝过来。
cp -r /home/develop/xq/tomcat/webapps/solr/WEB-INF/lib/* /home/develop/xq/solrcloud/solr-lib |
将配置文件上传到ZooKeeper中
java -classpath .:/home/develop/xq/solrcloud/solr-lib/* org.apache.solr.cloud.ZkCLI -cmd upconfig -zkhost 10.1.22.47:2181,10.1.22.48:2181,10.1.22.46:2181 -confdir /home/develop/xq/solrcloud/config-files/ -confname myconf |
备注:更新配置文件也是上面的命令。
将上传到ZooKeeper中配置文件与Collection相关联
java -classpath .:/home/develop/xq/solrcloud/solr-lib/* org.apache.solr.cloud.ZkCLI -cmd linkconfig -collection mycollection -confname myconf -zkhost 10.1.22.46:2181,10.1.22.47:2181,10.1.22.48:2181 |
关于org.apache.solr.cloud.ZkCLI类可查看solr-core-4.3.1.jar。
若要删除配置文件,可将/home/develop/xq/zookeeper/data/version-2/目录下所有文件删除。
运行以上命令,会生成zookeeper.out文件,可以查看命令是否运行成功。
运行zkCli.sh,查看配置文件是否上传成功。
-bash-3.2$ sh /home/develop/xq/zookeeper/bin/zkCli.sh ; |
查看配置文件
[zk: localhost:2181(CONNECTED) 0] ls /configs/myconf [admin-extra.menu-top.html, currency.xml, protwords.txt, mapping-FoldToASCII.txt, solrconfig.xml, lang, stopwords.txt, spellings.txt, mapping-ISOLatin1Accent.txt, admin-extra.html, xslt, solrconfig.xml_bak, synonyms.txt, scripts.conf, update-script.js, velocity, elevate.xml, admin-extra.menu-bottom.html, stopwords_en.txt, schema.xml] |
5.新建solrhome/solr目录,作为索引存储目录。创建solr.xml文件,作为solrcloud配置文件。
<?xml version="1.0" encoding="UTF-8" ?> <solr persistent="true"> <cores host="10.1.22.46" adminPath="/admin/cores" zkClientTimeout="${zkClientTimeout:15000}" hostPort="8080" hostContext="${hostContext:solr}"> </cores> </solr> |
6.修改tomcat的bin目录下的catalina.sh,加入以下命令
export JAVA_OPTS="-DzkHost=10.1.22.46:2181,10.1.22.48:2181,10.1.22.47:2181" |
7.修改tomcat/webapps/solr/WEB-INF/web.xml文件。增加solr/home配置。
<env-entry> <env-entry-name>solr/home</env-entry-name> <env-entry-value>/home/develop/xq/solrhome/solr</env-entry-value> <env-entry-type>java.lang.String</env-entry-type> </env-entry> |
按照1,2,3,5,6,7步骤,分别在别的两台机器上配置tomcat。注意solr.xml的host配置成本机ip。
分别启动tomcat。
在浏览器中输入http://10.1.22.47:8080/solr/,会出现以下错误,是由于没有创建collection和core的原因。
There are no SolrCores running.
Using the Solr Admin UI currently requires at least one SolrCore. |
在浏览器中输入以下命令进行创建collection和core。
http://10.1.22.46:8080/solr/admin/collections?action=create&name=mycollection&numShards=3&replicationFactor=1&maxShardsPerNode=3 |
注意,用create和CREATE都行,不区分大小写。以下删除同上。
删除collection和core:
http://10.1.22.46:8080/solr/admin/collections?action=delete&name=mycollection&numShards=3&replicationFactor=1&maxShardsPerNode=3 |
numShards:默认为1.分片数。
replicationFactor:每个分片的复本数
maxShardsPerNode:每个Solr服务器节点上最大分片数(Solr 4.2新增)
注意:一个机器上的分片数<=maxShardsPerNode.即:numShards*replicationFactor<=maxShardsPerNode.
若不符合以上规则,创建的时候会报错。
至此,tomcat ,solrcloud ,zookeeper外部部署完成。
本文固定链接: http://www.chepoo.com/tomcat-solrcloud-zookeeper-external-deployment.html | IT技术精华网
java -classpath .:/usr/local/solrcloud/solr-lib/* org.apache.solr.cloud.ZkCLI -cmd upconfig -zkhost 107.167.80.43:2181,173.254.246.118:2181,23.239.194.133:2181 -confdir /usr/local/solrcloud/config-files/ -confname myconf
出错
log4j:WARN No appenders could be found for logger (org.apache.zookeeper.ZooKeeper).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
这是什么原因?
2014-04-06 上午 8:58应该是没有发现log4j配置文件,
2014-04-08 上午 7:53将tomcat/webapps/solr/WEB-INF/classes/log4j.properties拷贝到/home/develop/xq/solrcloud/solr-lib/试试。
http://192.168.197.129:8080/solr/admin/collections?action=create&name=mycollection&numShards=2&replicationFactor=1&maxShardsPerNode=2
执行这部分报错
2014-06-11 上午 11:47Solr instance is not running in SolrCloud mode.
这是为什么求教
已找到问题原因
2014-06-13 下午 7:37不过在浏览器中输入命令进行创建collection和core时日志中有报错
199480 [http-8080-5] ERROR org.apache.solr.servlet.SolrDispatchFilter ?.null:org.apache.solr.common.SolrException
at org.apache.solr.handler.admin.CollectionsHandler.handleResponse(CollectionsHandler.java:248)
at org.apache.solr.handler.admin.CollectionsHandler.handleResponse(CollectionsHandler.java:233)
at org.apache.solr.handler.admin.CollectionsHandler.handleCreateAction(CollectionsHandler.java:368)
at org.apache.solr.handler.admin.CollectionsHandler.handleRequestBody(CollectionsHandler.java:141)
at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:135)
at org.apache.solr.servlet.SolrDispatchFilter.handleAdminRequest(SolrDispatchFilter.java:720)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:265)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:205)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662
我也返回这个结果 是因为什么啊 求指教
2015-01-23 下午 5:02