一:搭建zookeeper环境 (当前服务器ip:172.16.243.15)
(1)下载zookeeper-3.4.10.tar.gz到目录/home/zookeeper
(2)解压zookeeper-3.4.10.tar.gz
tar -zxvf zookeeper-3.4.10.tar.gz
(3)到/home/zookeeper/zookeeper-3.4.10/conf路径下面
修改 zoo_sample.cfg为zoo.cfg
(4)修改zoo.cfg
修改dataDir=/home/zkdir/zookeeper (注:该目录需要自己创建)
添加
dataLogDir=/home/zkdir/log
server.1=172.16.243.15:2888:3888
server.2=172.16.243.14:2888:3888
server.3=172.16.243.13:2888:3888 (注:端口号2888,3888分别用于仲裁通信和群首选举)
(5)在data目录即 /home/zkdir/zookeeper目录下面创建文件你
内容为相应ip的serverid 例如在172.16.243.15服务器上的内容为1;172.16.243.14服务器上为2
(6)配置环境变量
vim /etc/profile
添加内容
export ZOOKEEPER_HOME=/home/zookeeper/zookeeper-3.4.10
export PATH=$ZOOKEEPER_HOME/bin:$PATH
注: :$PATH 的意义是将变量$ZOOKEEPER_HOME/bin添加到$PATH中
(7)使环境变量生效:source /etc/profile
(8)在两位两台服务器上做同样的配置
注:推荐一种作法 将一台服务器上的文件直接拷贝到两位两台机器上 : scp /home/zookeeper root@172.16.243.15:/home
(9)启动zookeeper
(10)查看zookeeper状态(ip:172.16.243.15)
[root@iZbp18ie9kfhwdt5s8sxyzZ bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: leader
二:搭建solr集群
(1)将apache-tomcat-8.0.47.tar.gz放到/home/solr/tomcat下面
将apache-tomcat-8.0.47.tar.gz解压在当前目录下面,为了防止端口冲突需要修改当前目录下面的tomcat的一些配置
vi server.xlm
<Server port="8815" 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="8881" 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="8819" protocol="AJP/1.3" redirectPort="8443" />
端口修改以上三处即可。
(2)将 solr-5.5.0.tgz压缩包放置到/home/solr下面
解压 solr-5.5.0.tgz到当前目录
(3)将/home/solr/solr-5.5.0/server\solr-webapp 下的webapp目录拷贝到/home/solr/tomcat/apache-tomcat-8.0.47/webapps下面
重新命名为solr
(4)将 /home/solr/solr-5.5.0/server/lib和/home/solr/solr-5.5.0/server/lib/ext下面的jar包拷贝到
/home/solr/tomcat/apache-tomcat-8.0.47/webapps/solr/WEB-INF/lib下面
(5)创建文件目录/home/solr/solr_home
将/home/solr/solr-5.5.0/server/solr下面的文件复制到/home/solr/solr_home下面
(6)修改/home/solr/tomcat/apache-tomcat-8.0.47/webapps/solr/WEB-INF/web.xml内容
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/home/solr/solr_home</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
(7)修改/home/solr/solr_home/solr.xml文件的内容
<str name="host">172.16.243.15</str>
<int name="hostPort">8881</int> --该端口要和tomcat的端口保持一致
<str name="hostContext">${hostContext:solr}</str>
(8)修改/home/solr/tomcat/apache-tomcat-8.0.47/bin/catalina.sh的内容
在267行添加一下内容JAVA_OPTS="-DzkHost=172.16.243.15:2181,172.16.243.14:2181,172.16.243.13:2181"
(9)将配置信息上传到zookeeper
将/home/solr/solr_home/configsets/sample_techproducts_configs文件夹重命名名为goodsConfig
将goodsConfig文件拷贝到/home/solr/solr_home
执行命令 sh /home/solr/solr-5.5.0/server/scripts/cloud-scripts/zkcli.sh -zkhost 172.16.243.15:2181,172.16.243.14:2181,172.16.243.13:2181 -cmd upconfig -confdir /home/solr/solr_home/goodsConfig/conf -confname goodsconf
绑定sh /home/solr/solr-5.5.0/server/scripts/cloud-scripts/zkcli.sh -zkhost 172.16.243.15:2181,172.16.243.14:2181,172.16.243.13:2181 -cmd linkconfig -collection goodsCollection -confname goodsconf
(10)查看solr页面