(本文来源于百战程序员)
solr搜索框架
链接:https://pan.baidu.com/s/1kcpHmNTTEa74iffKJJdSXg 密码:783r
一、环境准备
CentOS-6.4-x86_64-minimal.iso
jdk-6u45-linux-i586-rpm.bin
zookeeper-3.4.5.tar
solr-4.6.0.zip
服务器6台: 192.168.56.11- SolrCloud.Shard1.Leader
192.168.56.12-SolrCloud.Shard2.Leader
192.168.56.13-SolrCloud.Shard3.Leader
192.168.56.14-SolrCloud.Shard1.Replica
192.168.56.15-SolrCloud.Shard2.Replica
192.168.56.16-SolrCloud.Shard3.Replica
二、环境安装
1、CentOs 6.4安装
1)配制用户
安装完后配制用户solrcloud 密码: solrcloud
[root@localhost ~]# useradd solrcloud
[root@ localhost ~]# passwd solrcloud
2)修改当前机器名称
vi etc/sysconfig/network
HOSTNAME=SolrCloud.Shard1.Leader
3)修改当前机器ip
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:5C:8C:BD
TYPE=Ethernet
UUID=4fc0a398-f82b-49e5-8657-27bf5b260444
ONBOOT=yes
NM_CONTROLLED=yes
IPADDR=192.168.56.11
NETMASK=255.255.255.0
重启服务 service network restart
4)上传安装包(工具上传WinSCP)
创建文件夹 mkdir /solrcloud
赋写权限 chmod 777 /solrcloud
上传所需安装软件包到/solrcloud
2、jdk安装
默认jdk安装会报错,64位系统安装32位jdk报的错
需要安装glic , yum install glibc.i686
安装完后再安装jdk 进入/solrcloud目录
./jdk-6u45-linux-i586-rpm.bin
3、zookeeper集群安装
(集群安装测试时以ip为例说明,正式上线后可以配主机名称)
1)解压zookeeper 安装包
tar -zxvf zookeeper-3.4.5.tar.gz
2)进入zookeeper-3.4.5文件夹,创建data 和log
创建目录并赋于写权限
指定zookeeper的数据存放目录和日志目录
3)拷贝zookeeper配制文件zoo_sample.cfg
拷贝zookeeper配制文件zoo_sample.cfg并重命名zoo.cfg
cp /solrcloud/zookeeper-3.4.5/conf/zoo_sample.cfg /solrcloud/zookerper-3.4.5/conf/zoo.cfg
4)修改zoo.cfg
加入 dataDir=/solrcloud/zookeeper-3.4.5/data
dataLogDir=/solrcloud/zookeeper-3.4.5/log
server.1=192.168.56.11:2888:3888
server.2=192.168.56.12:2888:3888
server.3=192.168.56.13:2888:3888
server.4=192.168.56.14:2888:3888
server.5=192.168.56.15:2888:3888
server.6=192.168.56.16:2888:3888
zoo.cfg配制完后如下:
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/solrcloud/zookeeper-3.4.5/data
dataLogDir=/solrcloud/zookeeper-3.4.5/log
# the port at which the clients will connect
clientPort=2181
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=192.168.56.11:2888:3888
server.2=192.168.56.12:2888:3888
server.3=192.168.56.13:2888:3888
server.1=192.168.56.11:2888:3888
server.2=192.168.56.12:2888:3888
server.3=192.168.56.13:2888:3888
server.4=192.168.56.14:2888:3888
server.5=192.168.56.15:2888:3888
server.6=192.168.56.16:2888:3888
5)进入data文件夹 建立对应的myid文件
例如server.1=192.168.56.11 data文件夹下的myid文件内容为1
6)制zookeeper-3.4.5文件夹到其他机器
7)开启zookeeper的端口
/sbin/iptables -I INPUT -p tcp --dport 2181 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 2888 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 3888 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT --顺便启用tomcat 8080端口
/etc/rc.d/init.d/iptables save #将更改进行保存
/etc/init.d/iptables restart #重启防火墙以便改动生效
8)启动zookeeper
进入bin
./zkServer.sh start
查看集群状态
./zkServer.sh status 刚启动可能会有错误,集群中其他节点一并起来后就正常了
4、solr集群安装
1)在solrcloud下新建solrhome,并赋于读写权限
2)将上传的solr.4.6.0压缩包解压缩,
tar -zxvf solr-4.6.0.tgz
3)将solr.4.6.0/dist/solr-4.6.0.war 复制到/solrcloud/solrhome 并重命为solr.war
cp /solrcloud/solr-4.6.0/dist/solr-4.6.0.war /solrcloud/solrhome/solr.war
4)将上传的tomcat解压缩
tar -zxvf apache-tomcat-6.0.29.tar.gz
5)进入tomcat bin目录,启动tomcat
cd /solrcloud/apache-tomcat-6.0.29/bin 进入bin目录
./startup.sh 启动tomcat 此时会在tomcat下的conf文件夹下多出一个目录Catalina
cd /solrcloud/apache-tomcat-6.0.29/conf/Catalina/localhost
新建solr.xml文件内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<Context docBase="/solrcloud/solrhome/solr.war" debug="0" crossContext="false" >
<Environment name="solr/home"
type="java.lang.String"
value="/solrcloud/solrhome"
override="true" />
</Context>
docBase="/solrcloud/solrhome/solr.war" 指定为solrcloud/solrhome下复制出来solr的war包
6)停tomcat 再次启动tomcat, webapps 下边多了解压出来的solr文件夹
进入solr/WEB-INF/ 下修改web.xml
<!--
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/put/your/solr/home/here</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>/solrcloud/solrhome</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
7)将/solrcloud/solr-4.6.0/example/solr 文件夹下所有东西复制到 /solrcloud/solrhome
cp -r /solrcloud/solr-4.6.0/example/solr/* /solrcloud/solrhome
8)复制solr-4.6.0/example/lib/ext下所有jar包到tomcat 的lib下
cp /solrcloud/solr-4.6.0/example/lib/ext/* /solrcloud/apache-tomcat-6.0.29/lib/
复制 solr-4.6.0/example/resources/log4j.properties 到solr/WEB-INF/class
如果没有class先创建class文件夹,并赋于写权限
cp /solrcloud/solr-4.6.0/example/resources/log4j.properties /solrcloud/apache-tomcat-6.0.29/webapps/solr/WEB-INF/class/
9)启动tomcat 访问 http://localhost:8080/solr 如图,至此单机版solr配制完成
10)配制集群
将zookeeper和tomcat关联
192.168.56.11台机修改tomcat 的 bin目录下catalina.sh文件在第二行加入
JAVA_OPTS="-Dbootstrap_confdir=/solrcloud/solrhome/collection1/conf -Dcollection.configName=myconf -DzkHost=192.168.56.11:2181,192.168.56.12:2181,192.168.56.13:2181,192.168.56.14:2181,192.168.56.15:2181,192.168.56.16:2181 -DnumShards=3"
192.168.56.12-16 , 5台机都修改tomcat 的 bin目录下catalina.sh文件在第二行加入
JAVA_OPTS="-DzkHost=192.168.56.11:2181,192.168.56.12:2181,192.168.56.13:2181,192.168.56.14:2181,192.168.56.15:2181,192.168.56.16:2181"
至此集群配制完毕
创建集合
http://192.168.56.11:8080/solr/admin/collections?action=CREATE&name=guangzhou&numShards=3&replicationFactor=3
任何一个ip均可访问
http://192.168.56.11:8080/solr/#/~cloud