0,准备
从apache官网下载zookeeper-3.4.6.tar.gz,solr-5.3.1.zip,apache-tomcat-8.0.28.zip,jdk7+
自带ik-analyzer.zip (附件)
1,目录和端口规划
{all-in-one}/zookeeper
{all-in-one}/zookeeper/zookeeper1 {2181,2881,3881}
{all-in-one}/zookeeper/zookeeper1/data
{all-in-one}/zookeeper/zookeeper1/data/myid 1(文件)
{all-in-one}/zookeeper/zookeeper2 {2182,2882,3882}
{all-in-one}/zookeeper/zookeeper2/data
{all-in-one}/zookeeper/zookeeper2/data/myid 2(文件)
{all-in-one}/zookeeper/zookeeper3 {2183,2883,3883}
{all-in-one}/zookeeper/zookeeper3/data
{all-in-one}/zookeeper/zookeeper3/data/myid 3(文件)
{all-in-one}/tomcat
{all-in-one}/tomcat/tomcat1 {8105,8180,8109}
{all-in-one}/tomcat/tomcat1/apache-tomcat-8.0.28/webapps/solr-5.3.1
{all-in-one}/tomcat/tomcat2 {8205,8280,8209}
{all-in-one}/tomcat/tomcat2/apache-tomcat-8.0.28/webapps/solr-5.3.1
{all-in-one}/tomcat/tomcat3 {8305,8380,8309}
{all-in-one}/tomcat/tomcat3/apache-tomcat-8.0.28/webapps/solr-5.3.1
{all-in-one}/solr
{all-in-one}/solr/solr1 8180:gettingstarted
{all-in-one}/solr/solr1/solr/gettingstarted/data
{all-in-one}/solr/solr2 8280:gettingstarted
{all-in-one}/solr/solr2/solr/gettingstarted/data
{all-in-one}/solr/solr3 8380:gettingstarted
{all-in-one}/solr/solr3/solr/gettingstarted/data
http://127.0.0.1:8180/solr-5.3.1
http://127.0.0.1:8280/solr-5.3.1
http://127.0.0.1:8380/solr-5.3.1
2,安装zookeeper
2.1 把zookeeper-3.4.6.tar.gz解压到zookeeper1
2.2 复制zookeeper-3.4.6/conf/zoo_sample.cfg为zoo.cfg
2.3 修改zoo.cfg 12行dataDir的值为
dataDir=../../data
2.4 zoo.cfg端口配置为2181(clientPort=2181)(zookeeper2为2182,zookeeper3为2183)
2.5 zoo.cfg最后添加集群配置信息
#cluster-set server.1=localhost:2881:3881 server.2=localhost:2882:3882 server.3=localhost:2883:3883
2.6 在/zookeeper/zookeeper1/data目录中新建 myid文件
文件内容为1
2.7 复制zookeeper1两次,改名为zookeeper2和zookeeper3,在zookeeper2的zoo.cfg中,将端口2181改为2182,myid为2;zookeeper3的端口为2183,myid为3
2.8 分别启动zookeeper1,zookeeper2,zookeeper3(/bin/zkServer.cmd)
日志中有
Notification: 1 (message format version), 3 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 3 (n.sid), 0x0 (n.peerEpoch) LEADING (my state)
其中3 (n.leader)表示zookeeper3是leader
然后使用客户端(/bin/zkCli.cmd)连接测试
ls / create /one 1 get /one
3,安装tomcat
3.1 把apache-tomcat-8.0.28.zip解压到tomcat/tomcat1
3.2 把/apache-tomcat-8.0.28/conf/server.xml中的三个端口8005,8080,8009改为8105,8180,8109
3.3 启动bin/startup.bat
3.4 访问测试
http://127.0.0.1:8180
4,安装solr
4.1 把solr-5.3.1.zip解压到/all-in-one/solr中
4.2 复制/all-in-one/solr/solr-5.3.1/server/solr到/all-in-one/solr/solr1中
4.3 把/all-in-one/solr/solr-5.3.1/server/solr-webapp/webapp复制到
tomcat1的webapp中,改名为 solr-5.3.1
4.4 添加jar包 把/all-in-one/solr/solr-5.3.1/server/lib/ext中的jar包复制到
/tomcat1/apache-tomcat-8.0.28/webapps/solr-5.3.1/WEB-INF/lib 中
把/all-in-one/solr/solr-5.3.1/server/resources中的log4j.properties复制到 apache-tomcat-8.0.28/webapps/solr-5.3.1/WEB-INF/classes中 (否则无法看solr日志输出)
4.5 修改tomcat1的bin/catalina.bat,添加solr的JVM环境变量 93行
set JAVA_OPTS=%JAVA_OPTS% -DzkHost=localhost:2181,localhost:2182,localhost:2183 -Dsolr.solr.home=../../../../solr/solr1/solr -Djetty.port=8180 -DhostContext=/solr-5.3.1 -DnumShards=1 -Dbootstrap_confdir=../../../../solr/solr1/solr/configsets/basic_configs/conf -Dcollection.configName=gettingstarted -Dsolr.data.dir=../../../../solr/solr1/solr/gettingstarted/data
4.6 关闭tomat1后,重新启动bin/startup.bat后访问http://127.0.0.1:8180/solr-5.3.1
看到solr的控制台就正常
4.7 复制
复制tomcat1成tomcat2,tomcat3,修改端口和环境变量
(8205,8280,8209)(8305,8380,8309)
jvm环境变量 solr1改成solr2(三处), 8180改成8280(一处), solr1改成solr3(三处), 8180改成8380(一处)
复制solr1,到solr2,solr3
4.8 启动测试 tomcat2,tomcat3
http://127.0.0.1:8280/solr-5.3.1
http://127.0.0.1:8380/solr-5.3.1
5 创建集群
5.1 停止所有tomcat,只启动tomcat1
5.2 打开控制台http://127.0.0.1:8180/solr-5.3.1/#/~cores
在Core Admin中点击Add Core,填入如下信息:
name:gettingstarted
instanceDir:gettingstarted
data: (空) 是jvm环境变量的设置
collection: gettingstarted
点击创建
5.3 然后依次启动tomcat2,tomcat3
5.4 在tomcat2和tomcat3中启动并执行5.2步骤
5.5 访问http://127.0.0.1:8180/solr-5.3.1/#/~cloud 查看集群状态
5.6 如果创建不成功,返回5.1
6 同步测试
6.1 进入实例
http://127.0.0.1:8180/solr-5.3.1/#/gettingstarted/documents
在Document(s)添加数据(默认数据类型不存在,保存报错)
{"id":"change.me","title_txt":"change.me"}
点击蓝色按钮提交
6.2 查看同步:在tomcat2和tomcat3中看到
http://127.0.0.1:8280/solr-5.3.1/#/gettingstarted/query
http://127.0.0.1:8380/solr-5.3.1/#/gettingstarted/query
7 宕机测试
7.1 关掉任意一台zookeeper,看6.1,6.2是否正常使用
7.2 关掉任意一台tomcat,看6.1,6.2是否正常使用(注意端口)
8 中文分词
8.1 安装
把ik-analyzer.zip里面的WEB-INF分别复制到tomcat1,tomcat2,tomcat3的\apache-tomcat-8.0.28\webapps\solr-5.3.1中
8.2 配置
配置一个中文字段类型和中文字段
在\solr\configsets\basic_configs\conf\schema.xml 534行
添加(注意:三个solr都要添加,否则后面重启覆盖)
<!-- 添加中文ik分词器 --> <fieldType name="text_ik" class="solr.TextField"> <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/> </fieldType> <field name="content" type="text_ik" indexed="true" stored="true" required="false" multiValued="false" />
8.3 重新启动tomcat测试,访问
http://127.0.0.1:8180/solr-5.3.1/#/gettingstarted/analysis
下拉框里面可以看到text_ik字段类型
说明中文分词器安装成功,输入中文体验一下