06、Solr实战:solrcloud搭建

一、集群环境

1、 solr-4.10.3;

2、 zookeeper-3.4.6;

3、 apache-tomcat-8.5.12;

4、 jdk1.7;

5、 centos6.4;

二、搭建zookeeper集群

1、 解压缩zookeeper;

tar -zxvf zookeeper-3.4.6.tar.gz -C /opt/modules/solrcloud/

2、 修改zookeeper名称,并且复制三份,命名为zookeeper1/zookeeper2/zookeeper3;

cd /opt/modules/solrcloud
mv zookeeper-3.4.6 zookeeper1
cp -r zookeeper1/ zookeeper2
cp -r zookeeper1/ zookeeper3

3、 zookeeper1、zookeeper2、zookeeper3文件夹下分别创建一个data目录,创建一个myid,分别命名为1,2,3;

mkdir data
cd data/
vi myid
1

4、 修改zookeeper的配置文件,把三个zookeeper1\conf\zoo_sample.cfg分别改为zoo.cfg,分别修改三个参数;

zk2
dataDir=/opt/modules/solrcloud/zookeeper1/data
# the port at which the clients will connect
clientPort=2181
server.1= 192.168.184.3:2881:3881
server.2= 192.168.184.3:2882:3882
server.3= 192.168.184.3:2883:3883

zk2
dataDir=/opt/modules/solrcloud/zookeeper2/data
# the port at which the clients will connect
clientPort=2182
server.1= 192.168.184.3:2881:3881
server.2= 192.168.184.3:2882:3882
server.3= 192.168.184.3:2883:3883

zk3
# example sakes.
dataDir=/opt/modules/solrcloud/zookeeper3/data
# the port at which the clients will connect
clientPort=2183
server.1= 192.168.184.3:2881:3881
server.2= 192.168.184.3:2882:3882
server.3= 192.168.184.3:2883:3883

5、 启动zookeeper;

solrcloud/zookeeper1/bin/zkServer.sh start
solrcloud/zookeeper2/bin/zkServer.sh start
solrcloud/zookeeper3/bin/zkServer.sh start

6、 进入zookeeper客户端;

bin/zkCli.sh

[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper]
[zk: localhost:2181(CONNECTED) 1] ls /zookeeper
[quota]

7、 检查状态;

*

三、构建单个实例

1、 解压缩tomcat,修改名字;

tar -zxvf apache-tomcat-8.5.12.tar.gz -c /opt/modules/solrcloud
mv apache-tomcat-8.5.12 tomcat1

2、 解压缩solr-4.10.3;

tar -zxvf /opt/softwares/solr-4.10.3.tgz -C /opt/modules/

3、 将solr-4.10.3里的solrhome模板拷贝到solrcloud目录下;

cp -r /opt/modules/solr-4.10.3/example/solr /opt/modules/solrcloud/solrhome1

4、 solr和tomcat整合;

(1)把solr解压缩的war包复制到tomcat 的webapp目录下

cp /opt/modules/solr-4.10.3-apache/example/webapps/solr.war  /opt/modules/solrcloud/tomcat1/webapps/

(2)启动tomcat以解压缩solr.war包

(3)关闭tomcat,删除solr.war

rm -rf solr.war

(4)把solr-4.10.3-apache/example/lib/ext目录下的所有的jar包添加到solr工程中

cp -r /opt/modules/solr-4.10.3-apache/example/lib/ext/* /opt/modules/solrcloud/tomcat1/webapps/solr/WEB-INF/lib/

(5)配置webapps/solr/WEB-INF/web.xml文件,确定solrhome位置

<env-entry>
   <env-entry-name>solr/home</env-entry-name>
   <env-entry-value>/opt/modules/solrcloud/solrhome1</env-entry-value>
   <env-entry-type>java.lang.String</env-entry-type>
</env-entry>

(6)启动tomcat

(7)访问http://hadoop01:8080/solr,成功~

*

四、构建solr cloud集群

1、 复制刚刚新建的tomcat1,solrhome1实例,复制三分;

[root@hadoop01 solrcloud]# cp -r solrhome1/ solrhome2
[root@hadoop01 solrcloud]# cp -r solrhome1/ solrhome3
[root@hadoop01 solrcloud]# cp -r solrhome1/ solrhome4
[root@hadoop01 solrcloud]# cp -r tomcat1/ tomcat2
[root@hadoop01 solrcloud]# cp -r tomcat1/ tomcat3
[root@hadoop01 solrcloud]# cp -r tomcat1/ tomcat4

2、 修改tomcat的端口号,修改solrcloud/tomcat1/conf/server.xml,针对四个tomcat分别修改三个端口号,依次+0,+1,+2,+3(因为是在一台主机部署四个tomcat运用,所以修改端口号;如果四台服务器,则不用修改);

*

*

*

3、 把tomcat中solr实例,修改solrcloud/tomcat1/webapps/solr/WEB-INF/web.xml,修改solrhome的位置,分别修改为对应的solrhome路径;

<env-entry>
   <env-entry-name>solr/home</env-entry-name>
   <env-entry-value>/opt/modules/solrcloud/solrhome1</env-entry-value>
   <env-entry-type>java.lang.String</env-entry-type>
</env-entry>

...

<env-entry>
   <env-entry-name>solr/home</env-entry-name>
   <env-entry-value>/opt/modules/solrcloud/solrhome4</env-entry-value>
   <env-entry-type>java.lang.String</env-entry-type>
</env-entry>

4、 开启tomcat,并且访问hadoop01:8080/solr;

tomcat1/bin/startup.sh
tomcat2/bin/startup.sh
tomcat3/bin/startup.sh
tomcat4/bin/startup.sh

访问hadoop01:8080/solr,hadoop01:8081/solr,hadoop01:8082/solr或者hadoop01:8083/solr,都可以~

*

5、 将solrhome/collection1/con1配置文件内容上传到zookeeper集群,集中管理;

启动zookeeper,然后上传文件

cd /opt/modules/solr-4.10.3-apache/example/scripts/cloud-scripts/
./zkcli.sh -zkhost 192.168.184.3:2181,192.168.184.3:2182,192.168.184.3:2183 -cmd upconfig -confdir /opt/modules/solrcloud/solrhome1/collection1/conf -confname myconf

备注:如果使用cdh版本的4.10.3的solr,可能会有各种报错,自己踩了各种坑,所以转为apache的solr搭建。真诚建议不要cdh搭建,除非大牛~~~

6、 查看zookeeper下的配置文件;

*

7、 修改solrcloud下,每个solrhome的solr.xml,host和hostPort分别是对应tomcat的ip以及端口号,例如:;

*

*

8、 配置每个tomcat的运行文件solrcloud/tomcat1/bin/catalina.sh,添加zookeeper服务器信息;

JAVA_OPTS="-DzkHost=192.168.184.3:2181,192.168.184.3:2182,192.168.184.3:2183"

*

9、 启动tomcat集群;

solrcloud/tomcat1/bin/startup.sh
solrcloud/tomcat2/bin/startup.sh
solrcloud/tomcat3/bin/startup.sh
solrcloud/tomcat4/bin/startup.sh

10、 访问solr服务,访问8080-8083任意端口,都可以访问solr集群,然后会有Cloud功能;

*

五、总结

1、 尽量不用CDH版本,在solr集群搭建过程中,CDH与zookeeper有些不兼容!;

版权声明:本文不是「本站」原创文章,版权归原作者所有 | 原文地址: