Solr6.3+tomcat8+zookeeper3.4.8+jdk8搭建SolrCloud
一.软件版本介绍
1.JDK8,版本jdk1.8.0_131
2.Solr,版本solr-6.3.0.zip
3.tomcat,版本apache-tomcat-8.0.21.zip
4.zookeeper,版本zookeeper-3.4.8.tar.gz
备注:solr6.x需要java8和tomcat8,zookeeper版本太低会有坑
二.安装
1. 首先把软件的安装包上传到linux的/setup 目录
[root@centos2 /]# cd setup/
[root@centos2 setup]# ls
apache-tomcat-8.0.21.zip jdk-8u131-linux-x64.tar.gz solr-6.3.0.zip
zookeeper-3.4.8.tar.gz
2. 安装配置JDK8
解压到/usr/local/jdk1.8.0_131
[root@centos2 setup]# tar -zxvf jdk-8u131-linux-x64.tar.gz /usr/local/
修改环境变量
[root@centos2 /]# vi /etc/profile
追加内容
export JAVA_HOME=/usr/local/jdk1.8.0_131 export
CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib export
JAVA_BIN=$JAVA_HOME/bin export JRE_HOME=$JAVA_HOME/jre export
PATH=$PATH:$JAVA_BIN
使环境变量生效
[root@centos2 /]# source etc/profile
查看环境变量和JAVA版本
[root@centos2 /]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/jdk1.8.0_131/bin:/root/bin:/usr/local/jdk1.8.0_131/bin
[root@centos2 /]# java -version java version “1.8.0_131” Java(TM) SE
Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit
Server VM (build 25.131-b11, mixed mode)
3.配置SolrCloud
准备了两台虚拟机ip分别为192.168.1.38和192.168.1.39。现在192.168.1.38上配置好,然后复制到39上
3.1. 在/usr/local 下建立solr目录
[root@centos2 /]# cd usr/local/
[root@centos2 local]# mkdir solr
3.2.进入solr目录,把tomcat,zookeeper,solr解压到/usr/local/solr中
[root@centos2 solr]# unzip /setup/solr-6.3.0.zip
[root@centos2 solr]# tar -zxvf /setup/zookeeper-3.4.8.tar.gz
[root@centos2 solr]# unzip /setup/apache-tomcat-8.0.21.zip
[root@centos2 solr]# ls
apache-tomcat-8.0.21 solr-6.3.0 zookeeper-3.4.8
3.3.添加用户solr, 分配组,将solr目录权限设置为solr
[root@centos2 local]# adduser solr
[root@centos2 local]# passwd solr
[root@centos2 local]# chown -R solr:solr solr/
3.4.配置zookeeper集群
3.4.1:创建data,logs目录
[solr@centos2 solr]$ mkdir zookeeper-3.4.8/data
[solr@centos2 solr]$ mkdir zookeeper-3.4.8/logs
3.4.2:创建data,logs目录
[solr@centos2 solr]$ mkdir zookeeper-3.4.8/data
[solr@centos2 solr]$ mkdir zookeeper-3.4.8/logs
3.4.3:拷贝conf/zoo_sample.cfg创建zoo.cfg,并修改zoo.cfg
[solr@centos2 solr]$ cp -r zookeeper-3.4.8/conf/zoo_sample.cfgzookeeper-3.4.8/conf/zoo.cfg
[solr@centos2 solr]$ vi zookeeper-3.4.8/conf/zoo.cfg
//zoo.cfg配置如下
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/solr/zookeeper-3.4.8/data
dataLogDir=/usr/local/solr/zookeeper-3.4.8/logs
clientPort=2181
server.1=192.168.1.38:2888:3888
server.2=192.168.1.39:2888:3888
3.4.5:在data目录下创建myid,并写下1
[solr@centos2 solr]$ echo “1” >> zookeeper-3.4.8/data/myid
3.4.6: 把zookeeper-3.4.8整个目录拷贝到192.168.1.39上
[solr@centos2 solr]$ scp -r zookeeper-3.4.8/ root@192.168.1.39:/usr/local/solr/zookeeper-3.4.8/
在39上修改myid
[root@centos3 solr]# rm -rf zookeeper-3.4.8/data/myid
[root@centos3 solr]# echo “2” >> zookeeper-3.4.8/data/myid
3.4.7:启动zookeeper并查看状态
[root@centos3 solr]# zookeeper-3.4.8/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/solr/zookeeper-3.4.8/bin/../conf/zoo.cfg
Starting zookeeper … STARTED
[root@centos3 solr]# zookeeper-3.4.8/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/solr/zookeeper-3.4.8/bin/../conf/zoo.cfg
Mode: leader
[solr@centos2 solr]$ zookeeper-3.4.8/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/solr/zookeeper-3.4.8/bin/../conf/zoo.cfg
Starting zookeeper … STARTED
[solr@centos2 solr]$ zookeeper-3.4.8/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/solr/zookeeper-3.4.8/bin/../conf/zoo.cfg
Mode: follower
其中一个是leader,一个是follower,搭建完成
3.5:配置solr
3.5.1:复制一些solr的文件到tomcat下面
1).将 solr-6.3.0/server/solr-webapp的webapp文件夹复制到,apache-tomcat-8.0.21/webapps下并命名solr
2).将 solr-6.3.0/server/lib/ext的所有jar包复制到,apache-tomcat-8.0.21/webapps/solr/WEB-INF/lib/下
3).将 solr-6.3.0/dist 下的jar复制到,apache-tomcat-8.0.21/webapps/solr/WEB-INF/lib/下
4).在apache-tomcat-8.0.21/webapps/solr/WEB-INF/建立classes目录,并将solr-6.3.0/server/resources/log4j.properties复制过去
5).建立solrhome目录放在/usr/local/solr/下,复制solr-6.3.0/server/solr/* 到该目录下
[solr@centos2 solr]$ pwd
/usr/local/solr
[solr@centos2 solr]$ cp -R solr-6.3.0/server/solr-webapp/webapp/ apache-tomcat-8.0.21/webapps/solr
[solr@centos2 solr]$ cp -r solr-6.3.0/server/lib/ext/* apache-tomcat-8.0.21/webapps/solr/WEB-INF/lib/
[solr@centos2 solr]$ cp -r solr-6.3.0/dist/solr-* apache-tomcat-8.0.21/webapps/solr/WEB-INF/lib/
[solr@centos2 solr]$ mkdir apache-tomcat-8.0.21/webapps/solr/WEB-INF/classes
[solr@centos2 solr]$ cp solr-6.3.0/server/resources/log4j.properties apache-tomcat-8.0.21/webapps/solr/WEB-INF/classes/
[solr@centos2 solr]$ mkdir solrhome
[solr@centos2 solr]$ cp -R solr-6.3.0/server/solr/* solrhome/
[solr@centos2 solr]$ ls solrhome/
configsets README.txt solr.xml zoo.cfg
3.5.2:配置solr
编辑web.xml,配置solr根路径
[solr@centos2 solr]$ vi apache-tomcat-8.0.21/webapps/solr/WEB-INF/web.xml
3.5.3:修改 apache-tomcat-8.0.21/bin/catalina.sh
[solr@centos2 solr]$ vi apache-tomcat-8.0.21/bin/catalina.sh
//加上一行,zookeeper集群以”,”分割
JAVA_OPTS=”$JAVA_OPTS -DzkHost=192.168.1.39:2181,192.168.1.38:2181 -DnumShards=2”
3.5.4:复制tomca和solrhome 到39那台机器
[solr@centos2 solr]$ scp -r apache-tomcat-8.0.21/ root@192.168.1.39:/usr/local/solr/apache-tomcat-8.0.21/
[solr@centos2 solr]$ scp -r solrhome/ root@192.168.1.39:/usr/local/solr/solrhome/
3.5.5:启动两个tomcat
如果没有启动权限则
[solr@centos3 solr]$ chmod u+x apache-tomcat-8.0.21/bin/*.sh
备注:
1.http://192.168.1.38:8080/solr/# 如果访问不了,可以带上index.html
或者修改web.xml中 把index.html修改为1.html,对应的把index.html重命名
[solr@centos3 solr]$ mv apache-tomcat-8.0.21/webapps/solr/index.html apache-tomcat-8.0.21/webapps/solr/1.html
2.如果出现HTTP Status 404,可以查看下 solr/WEB-INF/lib 看是否存在子文件夹,如果jar拷贝错误会出现这个问题,具体可以查看tomcat日志
3.如果出现HTTP Status 500 - Error processing the request. CoreContainer is either not initialized or shutting down.
先去查看zookeeper集群是否启动成功
参考文章:
http://www.w2bc.com/article/206126
http://www.cnblogs.com/wander1129/p/6658318.html