1.zookeeper 配置
下载zookeeper; 集群安装配置可参考其他网络文章,
在此我贴出关键信息:
(1)配置文件内容:
# 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=E:/zookeeper-3.4.5/td/zookeeper
# 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=127.0.0.1:2888:3888
server.2=192.168.1.208:2888:3888
server.3=192.168.1.207:2888:3888
在数据文件下创建myid文件,文件内容为1;不同的节点内容不一样,使用server.1后的数字作为myid的文件内容。
2.配置完成后启动三台服务器的zookeeper。
3.上传solr的配置文件到ZooKeeper ensemble中。
solr的配置文件目录可以随意。
(1)上传solr配置文件
java -classpath d:\lib\*;d:\lib\apache-solr-solrj-4.0.0.jar org.apache.solr.cloud.ZkCLI -cmd upconfig -zkhost 127.0.0.1:2181,192.168.1.207:2181,192.168.1.208:2181 -confdir E:\tomcatcluster\collection1\conf -confname testconf
classpath:参数总是报错找不到solrj.jar,干脆把其加入classpath中;lib目录中包含solr.war中的lib包所有内容
zkhost:zookeeper的服务器地址列表;
confdir:solr的配置文件目录,包含schema,solrconfig等文件;
confname:起个名,下面有用
(2)将上传的配置文件和collection联系起来
java -classpath d:\lib\*;d:\lib\apache-solr-solrj-4.0.0.jar org.apache.solr.cloud.ZkCLI -cmd linkconfig -collection europe-collection -confname testconf -zkhost 127.0.0.1:2181,192.168.1.207:2181,192.168.1.208:2181
collection:collection的名字,后面有用,要记住
(3)测试
配置完成后测试下是否正确;
使用zookeeper下面的工具 zkCli; zkCli -server localhost:2181
[zk: localhost:2181(CONNECTED) 1]
ls
/
[configs, collections, zookeeper]
[zk: localhost:2181(CONNECTED) 2]
ls
/configs
[myconf]
[zk: localhost:2181(CONNECTED) 3]
ls
/configs/myconf
[admin-extra.menu-
top
.html, currency.xml, protwords.txt, mapping-FoldToASCII.txt, solrconfig.xml, stopwords.txt, lang, spellings.txt, mapping-ISOLatin1Accent.txt, admin-extra.html, xslt, synonyms.txt, scripts.conf, update-script.js, velocity, elevate.xml, admin-extra.menu-bottom.html, schema.xml]
[zk: localhost:2181(CONNECTED) 4]
ls
/collections
[europe-collection]
[zk: localhost:2181(CONNECTED) 5]
4.tomcat中配置solrcloud
(1)部署三套tomcat,端口分别用7070,8080,9090;
(2)将solr.war包拷贝到webapps下;
(3)在tomcat\conf\Catalina\localhost 增加配置文件solr.xml,内容类似下面内容:
<?xml version="1.0" encoding="utf-8"?>
<Context docBase="E:\tomcatcluster\tomcat6080\webapps\solr.war" debug="0" crossContext="true">
<Environment name="solr/home" type="java.lang.String" value="../solr" override="true"/>
</Context>
(4)在tomcat目录下创建solr目录;并在solr目录中创建文件solr.xml,内容类似下面:
<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="true">
<cores adminPath="/admin/cores" hostPort="7080">
</cores>
</solr>
上面4步是solr的安装。
一直困扰我的问题是zookeeper和tomcat如何交互,原来秘密在这个地方。
打开文件catalina.bat添加类似内容:
set JAVA_OPTS= -Xms512m -Xmx1024m -XX:MaxNewSize=256m -XX:MaxPermSize=128m -Dport=7080 -DhostContext=solr -DzkHost=localhost:2181,192.168.1.207:2181,192.168.1.208:2181
这样就基本搞定了,启动3台tomcat。
5 在solrcloud中创建Collection, Shard(s), Replica(s)
- Number of Shards => 3
- Replicator Factor => 3 (no. of document copies in the collection
(1)创建collection
(2)创建replica(s)
Shard 2 Replica’s
Shard 3 Replica’s
Shard 1 Replica’s -
干完了上面的活,随便访问一个solr
点击左边的cloud,如果看到一个令你兴奋的图估计就成功了。
参考了如下文章:
http://wiki.apache.org/solr/SolrCloud
当你会做的时候,发现他们其实说的挺明白的