1.安装配置zookeeper
在zookeeper安装目录/conf下 cp zoo_sample.cfg zoo.cfg
Vi zoo.cfg
dataDir={zookeeper工作目录}
clientPort=2181(服务端口)
server.1=hadoop.datanode3.com:2888:9888
server.2=hadoop.datanode5.com:2888:9888
server.3=hadoop.datanode2.com:2888:9888
2.配置主tomcat
JAVA_OPTS="JAVA_OPTS="$JAVA_OPTS -Dcollection.configName=myconf -DzkHost= hadoop.datanode2.com:2181,hadoop.datanode3.com: 2181,hadoop.datanode5.com: 2181 -DnumShards=2"
注:其中DzkHost是用来指定zookeeper服务器的ip和端口。 confdir目录指定所有的索引库都从collection1索引库中同步字段。NumShards表示将索引库分片的数量。
4.配置从tomcat
vim /home/tomcat/bin/catalina.sh 在和上图同样的位置加入
JAVA_OPTS="-DzkHost=hadoop.datanode2.com: 2181,hadoop.datanode3.com: 2181,hadoop.datanode5.com: 2181"
5.配置各个tomcat指向的solr_home下的solr.xml
<solr>
<cores adminPath="/admin/cores" host="${host:}" hostPort="${hostport:1080}" hostContext="${hostContext:solr }" zkHost="${zkHost:hadoop.datanode2.com:2181, hadoop.datanode3.com:2181, hadoop.datanode5.com:2181 }" zkClientTimeout="${zkClientTimeout:15000}" genericCoreNodeNames="${genericCoreNodeNames:true}">
<shardHandlerFactory name="shardHandlerFactory"
>
<int name="socketTimeout">${socketTimeout:0}</int>
<int name="connTimeout">${connTimeout:0}</int>
<str name="urlScheme">${urlScheme:}</str>
</shardHandlerFactory>
<core name="programSerial" instanceDir="programSerial" />
<core name="aspectprogramSerial" instanceDir="aspectprogramSerial" />
</cores>
</solr>
6.分别按顺序启动zookeeper,主tomcat,从tomcat
启动过程中观察日志,主tomcat启动过程后,从tomcat没有及时启动会有错误日志,不影响,因为集群部署中shard节点必须满足一半以上集群才能正常服务
7.访问任一tomcat下solr应用地址,看到如下图所示即成功启动
8.以上分片数据按shard分散在各个solr服务中,可以进一步配置主从服务,保证数据完整性和安全性
Vi solr_home/collection/conf/solrconfig.xml
<requestHandler name="/replication" class="solr.ReplicationHandler" >
<!--
To enable simple master/slave replication, uncomment one of the
sections below, depending on whether this solr instance should be
the "master" or a "slave". If this instance is a "slave" you will
also need to fill in the masterUrl to point to a real machine.
-->
<lst name="master">
<str name="replicateAfter">commit</str>
<str name="replicateAfter">startup</str>
<str name="confFiles">schema.xml,stopwords.txt</str>
</lst>
<!--
<lst name="slave">
<str name="masterUrl">http://your-master-hostname:8983/solr</str>
<str name="pollInterval">00:00:60</str>
</lst>
-->
</requestHandler>