实验说明: 三台虚拟机做solrcloud集群
安装solr前请确保jdk 、tomcat、zookeeper已安装好,否则无法启动
三台虚拟机IP分别为:192.168.12.162 192.168.12.163 192.168.12.164
一、ssh登陆192.168.12.162上执行如下操作:
1.1 下载解压solr包:
1 wget http://archive.apache.org/dist/lucene/solr/4.10.2/solr-4.10.2.zip -P /opt 2 unzip –d /opt/ /opt/ solr-4.10.2.zip
1.2 将原始solr包解压到tomcat项目中:
1 unzip -d /usr/local/apache-tomcat-7.0.57/webapps/solr /opt/solr-4.10.2/example/webapps/solr.war 2 cp -r /opt/solr-4.10.2/example/lib/ext/*.jar /usr/local/apache-tomcat-7.0.57/webapps/solr/WEB-INF/lib/
1.3 创建solr-data、solr-lib 目录和solr-config 目录:
1 mkdir –p /usr/local/solr-data 2 mkdir –p /usr/local/solrcloud/solr-lib 3 mkdir –p /usr/local/solrcloud/config-files
1.4 将solr包中的lib 文件和配置文件拷贝到创建的目录中:
1 cp –r /usr/local/apache-tomcat-7.0.57/webapps/solr/WEB-INF/lib/* /usr/local/solrcloud/solr-lib/ 2 cp –r /opt/solr-4.10.2/example/solr/collection1/conf/* /usr/local/solrcloud/config-files/
1.5 编辑solr home文件:
vim /usr/local/apache-tomcat-7.0.57/conf/Catalina/localhost/solr.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <Context docBase="/usr/local/apache-tomcat-7.0.57/webapps/solr" debug="0" crossContext="true"> 3 <Environment name="solr/home" type="java.lang.String" value="/usr/local/solr-data" override="true"/> 4 </Context>
1.6 编辑solr data文件:
vim /usr/local/solr-data/solr.xml
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <solr persistent="true"> 3 <logging enabled="true"> 4 <watcher size="100" threshold="INFO" /> 5 </logging> 6 <cores defaultCoreName="xjh" adminPath="/admin/cores" host="${host:}" hostPort="8080" hostContext="${hostContext:solr}" zkClientTimeout="${zkClientTimeout:15000}"> 7 </cores> 8 </solr>
1.7 编辑catalina.sh 加入zookeeper集群及solr配置文件目录和名称:
vim /usr/local/apache-tomcat-7.0.57/bin/catalina.sh
1 JAVA_OPTS="-server 2 -Dbootstrap_confdir=/usr/local/solrcloud/config-files 3 -Dcollection.configName=xjh 4 -DzkHost=192.168.12.162:2181,192.168.12.163:2181,192.168.12.164:2181"
1.8 在zookeeper集群中同步配置:
1 java -classpath .:/usr/local/apache-tomcat-7.0.57/webapps/solr/WEB-INF/lib/*:/usr/local/solrcloud/solr-lib/* org.apache.solr.cloud.ZkCLI -cmd upconfig -zkhost 192.168.12.162:2181,192.168.12.163:2181,192.168.12.164:2181 -confdir /usr/local/solrcloud/config-files -confname xjh
1.9 查看配置文件是否同步到zookeeper中:
1 /usr/local/zookeeper/bin/zkCli.sh 2 ls /configs/
1.10 下载安装IK分词器(IKAnalyzer2012FF_u1.jar):
wget https://code.google.com/p/ik-analyzer/downloads/list/IKAnalyzer2012FF_u1.jar –P /usr/local/apache-tomcat-7.0.57/webapps/solr/WEB-INF/lib/
配置/usr/local/solrcloud/config-files/schema.xml文件,我们这里配置从生产环境导入一份。
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
启动tomcat
/usr/local/apache-tomcat-7.0.57/bin/catalina.sh start
浏览器打开http://192.168.12.162:8080/solr
二、 登陆192.168.12.163 和192.168.12.164 上:
192.168.12.163和192.168.12.164中部署步骤和192.168.12.162除1.7步骤以外全部一致
1.7修改为如下内容(不指定配置文件目录和名称,只配置zookeeper集群地址)
1.7 编辑catalina.sh 加入zookeeper集群
vim
/usr/local/apache-tomcat-7.0.57/bin/catalina.sh
1 JAVA_OPTS="-server 2 -DzkHost=192.168.12.162:2181,192.168.12.163:2181,192.168.12.164:2181"
vim
/usr/local/apache-tomcat-7.0.57/bin/catalina.sh