本文采用zookeeper-3.4.6、jdk1.7、solr4.10、tomcat7进行配置
在/home下建立solrcloud文件夹存放相关文件
一、zookeeper的安装
1、下载zookeeper 解压至/home/solrcloud下,重命名为:zk_server_1
2、复制/home/solrcloud/zk_server_1/conf/zoo_sample.cfg 重命名为zoo.cfg 具体配置如下,ip改为自己本机的
# 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/solrcloud/zk_server_1/data
#dataLogDir=/home/solrcloud/zk_server_1/logs
# the port at which the clients will connect
clientPort=2181
server.1=192.168.56.101:2888:3888
server.2=192.168.56.101:2889:3889
server.3=192.168.56.101:2890:3890
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# 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
3、在/home/solrcloud/zk_server_1/下创建data目录,data目录下创建文件myid,写入数字1
4、复制zk_server_1分别为/zk_server_2、/zk_server_3,修改myid文件内部数字为2、3,修改配置文件dataDir的路径,修改clientPort分别为2182、2183
二、tomcat中部署solr
1、把tomcat压缩包解压到solrCloud目录下,重命名为tomcat_server_1。把solr/example/目录下的solr文件夹复制到solrCloud目录下,重命名为solr_home_1
修改solr.xml,同样ip配置本机ip,hostport为tomcat端口号
<?xml version="1.0" encoding="UTF-8" ?>
<solr>
<solrcloud>
<str name="host">192.168.56.101</str>
<int name="hostPort">8080</int>
<str name="hostContext">${hostContext:solr}</str>
<int name="zkClientTimeout">${zkClientTimeout:30000}</int>
<bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>
</solrcloud>
<shardHandlerFactory name="shardHandlerFactory"
class="HttpShardHandlerFactory">
<int name="socketTimeout">${socketTimeout:0}</int>
<int name="connTimeout">${connTimeout:0}</int>
</shardHandlerFactory>
</solr>
2、 把example\webapps\solr.war复制到tomcat-server_1/webapps目录下
在tomcat/bin目录下的catalina.sh 中增加如下内容
JAVA_OPTS="-Dsolr.solr.home=/home/solrcloud/solr_home_1-Dbootstrap_confdir=/home/solrcloud/solr_home_1/collection1/conf-Dcollection.configName=myconf -DzkHost=192.168.56.101:2181,192.168.56.101:2182,192.168.56.101:2183-DnumShards=2"
l -Dsolr.solr.home:指定了solrHome地址
l -Dbootstrap_confdir:solr的配置文件地址,它会把配置文件信息传给zookeepr由zookeeper统一管理
l -Dcollection.configName: 设置上传的配置文件的存储目录名
l -DzkHost:指定zookeeper集群
l -DnumShards: 分片数,即设置分布情况
3、将tomcat_server_1 复制两份,分别为tomcat_server_2、tomcat_server_3,同一台机器上需修改端口
4、tomcat_server_2、tomcat_server_3的catalina.sh 修改如下
JAVA_OPTS="-Dsolr.solr.home=/home/solrcloud/solr_home_2 -DzkHost=192.168.56.101:2181,192.168.56.101:2182,192.168.56.101:2183
5、solr_home_1复制两份分别为solr_home2; solr_home_3 修改solr.xml中的端口号分别为 tomcat_server_2; tomcat_server_3的端口号
在zookeeper集群启动的情况下,先启动tomcat_server_1 再启动其它tomcat。启动成功访问http://localhost:8080/solr/#/~cloud,看到如下信息则配置成功