一、官网下载所需包。
solr-5.5.2.tgz
下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/lucene/solr/5.5.2/
zookeeper-3.4.6.tar.gz
下载地址:http://apache.org/dist/zookeeper/zookeeper-3.4.6/
solr-5.5.2版本本身已经集成了jetty,所以这里就不需要tomcat了。
二、准备环境
《192.168.0.36服务器》
1.安装JDK 1.7版本以上(You will need the Java Runtime Environment (JRE) version 1.7 or higher.)
略过~~
2.安装zookeeper
创建/usr/solr/文件夹并上传zookeeper-3.4.6.tar.gz到该目录下。
命令进入目录:
cd /usr/solr/
解压文件:
tar -xzvf zookeeper-3.4.6.tar.gz
将解压后得到的zookeeper-3.4.6
创建zookeeper-3.4.6的dataDir文件夹/usr/solr/zookeeper-data。
mkdir zookeeper-data
进入到zookeeper-data目录下创建myid文件。
vi myid
输入1并保存。
进入/usr/solr/zookeeper-3.4.6/conf目录下,拷贝一份zoo_sample.cfg为zoo.cfg
cp zoo_sample.cfg zoo.cfg
修改zoo.cfg中的dataDir=/usr/solr/zookeeper-data
在最后添加:
server.1=192.168.0.36:2999:3999
server.2=192.168.0.33:2999:3999
server.3=192.168.0.32:2999:3999
(端口自己定义)
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=/usr/solr/zookeeper-data # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # 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.0.36:2999:3999 server.2=192.168.0.33:2999:3999 server.3=192.168.0.32:2999:3999
3.《192.168.0.32服务器》和《192.168.0.33服务器》
按1-2步骤安装好zookeeper。
修改myid内容
备注:每一台服务器zookeeper-data目录下myid中的内容必须与zoo.cfg中添加的server.后面数字编号一致,代表的是第几台服务器。
4.启动每台服务器上的zookeeper。
命令:zookeeper-3.4.6/bin/zkServer.sh start
查看状态:zookeeper-3.4.6/bin/zkServer.sh status
三、安装启动Solr-5.5.2
1.上传solr-5.5.2.tgz到/usr/solr目录下并解压。
tar -xzvf solr-5.5.2.tgz
得到solr-5.5.2
SolrCloud模式启动命令(看帮助命令 solr-5.5.2/bin/solr start -help):
solr-5.5.2/bin/solr start -c -d server -z 192.168.0.33:2181,192.168.0.36:2181,192.168.0.32:2181 -m 1g -s solr
启动成功提示
(如果启动solr提示未安装lsof,请安装:yum install lsof,如果启动成功访问不了有可能是开启了防火墙,关闭防火墙:service iptables stop)
启动成功后访问:http://192.168.0.36:8983/solr(本机:http://localhost:8983/solr) 就可以看到Solr的管理界面了
2.《192.168.0.32服务器》和《192.168.0.33服务器》
重复第三步骤启动solr访问即可。
创建collection命令:
solr-5.5.2/bin/solr create_collection -c my_app -shards 3 -replicationFactor 3
删除collection命令:
solr-5.5.2/bin/solr delete my_app
清除zookeeper中的数据:
sh solr-5.5.2/server/scripts/cloud-scripts/zkcli.sh -z 192.168.0.33:2181,192.168.36:2181,192.168.0.32:2181 -cmd clear /
参考文档:
https://cwiki.apache.org/confluence/display/solr/Getting+Started
http://archive.apache.org/dist/lucene/solr/ref-guide/apache-solr-ref-guide-5.5.pdf
来源:https://www.cnblogs.com/lyxy/p/5826910.html