本文叙述组建SolrCloud过程(Zookeeper 的搭建请参考 http://blog.csdn.net/u011523533/article/details/48626199)
软件准备:solr-4.5.1.zip 、apache-tomcat-8.0.26.tar.gz
搭建环境:虚拟机中的 centos 7 64位
一、solr + tomcat 的安装
1.在centos 7中解压apache-tomcat-8.0.26.tar.gz
tar -zxvf apache-tomcat-8.0.26.tar.gz
2.在windos下解压solr-4.5.1.zip
3.在solr-4.5.1\example\webapps 下找到 solr.war 包
4.wondows下将solr.war后缀名修改为.zip并解压
5.在刚解压的(solr.war)文件夹中创建solr_home文件夹并将将solr-4.5.1\example 下的 solr文件夹复制到该文件夹中
6.将solr-4.5.1\example\lib\ext 下的所有jar包复制到刚解压的(solr.war)文件夹的WEB-INF/lib中
7.在刚解压的(solr.war)文件夹WEB-INF中新建classes文件夹,并将solr-4.5.1\example\resources下的log4j.properties复制到该classes文件夹中
8.在刚解压的(solr.war)文件夹重新打包成.war文件
9.将solr.war文件上传到tomcat的webapps下,并启动tomcat,启动后停止tomcat(解压war包作用)
10.进入tomcat下的webapps/solr-4.5.1/WEB-INF 修改web.xml文件
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/home/hadoop/tomcats/tomcat3/webapps/solr-4.5.1/solr_home</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
注:<env-entry-value>为第5步创建的solr_home的路劲
11.到此配置已完成,启动tomcat即可访问Solr
注:参考文章 http://eksliang.iteye.com/blog/2096478
二、组建SolrCloud
前提:已安装好Zookeeper
我的Zookeeper配置文件zoo.cfg内容如下
第一个节点:
tickTime=2000
initLimit=5
syncLimit=2
clientPort=2181
server.0=127.0.0.1:8880:7770
server.1=127.0.0.1:8881:7771
server.2=127.0.0.1:8882:7772
第二个节点:
tickTime=2000
initLimit=5
syncLimit=2
clientPort=2182
server.0=127.0.0.1:8880:7770
server.1=127.0.0.1:8881:7771
server.2=127.0.0.1:8882:7772
第三个节点:
tickTime=2000
initLimit=5
syncLimit=2
clientPort=2183
server.0=127.0.0.1:8880:7770
server.1=127.0.0.1:8881:7771
server.2=127.0.0.1:8882:7772
1.创建4个tomcat服务器,目录如下
tomcat0 tomcat1tomcat2tomcat3
2.修改各tomcat端口的监听端口
如:进入tomcat1/conf 修改server.xml文件
<Server <span style="color:#ff0000;">port="8105"</span> shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
This connector uses the NIO implementation that requires the JSSE
style configuration. When using the APR/native implementation, the
OpenSSL style configuration is required as described in the APR/native
documentation -->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
3.在4个Tomcat服务器中安装solr(请参考第一步)
4..进入${tomcat_home}/bin/目录修改catalina.sh,在第一行加入
tomcat0 第一行加入:
JAVA_OPTS="$JAVA_OPTS -DzkHost=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
-Dbootstrap_confdir=/home/hadoop/tomcats/tomcat0/webapps/solr-4.5.1/solr_home/collection1/conf
-Dcollection.configName=myconf -DnumShards=3"
其余tomcat第一行加入:
JAVA_OPTS="$JAVA_OPTS -DzkHost=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183 -DnumShards=3"
注:-DzkHost 属性的内容为Zookeeper配置文件中的服务器地址内容,其中2181等对应Zookeeper中的clientPort属性
5.修改各tomcat中solr的监听端口
如:tomcat1
进入tomcat1/webapps/solr-4.5.1/solr_home 修改solr.xml文件为
<solr>
<solrcloud>
<str name="host">${host:}</str>
<int name="hostPort">${jetty.port:8081}</int>
<str name="hostContext">${hostContext:solr}</str>
<int name="zkClientTimeout">${zkClientTimeout:15000}</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>
hostPort对应tomcat端口
6.依次启动Zookeeper、tomcat
7.访问solr
注:参考http://www.tuicool.com/articles/NNjAFr
至此,SolrCloud 安装配置完毕