一、软件准备
1、jdk1.7或以后, 安装目录:/install/jdk/jdk1.8.0_60
2、tomat9.0,安装目录:/install/tomcat/tomcat-9.0.0
3、solr5.4,解压目录:/opt/software/solr-5.4.0
4、zookeeper-3.4.7,解压目录:/opt/software/zookeeper-3.4.7
二、部署、配置zookeeper
1、创建solr集群安装目录:
mkdir /install/solrCloud
cd /install/solrCloud
2、创建zookeeper安装目录:
mkdir zookeeper1
mkdir zookeeper2
mkdir zookeeper3
3、在zookeeper1、zookeeper2、zookeeper3下分别创建data、datalog、logs目录:
cd /install/solrCloud/zookeeper1
mkdir data datalog logs
cd /install/solrCloud/zookeeper2
mkdir data datalog logs
cd /install/solrCloud/zookeeper3
mkdir data datalog logs
4、在zookeeper1、zookeeper2、zookeeper3的data目录下创建myid文件:
echo 1 >> /install/solrCloud/zookeeper1/data/myid
echo 2 >> /install/solrCloud/zookeeper2/data/myid
echo 3 >> /install/solrCloud/zookeeper3/data/myid
5、拷贝zookeeper解压目录到zookeeper1、zookeeper2、zookeeper3下:
cp -rf /opt/software/zookeeper-3.4.7 /install/solrCloud/zookeeper1
cp -rf /opt/software/zookeeper-3.4.7 /install/solrCloud/zookeeper2
cp -rf /opt/software/zookeeper-3.4.7 /install/solrCloud/zookeeper3
6、分别在zookeeper1、zookeeper2、zookeeper3下的zookeeper-3.4.7下的conf中创建zoo.cfg(可拷贝zoo_sample.cfg):
cd /install/solrCloud/zookeeper1/zookeeper-3.4.7/conf
cp zoo_sample.cfg zoo.cfg
cd /install/solrCloud/zookeeper2/zookeeper-3.4.7/conf
cp zoo_sample.cfg zoo.cfg
cd /install/solrCloud/zookeeper3/zookeeper-3.4.7/conf
cp zoo_sample.cfg zoo.cfg
7、分别编辑刚刚创建的zoo.cfg:
vi /install/solrCloud/zookeeper1/zookeeper-3.4.7/conf/zoo.cfg, 内容为:
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/install/solrCloud/zookeeper1/data
datalogDir=/install/solrCloud/zookeeper1/datalog
clientPort=3181
server.1=solrCloudNode1:4888:5888
server.2=solrCloudNode2:4889:5889
server.3=solrCloudNode3:4890:5890
vi /install/solrCloud/zookeeper2/zookeeper-3.4.7/conf/zoo.cfg, 内容为:
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/install/solrCloud/zookeeper2/data
datalogDir=/install/solrCloud/zookeeper2/datalog
clientPort=3182
server.1=solrCloudNode1:4888:5888
server.2=solrCloudNode2:4889:5889
server.3=solrCloudNode3:4890:5890
vi /install/solrCloud/zookeeper3/zookeeper-3.4.7/conf/zoo.cfg, 内容为:
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/install/solrCloud/zookeeper3/data
datalogDir=/install/solrCloud/zookeeper3/datalog
clientPort=3183
server.1=solrCloudNode1:4888:5888
server.2=solrCloudNode2:4889:5889
server.3=solrCloudNode3:4890:5890
8、配置hosts:
vi /etc/hosts 加入内容:
127.0.0.1 solrCloudNode1 solrCloudNode2 solrCloudNode3
9、依次启动3个zookeeper(启动中可能会报错,不用管,这是因为其他zookeep没有启动):
/install/solrCloud/zookeeper1/zookeeper-3.4.7/bin/zkServer.sh start
/install/solrCloud/zookeeper2/zookeeper-3.4.7/bin/zkServer.sh start
/install/solrCloud/zookeeper3/zookeeper-3.4.7/bin/zkServer.sh start
10、分别查看3个zookeeper的运行状态:
/install/solrCloud/zookeeper1/zookeeper-3.4.7/bin/zkServer.sh status
/install/solrCloud/zookeeper2/zookeeper-3.4.7/bin/zkServer.sh status
/install/solrCloud/zookeeper3/zookeeper-3.4.7/bin/zkServer.sh status
三、部署、配置solr
1、在solr集群安装目录下,分别创建solr1、solr2、solr3、solr4:
cd /install/solrCloud
mkdir solr1 solr2 solr3 solr4
2、拷贝单机安装好的solr_home、solr_webapp到solr1、solr2、solr3、solr4下;
详情请见我的另一篇文章《CentOS6.5下Tomcat部署Solr5.4.0》
3、分别修改solr1、solr2、solr3、solr4下的solr_webapp/solr/WEB-INF/web.xml中的solr home配置:
vi /install/solrCloud/solr1/solr_webapp/solr/WEB-INF/web.xml, 修改内容:
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/install/solrCloud/solr1/solr_home</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
vi /install/solrCloud/solr2/solr_webapp/solr/WEB-INF/web.xml, 修改内容:
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/install/solrCloud/solr2/solr_home</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
vi /install/solrCloud/solr3/solr_webapp/solr/WEB-INF/web.xml, 修改内容:
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/install/solrCloud/solr3/solr_home</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
vi /install/solrCloud/solr4/solr_webapp/solr/WEB-INF/web.xml, 修改内容:
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/install/solrCloud/solr4/solr_home</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
4、分别修改solr1、solr2、solr3、solr4下的solr_home/solr.xml配置:
vi /install/solrCloud/solr1/solr_home/solr.xml ,修改端口为tomcat1的启动端口:
<int name="hostPort">${jetty.port:8180}</int>
vi /install/solrCloud/solr2/solr_home/solr.xml ,修改端口为tomcat2的启动端口:
<int name="hostPort">${jetty.port:8280}</int>
vi /install/solrCloud/solr3/solr_home/solr.xml ,修改端口为tomcat3的启动端口:
<int name="hostPort">${jetty.port:8380}</int>
vi /install/solrCloud/solr4/solr_home/solr.xml ,修改端口为tomcat4的启动端口:
四、部署、配置tomcat<int name="hostPort">${jetty.port:8480}</int>
1、复制4个tomcat到solr集群安装目录下,分别为tomcat1、tomcat2、tomcat3、tomcat4:
cd /install/solrCloud
cp -rf /install/tomcat/tomcat-9.0.0 ./tomcat1
cp -rf /install/tomcat/tomcat-9.0.0 ./tomcat2
cp -rf /install/tomcat/tomcat-9.0.0 ./tomcat3
cp -rf /install/tomcat/tomcat-9.0.0 ./tomcat4
2、分别修改tomcat1、tomcat2、tomcat3、tomcat4的启动端口为8180、8280、8380、8480,
注意tomact启动时用到的其他端口,防止端口被占用导致tomcat启动失败
3、在solr集群安装目录下创建confs目录,并拷贝solr配置文件到该目录下:
cd /install/solrCloud
mkdir confs
cp -rf solr1/solr_home/configsets/sample_techproducts_configs/conf ./confs
4、配置tomcat1的启动文件catalina.sh,在前面加上:
JAVA_OPTS="$JAVA_OPTS -DzkHost=solrCloudNode1:3181,solrCloudNode2:3182,solrCloudNode3:3183 -Dbootstrap_confdir=/install/solrCloud/confs/conf -Dcollection.configName=myconf"
5、配置tomcat2、tomcat3、tomcat4的启动文件catalina.sh,在前面加上:
JAVA_OPTS="$JAVA_OPTS -DzkHost=solrCloudNode1:3181,solrCloudNode2:3182,solrCloudNode3:3183"
五、启动solr集群
1、分别在tomcat1、tomcat2、tomcat3、tomcat4的conf/Catalina/localhost下创建,solr启动文件solr.xml
对应启动工程路径为solr1、solr2、solr3、solr4下面的solr_webapp/solr
2、依次分别启动tomcat1、tomcat2、tomcat3、tomcat4
cd /install/solrCloud
tomcat1/bin/startup.sh
tomcat2/bin/startup.sh
tomcat3/bin/startup.sh
tomcat4/bin/startup.sh
3、查看启动情况
http:localhost:8180/solr/index.html
http:localhost:8280/solr/index.html
http:localhost:8380/solr/index.html
http:localhost:8480/solr/index.html
六、创建collection
1、方式1:
http://localhost:8180/solr/admin/collections?action=CREATE&name=eSearch&numShards=3&replicationFactor=3&maxShardsPerNode=3&collection.configName=myconf
2、方式2:
在collection界面管理菜单创建
3、删除collection:
七、备注:http://localhost:8380/solr/admin/collections?action=DELETE&name=eSearch
由于我是在一台服务器上部署3个zookeeper节点,4个solr节点,所以zookeeper、tomcat的端口都不一样;实际环境中,如果是都部署在真实的服务器节点上,zookeeper、tomcat的端口可以一样,只需要在各个节点上配置好hosts即可。