[Solr]zookeeper+solr 集群搭建

本贴最后更新于 1961 天前,其中的信息可能已经天翻地覆

当我们访问购物网站的时候,我们可以根据我们随意所想的内容输入关键字就可以查询出相关的内容,这是怎么做到呢?这些随意的数据不可能是根据数据库的字段查询的,那是怎么查询出来的呢,为什么千奇百怪的关键字都可以查询出来呢?
答案就是全文检索工具的实现,solr 支持分词检索。举个例子:北京天安门------切分词:北京 京天 天安 安门 等等这些分词。所以我们搜索的时候都可以检索到。

这里主要是讲主要搭建 solr 集群,由于只是开发,并不在生产环境,所以只能实现一个伪集群,也就是和之前的 redis 类似。
但是真正集群和伪集群也只是多台服务器和单台服务器的差别,并没有多大区别,可能防火墙、IP 等会有不同的配置。
伪集群会用了,起码真正集群有思路了,对吧,到时候再见招拆招就是了。

本文主要介绍单 solr 如何安装使用和测试,集群如何搭建,搭建好之后如何测试;

1、单机 solr 安装与测试

1.1、 安装

我这里使用的是 solr-4.10.3 版本有点低,大家可以选择高版本的试下,容器用的是 tomcat,当然你也可以选择 jetty,在我这里用哪个问题都不大,tomcat 比较熟,所以就用 tomcat,如果你是要生产环境用的,倒是要考虑清楚两者优缺点;

我们先在 HOME 目录解压 solr 包

tar -xzvf solr-4.10.3.tgz.tgz

再解压 tomcat 包

tar -xzvf apache-tomcat-7.0.47.tar.gz

一般来说,我们自己安装的软件都会放到/usr/local 里,所以这里也选择这个目录

sudo mkdir /usr/local/solr

再把 tomcat 拷贝到这个目录下

sudo cp -rf apache-tomcat-7.0.47 /usr/local/solr/tomcat

再把 solr 包里的 solr 的 war 包拷贝到 tomcat 的 webapps 里

sudo cp solr-4.10.3/dist/solr-4.10.3.war /usr/local/solr/tomcat/webapps/solr.war

启动 tomcat 解压 war 包

cd /usr/local/solr/tomcat/bin
sudo sh startup.sh

这时可以查看下日志,确认是否已经启动成功 ,日志在 tomcat/logs 的 catalina.out
这里不介绍了。

启动完之后,可以进 tomcat/webapps/下看看,确认有 solr 文件夹生成后,可以停掉 tomcat 了。

cd /usr/local/solr/tomcat/bin
sudo sh shutdown.sh

这里 solr.war 没用了,你可以选择删掉可以留着。

到这,solr 的启动准备已经做好了,现在就开始配置这个 tomcat 里的 solr 了。

1.2 配置

先复制 solr 压缩包中 example 下的 jar 包

cd solr-4.10.3
sudo cp example/lib/ext/*.jar /usr/local/solr/tomcat/webapps/solr/WEB-INF/lib/

接下来配置 solrhome,example 下 solr 可以做为 solrhome

sudo cp -rf example/solr /usr/local/solr/solrhome

有了 solrhome 后,需要配置 solr 的 web.xml 通过 JNDI 指定 solrhome 目录

  <!-- People who want to hardcode their "Solr Home" directly into the
       WAR File can set the JNDI property here...
   -->
   <!-- 打开下面env-entry的注释,并且修改entry-value -->
    <env-entry>
       <env-entry-name>solr/home</env-entry-name>
       <env-entry-value>/usr/local/solr/solrhome</env-entry-value>
       <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>

配置完 solrhome 之后,我们就可以启动 tomcat,网页方式登陆 solr 控制台看看了。

cd /usr/local/solr/tomcat/bin/
sudo sh startup.sh

访问 http://虚拟机 IP:8080/solr 访问了。

如果访问不了,确认一下防火墙状态,如果防火墙开了,可以通过修改防火墙配置文件后再访问。

sudo vi /etc/sysconfig/iptables

确认里面有没有以下内容
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
配置完重启防火墙就可以了。

sudo service iptables restart

1.3 加入 IK 中文分词器,确认需要自定义的 Field Type

下载好 IK Analyzer 包,上传到虚拟机后,解压,把里面的 jar 包和词典等都复制到相应位置

cd IK Analyzer 2012FF_hf1
sudo cp IKAnalyzer2012FF_u1.jar /usr/local/solr/tomcat/webapps/solr/WEB-INF/lib
sudo mkdir /usr/local/solr/tomcat/webapps/solr/WEB-INF/classes
sudo cp ext_stopword.dic IKAnalyzer.cfg.xml mydict.dic /usr/local/solr/tomcat/webapps/solr/WEB-INF/classes/

这样 IK 中文分词器就加入成功了。
接下来定义 solr 的 field type

这里需要进入到 solrhome 中的 collection1 里,修改其中的 schema.xml

cd /usr/local/solr/solrhome/collection1/conf
sudo vi schema.xml

里面有一段定义如下:

solr.TextField allows the specification of custom text analyzers
         specified as a tokenizer and a list of token filters. Different
         analyzers may be specified for indexing and querying.

TextFiled 允许使用自定义的解析器
所以我们要定义的 fieldtype 也是需要这个类型的,
在文件最后添加以下内容:

  <fieldType name="text_ik" class="solr.TextField">
    <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>
  </fieldType>
  <field name="item_title" type="text_ik" indexed="true" stored="true"/>

因为我们刚刚已经把 IK 的 jar 包放到 solr 工程里了,所以 solr 能找到这个 IK 解析器。
至于 field 主要是看项目中可能搜索哪些字段,需要搜索的字段都应该在这里添加相应声明配置,
这里需要注意的是,需要中文解析器解析的时候才需要用 text_ik,而类似 URL,数字型的,solr 都有相应的类型可供选择。

配置完这些,需要重启下 tomcat。

1.4 测试

1.4.1 页面验证

重启完 tomcat 后,重新访问下 solr 控制台。
选择 collection1 -> Analysis 查找一下自己定义的 field type 和 field name。
选择 text_ik 或者自定义的 field,在 field value 里随便摘抄一段中文段落,点击 Anaylse Values,检查是否分词成功 ;

1.4.2 代码测试

新建 maven 工程,pom.xml 中包含以下依赖

	<dependency>
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
	</dependency>
	
		<!-- solr客户端 -->
	<dependency>
		<groupId>org.apache.solr</groupId>
		<artifactId>solr-solrj</artifactId>
	</dependency>

test 目录新建 TestSolrJ.java
代码如下:

	@Test
	public void testAddDocument() throws Exception {
		//创建一个solrServer对象,引用HttpSOlrServer对象
		//指定URL
		SolrServer solrServer = new HttpSolrServer("http://192.168.200.128:8080/solr/collection1");
		//创建一个文档对象SolrInputDocument
		SolrInputDocument doc = new SolrInputDocument();
		//向文档中添加域,必须有id域,域的名称必须在schema.xml中定义
		doc.addField("id", "test001");
		doc.addField("item_title", "测试商品1");
		//写入索引数据库
		solrServer.add(doc);
		//提交
		solrServer.commit();
	}
	
		@Test
	public void testQuery() throws Exception {
		//创建一个solrServer对象
		SolrServer solrServer = new HttpSolrServer("http://192.168.200.128:8080/solr/collection1");
		//创建一个SolrQuery对象
		SolrQuery query = new SolrQuery();
		//设置查询条件,过滤条件,分页条件,排序条件,高亮等
		//query.set("q","*:*");
		query.setQuery("测试");
		//分页条件
		query.setStart(0);
		query.setRows(10);
		//默认搜索
		query.set("df", "item_title");
		//设置高亮
		query.setHighlight(true);
		query.addHighlightField("item_title");
		query.setHighlightSimplePre("<div>");
		query.setHighlightSimplePost("</div>");
		//执行查询,得到一个Response对象
		QueryResponse resp = solrServer.query(query);
		//取查询结果
		SolrDocumentList resultList = resp.getResults();
		//取查询结果总记录数
		System.out.println("查询结果总记录数:" + resultList.getNumFound());
		for (SolrDocument solrDocument : resultList) {
			System.out.println(solrDocument.get("id"));
			//取高亮显示
			Map<String, Map<String, List<String>>> highlighting = resp.getHighlighting();
			List<String> list = highlighting.get(solrDocument.get("id")).get("item_title");
			//如果取到的高亮为空,则用原来的item_title,否则用高亮显示
			String item_title = "";
			if(list != null && list.size() > 0) {
				item_title = list.get(0);
			} else {
				item_title = (String) solrDocument.get("item_title");
			}
			System.out.println(item_title);
			System.out.println("===========================================================");
		}
	}
}

2. 集群搭建与测试

先新建个 solr-cloud 文件夹

sudo mkdir /usr/local/solr-cloud

2.1 zookeeper 集群搭建

这里使用的 zookeeper 版本是 3.4.6 高版本应该也是一样的,可以作参考。
解压 zookeeper 后,由于集群需要用 3 个 zookeeper,所以需要复制 3 份到/usr/local/solr-cloud 中

sudo cp -rf zookeeper-3.4.6 /usr/local/solr-cloud/zookeeper01
sudo cp -rf zookeeper-3.4.6 /usr/local/solr-cloud/zookeeper02
sudo cp -rf zookeeper-3.4.6 /usr/local/solr-cloud/zookeeper03

接下来进入 zookeeper 文件夹进行配置

cd /usr/local/solr-cloud/zookeeper01
sudo mkdir data
touch data/myid
vi 编译,里面只写 “1”

如下:

[llq@bogon data]$ cat myid 
1

创建完 data/myid 后,修改 conf/zoo.cfg 配置,如果没有 ,则用 conf 目录下的 zoo_sample.cfg 复制一个 zoo.cfg
修改里面内容如下:

dataDir=/usr/local/solr-cloud/zookeeper01/data/
clientPort=2181
在文件最后插入以下三行
server.1=192.168.200.128:2881:3881
server.2=192.168.200.128:2882:3882
server.3=192.168.200.128:2883:3883

这里要注意,2181 是客户端访问 zookeeper 的端口,2881 是 zookeeper 集群中 leader 和 follow 之间通信用的,3881 是集群节点间投票选举时用的端口。

zookeeper01 配置完了,另外两个也是同样配置,只改 myid 对应为 2 3, zoo.cfg 中,要改 dataDir 为对应目录,clientPort 也需要相应改为 2182 2183,下面的 server.1 2 3 就不需要改了,直接添加就行了。
也就是如下所示:

[llq@bogon solr-cloud]$ cat zookeeper01/data/myid 
1
[llq@bogon solr-cloud]$ cat zookeeper02/data/myid 
2
[llq@bogon solr-cloud]$ cat zookeeper03/data/myid 
3

由于 zoo.cfg 篇幅较大,这里只贴出 zookeeper03,看看就知道前面两个怎么配了。

# 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=/tmp/zookeeper
dataDir=/usr/local/solr-cloud/zookeeper03/data/
# the port at which the clients will connect
clientPort=2183
# 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.200.128:2881:3881
server.2=192.168.200.128:2882:3882
server.3=192.168.200.128:2883:3883

到这里已经配置好 zookeeper 集群了,现在写个脚本启动下这个集群

[llq@bogon solr-cloud]$ cat zookeeper-cmd.sh 
#!/bin/sh
if [ x"$1" = x ]; then
        echo "no cmd param!"
        exit 1
fi
if [ "$1" != start -a "$1" != stop -a "$1" != status ]; then
        echo "cmd not found!"
        exit 1
fi 
cd zookeeper01/bin
./zkServer.sh $1 
cd ../../
cd zookeeper02/bin
./zkServer.sh $1 
cd ../../
cd zookeeper03/bin
./zkServer.sh $1 
cd ../../

赋权,执行启动

sudo chmod +x zookeeper-cmd.sh
sudo ./zookeeper-cmd.sh start

[llq@bogon solr-cloud]$ sudo ./zookeeper-cmd.sh start
JMX enabled by default
Using config: /usr/local/solr-cloud/zookeeper01/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
JMX enabled by default
Using config: /usr/local/solr-cloud/zookeeper02/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
JMX enabled by default
Using config: /usr/local/solr-cloud/zookeeper03/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[llq@bogon solr-cloud]$ !ps
ps -ef | grep -i zook
root      45891      1  3 18:28 pts/3    00:00:00 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /usr/local/solr-cloud/zookeeper01/bin/../build/classes:/usr/local/solr-cloud/zookeeper01/bin/../build/lib/*.jar:/usr/local/solr-cloud/zookeeper01/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/solr-cloud/zookeeper01/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/solr-cloud/zookeeper01/bin/../lib/netty-3.7.0.Final.jar:/usr/local/solr-cloud/zookeeper01/bin/../lib/log4j-1.2.16.jar:/usr/local/solr-cloud/zookeeper01/bin/../lib/jline-0.9.94.jar:/usr/local/solr-cloud/zookeeper01/bin/../zookeeper-3.4.6.jar:/usr/local/solr-cloud/zookeeper01/bin/../src/java/lib/*.jar:/usr/local/solr-cloud/zookeeper01/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /usr/local/solr-cloud/zookeeper01/bin/../conf/zoo.cfg
root      45911      1  4 18:28 pts/3    00:00:00 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /usr/local/solr-cloud/zookeeper02/bin/../build/classes:/usr/local/solr-cloud/zookeeper02/bin/../build/lib/*.jar:/usr/local/solr-cloud/zookeeper02/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/solr-cloud/zookeeper02/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/solr-cloud/zookeeper02/bin/../lib/netty-3.7.0.Final.jar:/usr/local/solr-cloud/zookeeper02/bin/../lib/log4j-1.2.16.jar:/usr/local/solr-cloud/zookeeper02/bin/../lib/jline-0.9.94.jar:/usr/local/solr-cloud/zookeeper02/bin/../zookeeper-3.4.6.jar:/usr/local/solr-cloud/zookeeper02/bin/../src/java/lib/*.jar:/usr/local/solr-cloud/zookeeper02/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /usr/local/solr-cloud/zookeeper02/bin/../conf/zoo.cfg
root      45931      1  6 18:28 pts/3    00:00:00 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /usr/local/solr-cloud/zookeeper03/bin/../build/classes:/usr/local/solr-cloud/zookeeper03/bin/../build/lib/*.jar:/usr/local/solr-cloud/zookeeper03/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/solr-cloud/zookeeper03/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/solr-cloud/zookeeper03/bin/../lib/netty-3.7.0.Final.jar:/usr/local/solr-cloud/zookeeper03/bin/../lib/log4j-1.2.16.jar:/usr/local/solr-cloud/zookeeper03/bin/../lib/jline-0.9.94.jar:/usr/local/solr-cloud/zookeeper03/bin/../zookeeper-3.4.6.jar:/usr/local/solr-cloud/zookeeper03/bin/../src/java/lib/*.jar:/usr/local/solr-cloud/zookeeper03/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /usr/local/solr-cloud/zookeeper03/bin/../conf/zoo.cfg
llq       45943  45086  0 18:28 pts/3    00:00:00 grep -i zook
[llq@bogon solr-cloud]$ netstat -an | grep -i 218
tcp        0      0 192.168.200.128:54218       192.168.200.128:17006       ESTABLISHED 
tcp        0      0 192.168.200.128:17006       192.168.200.128:54218       ESTABLISHED 
tcp        0      0 :::2181                     :::*                        LISTEN      
tcp        0      0 :::2182                     :::*                        LISTEN      
tcp        0      0 :::2183                     :::*                        LISTEN

好了,启动成功了,进程也有了,端口监听也有了。
我们也可以去看看每个 zookeeper 的状态

[llq@bogon solr-cloud]$ sudo ./zookeeper-cmd.sh status
JMX enabled by default
Using config: /usr/local/solr-cloud/zookeeper01/bin/../conf/zoo.cfg
Mode: follower
JMX enabled by default
Using config: /usr/local/solr-cloud/zookeeper02/bin/../conf/zoo.cfg
Mode: leader
JMX enabled by default
Using config: /usr/local/solr-cloud/zookeeper03/bin/../conf/zoo.cfg
Mode: follower

我们可以看到他们选举了 zookeeper02 作为 leader 了

2.2 solr cloud 搭建

我们这里需要用到 4 个 solr 节点,也就是需要 4 个 tomcat 和 4 个 solrhome,每个节点的安装方式和单机类似,可以直接拷贝单机的过来改一下就行了。

我们先准备 4 个 tomcat,从我们单机版 solr 解压的 tomcat 拷贝到/usr/local/solr-cloud 下

sudo cp -rf apache-tomcat-7.0.47 /usr/local/solr-cloud/tomcat01
sudo cp -rf apache-tomcat-7.0.47 /usr/local/solr-cloud/tomcat02
sudo cp -rf apache-tomcat-7.0.47 /usr/local/solr-cloud/tomcat03
sudo cp -rf apache-tomcat-7.0.47 /usr/local/solr-cloud/tomcat04

接下来就改配置了

cd /usr/local/solr-cloud
sudo vim tomcat01/conf/server.xml

找到以下端口,改之前如下:

<Server port="8005" shutdown="SHUTDOWN">
<Connector port="8080" protocol="HTTP/1.1"
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

改之后如下:

<Server port="8105" shutdown="SHUTDOWN">
<Connector port="8180" protocol="HTTP/1.1"
<Connector port="8109" protocol="AJP/1.3" redirectPort="8443" />

四个 tomcat 都按上面改,每个 tomcat 的端口都不能重复,tomcat02 就是 8205,8280,8209,以此类推

tomcat 搞好之后,我们最好先把之前单机版的 tomcat 关掉,然后我们再把单机的 tomcat 解压的 solr 文件夹拷贝到这 4 台 tomcat 中

sudo /usr/local/solr/tomcat/bin/shutdown.sh
sudo cp -rf ../solr/tomcat/webapps/solr/ tomcat01/webapps/
sudo cp -rf ../solr/tomcat/webapps/solr/ tomcat02/webapps/
sudo cp -rf ../solr/tomcat/webapps/solr/ tomcat03/webapps/
sudo cp -rf ../solr/tomcat/webapps/solr/ tomcat04/webapps/

再把 solrhome 也拷贝四个

sudo cp -rf ../solr/solrhome/ solrhome01
sudo cp -rf ../solr/solrhome/ solrhome02
sudo cp -rf ../solr/solrhome/ solrhome03
sudo cp -rf ../solr/solrhome/ solrhome04


tomcat 和 solrhome 都准备好了之后,我们开始改配置。

sudo vi solrhome01/solr.xml

  <solrcloud>
	 <!-- 这个是tomcat01的ip -->
    <str name="host">192.168.200.128</str>
	<!-- 这个是tomcat01的端口 -->
    <int name="hostPort">8180</int>
    <str name="hostContext">${hostContext:solr}</str>
    <int name="zkClientTimeout">${zkClientTimeout:30000}</int>
    <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>
  </solrcloud>

只改两项,其它三个 tomcat 相应做修改。

solrhome 关联 tomcat 已经改了,tomcat 下的 solr 关联 solrhome 还没有,现在改

sudo vi tomcat01/webapps/solr/WEB-INF/web.xml

主要是修改单机时配置的 solrhome 目录,改为 solr-cloud 的 solrhome 目录

    <env-entry>
       <env-entry-name>solr/home</env-entry-name>
       <env-entry-value>/usr/local/solr-cloud/solrhome01</env-entry-value>
       <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>

另外三个 solr 的 web.xml 也是同样方式修改,每个 solrhome 要对应上。
好了,现在 solrhome 和 tomcat 之间都有联系了,现在就差与 zookeeper 挂上钩了。
现在需要在 tomcat 启动的时候加上-zkHost 的参数,在哪加呢,我们可以在 tomcat/bin 目录下的 catalina.sh 里的 JAVA_OPTS。

#   JAVA_OPTS       (Optional) Java runtime options used when any command
#                   is executed.
#                   Include here and not in CATALINA_OPTS all options, that
#                   should be used by Tomcat and also by the stop process,
#                   the version command etc.
#                   Most options should go into CATALINA_OPTS.

sudo vi tomcat01/bin/catalina.sh

搜索JAVA_OPTS,在下面位置添加一行JAVA_OPTS,配置-DzkHost
# Uncomment the following line to make the umask available when using the
# org.apache.catalina.security.SecurityListener
#JAVA_OPTS="$JAVA_OPTS -Dorg.apache.catalina.security.SecurityListener.UMASK=`umask`"
JAVA_OPTS="-DzkHost=192.168.200.128:2181,192.168.200.128:2182,192.168.200.128:2183"

好了,tomcat 和 zookeeper 的关联关系也配置好了。
接下来,我们还需要将任意一个 solrhome 的配置文件夹上传到 zookeeper,这样,当 solrcloud 启动的时候,就会自动从 zookeeper 上下载配置文件了,这样就实现了 zookeeper 统一管理配置文件了。

使用 solr 安装包里的脚本上传配置文件

cd solr-4.10.3/example/scripts/cloud-scripts
sudo ./zkcli.sh -zkhost 192.168.200.128:2181,192.168.200.128:2182,192.168.200.128:2183 -cmd upconfig -confdir /usr/local/solr-cloud/solrhome01/collection1/conf -confname myconf

刷一下屏之后就上传成功了。

[llq@bogon cloud-scripts]$ sudo ./zkcli.sh -zkhost 192.168.200.128:2181,192.168.200.128:2182,192.168.200.128:2183 -cmd upconfig -confdir /usr/local/solr-cloud/solrhome01/collection1/conf -confname myconf
INFO  - 2018-07-14 20:16:42.694; org.apache.zookeeper.Environment; Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
INFO  - 2018-07-14 20:16:42.699; org.apache.zookeeper.Environment; Client environment:host.name=<NA>
INFO  - 2018-07-14 20:16:42.702; org.apache.zookeeper.Environment; Client environment:java.version=1.8.0_151
INFO  - 2018-07-14 20:16:42.703; org.apache.zookeeper.Environment; Client environment:java.vendor=Oracle Corporation
INFO  - 2018-07-14 20:16:42.703; org.apache.zookeeper.Environment; Client environment:java.home=/usr/java/jdk1.8.0_151/jre
INFO  - 2018-07-14 20:16:42.704; org.apache.zookeeper.Environment; Client environment:java.class.path=./../../solr-webapp/webapp/WEB-INF/lib/hadoop-hdfs-2.2.0.jar:./../../solr-webapp/webapp/WEB-INF/lib/lucene-memory-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/lucene-analyzers-phonetic-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/httpcore-4.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/joda-time-2.2.jar:./../../solr-webapp/webapp/WEB-INF/lib/dom4j-1.6.1.jar:./../../solr-webapp/webapp/WEB-INF/lib/hadoop-common-2.2.0.jar:./../../solr-webapp/webapp/WEB-INF/lib/org.restlet.ext.servlet-2.1.1.jar:./../../solr-webapp/webapp/WEB-INF/lib/lucene-codecs-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/commons-configuration-1.6.jar:./../../solr-webapp/webapp/WEB-INF/lib/hadoop-annotations-2.2.0.jar:./../../solr-webapp/webapp/WEB-INF/lib/commons-fileupload-1.2.1.jar:./../../solr-webapp/webapp/WEB-INF/lib/protobuf-java-2.5.0.jar:./../../solr-webapp/webapp/WEB-INF/lib/lucene-highlighter-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/spatial4j-0.4.1.jar:./../../solr-webapp/webapp/WEB-INF/lib/zookeeper-3.4.6.jar:./../../solr-webapp/webapp/WEB-INF/lib/lucene-queryparser-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/commons-cli-1.2.jar:./../../solr-webapp/webapp/WEB-INF/lib/antlr-runtime-3.5.jar:./../../solr-webapp/webapp/WEB-INF/lib/concurrentlinkedhashmap-lru-1.2.jar:./../../solr-webapp/webapp/WEB-INF/lib/lucene-queries-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/lucene-misc-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/noggit-0.5.jar:./../../solr-webapp/webapp/WEB-INF/lib/wstx-asl-3.2.7.jar:./../../solr-webapp/webapp/WEB-INF/lib/hppc-0.5.2.jar:./../../solr-webapp/webapp/WEB-INF/lib/asm-commons-4.1.jar:./../../solr-webapp/webapp/WEB-INF/lib/commons-io-2.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/lucene-core-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/commons-codec-1.9.jar:./../../solr-webapp/webapp/WEB-INF/lib/httpclient-4.3.1.jar:./../../solr-webapp/webapp/WEB-INF/lib/lucene-analyzers-common-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/solr-core-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/guava-14.0.1.jar:./../../solr-webapp/webapp/WEB-INF/lib/commons-lang-2.6.jar:./../../solr-webapp/webapp/WEB-INF/lib/httpmime-4.3.1.jar:./../../solr-webapp/webapp/WEB-INF/lib/lucene-suggest-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/org.restlet-2.1.1.jar:./../../solr-webapp/webapp/WEB-INF/lib/hadoop-auth-2.2.0.jar:./../../solr-webapp/webapp/WEB-INF/lib/lucene-join-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/lucene-analyzers-kuromoji-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/lucene-grouping-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/lucene-spatial-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/solr-solrj-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/lucene-expressions-4.10.3.jar:./../../solr-webapp/webapp/WEB-INF/lib/asm-4.1.jar:./../../lib/ext/log4j-1.2.17.jar:./../../lib/ext/jul-to-slf4j-1.7.6.jar:./../../lib/ext/slf4j-log4j12-1.7.6.jar:./../../lib/ext/jcl-over-slf4j-1.7.6.jar:./../../lib/ext/slf4j-api-1.7.6.jar
INFO  - 2018-07-14 20:16:42.704; org.apache.zookeeper.Environment; Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
INFO  - 2018-07-14 20:16:42.705; org.apache.zookeeper.Environment; Client environment:java.io.tmpdir=/tmp
INFO  - 2018-07-14 20:16:42.705; org.apache.zookeeper.Environment; Client environment:java.compiler=<NA>
INFO  - 2018-07-14 20:16:42.706; org.apache.zookeeper.Environment; Client environment:os.name=Linux
INFO  - 2018-07-14 20:16:42.706; org.apache.zookeeper.Environment; Client environment:os.arch=amd64
INFO  - 2018-07-14 20:16:42.706; org.apache.zookeeper.Environment; Client environment:os.version=2.6.32-696.el6.x86_64
INFO  - 2018-07-14 20:16:42.706; org.apache.zookeeper.Environment; Client environment:user.name=root
INFO  - 2018-07-14 20:16:42.706; org.apache.zookeeper.Environment; Client environment:user.home=/root
INFO  - 2018-07-14 20:16:42.706; org.apache.zookeeper.Environment; Client environment:user.dir=/home/llq/developer/solr-4.10.3/example/scripts/cloud-scripts
INFO  - 2018-07-14 20:16:42.708; org.apache.zookeeper.ZooKeeper; Initiating client connection, connectString=192.168.200.128:2181,192.168.200.128:2182,192.168.200.128:2183 sessionTimeout=30000 watcher=org.apache.solr.common.cloud.ConnectionManager@762efe5d
INFO  - 2018-07-14 20:16:42.731; org.apache.solr.common.cloud.ConnectionManager; Waiting for client to connect to ZooKeeper
INFO  - 2018-07-14 20:16:42.737; org.apache.zookeeper.ClientCnxn$SendThread; Opening socket connection to server 192.168.200.128/192.168.200.128:2181. Will not attempt to authenticate using SASL (unknown error)
INFO  - 2018-07-14 20:16:42.871; org.apache.zookeeper.ClientCnxn$SendThread; Socket connection established to 192.168.200.128/192.168.200.128:2181, initiating session
INFO  - 2018-07-14 20:16:42.890; org.apache.zookeeper.ClientCnxn$SendThread; Session establishment complete on server 192.168.200.128/192.168.200.128:2181, sessionid = 0x1649855c46a0001, negotiated timeout = 30000
INFO  - 2018-07-14 20:16:42.894; org.apache.solr.common.cloud.ConnectionManager; Watcher org.apache.solr.common.cloud.ConnectionManager@762efe5d name:ZooKeeperConnection Watcher:192.168.200.128:2181,192.168.200.128:2182,192.168.200.128:2183 got event WatchedEvent state:SyncConnected type:None path:null path:null type:None
INFO  - 2018-07-14 20:16:42.895; org.apache.solr.common.cloud.ConnectionManager; Client is connected to ZooKeeper
INFO  - 2018-07-14 20:16:42.930; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/_schema_analysis_stopwords_english.json
INFO  - 2018-07-14 20:16:43.010; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/update-script.js
INFO  - 2018-07-14 20:16:43.024; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/protwords.txt
INFO  - 2018-07-14 20:16:43.039; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/mapping-ISOLatin1Accent.txt
INFO  - 2018-07-14 20:16:43.052; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/spellings.txt
INFO  - 2018-07-14 20:16:43.063; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/_rest_managed.json
INFO  - 2018-07-14 20:16:43.070; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/stopwords.txt
INFO  - 2018-07-14 20:16:43.082; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/admin-extra.menu-top.html
INFO  - 2018-07-14 20:16:43.094; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/synonyms.txt
INFO  - 2018-07-14 20:16:43.102; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/mapping-FoldToASCII.txt
INFO  - 2018-07-14 20:16:43.138; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/currency.xml
INFO  - 2018-07-14 20:16:43.151; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/schema.xml
INFO  - 2018-07-14 20:16:43.168; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/_schema_analysis_synonyms_english.json
INFO  - 2018-07-14 20:16:43.176; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/scripts.conf
INFO  - 2018-07-14 20:16:43.187; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/contractions_it.txt
INFO  - 2018-07-14 20:16:43.203; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_lv.txt
INFO  - 2018-07-14 20:16:43.215; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_nl.txt
INFO  - 2018-07-14 20:16:43.231; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_fi.txt
INFO  - 2018-07-14 20:16:43.238; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_fr.txt
INFO  - 2018-07-14 20:16:43.255; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stoptags_ja.txt
INFO  - 2018-07-14 20:16:43.264; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_de.txt
INFO  - 2018-07-14 20:16:43.272; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_fa.txt
INFO  - 2018-07-14 20:16:43.292; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/contractions_ga.txt
INFO  - 2018-07-14 20:16:43.305; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_hu.txt
INFO  - 2018-07-14 20:16:43.313; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/userdict_ja.txt
INFO  - 2018-07-14 20:16:43.327; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_ar.txt
INFO  - 2018-07-14 20:16:43.337; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_bg.txt
INFO  - 2018-07-14 20:16:43.350; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_id.txt
INFO  - 2018-07-14 20:16:43.362; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_cz.txt
INFO  - 2018-07-14 20:16:43.375; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stemdict_nl.txt
INFO  - 2018-07-14 20:16:43.390; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/contractions_fr.txt
INFO  - 2018-07-14 20:16:43.402; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_th.txt
INFO  - 2018-07-14 20:16:43.414; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_eu.txt
INFO  - 2018-07-14 20:16:43.427; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_en.txt
INFO  - 2018-07-14 20:16:43.436; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/contractions_ca.txt
INFO  - 2018-07-14 20:16:43.443; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_da.txt
INFO  - 2018-07-14 20:16:43.456; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_tr.txt
INFO  - 2018-07-14 20:16:43.482; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_hi.txt
INFO  - 2018-07-14 20:16:43.490; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_ja.txt
INFO  - 2018-07-14 20:16:43.497; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_ckb.txt
INFO  - 2018-07-14 20:16:43.511; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_hy.txt
INFO  - 2018-07-14 20:16:43.516; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_es.txt
INFO  - 2018-07-14 20:16:43.526; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_no.txt
INFO  - 2018-07-14 20:16:43.541; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_sv.txt
INFO  - 2018-07-14 20:16:43.549; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_it.txt
INFO  - 2018-07-14 20:16:43.559; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_el.txt
INFO  - 2018-07-14 20:16:43.566; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_gl.txt
INFO  - 2018-07-14 20:16:43.577; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_ru.txt
INFO  - 2018-07-14 20:16:43.586; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_ro.txt
INFO  - 2018-07-14 20:16:43.594; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_pt.txt
INFO  - 2018-07-14 20:16:43.609; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_ga.txt
INFO  - 2018-07-14 20:16:43.614; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/stopwords_ca.txt
INFO  - 2018-07-14 20:16:43.625; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/lang/hyphenations_ga.txt
INFO  - 2018-07-14 20:16:43.629; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/admin-extra.menu-bottom.html
INFO  - 2018-07-14 20:16:43.636; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/clustering/carrot2/stc-attributes.xml
INFO  - 2018-07-14 20:16:43.667; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/clustering/carrot2/lingo-attributes.xml
INFO  - 2018-07-14 20:16:43.681; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/clustering/carrot2/kmeans-attributes.xml
INFO  - 2018-07-14 20:16:43.691; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/solrconfig.xml
INFO  - 2018-07-14 20:16:43.701; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/query_spatial.vm
INFO  - 2018-07-14 20:16:43.713; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/head.vm
INFO  - 2018-07-14 20:16:43.720; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/facet_queries.vm
INFO  - 2018-07-14 20:16:43.728; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/facet_fields.vm
INFO  - 2018-07-14 20:16:43.732; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/cluster.vm
INFO  - 2018-07-14 20:16:43.742; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/richtext_doc.vm
INFO  - 2018-07-14 20:16:43.749; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/error.vm
INFO  - 2018-07-14 20:16:43.757; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/query.vm
INFO  - 2018-07-14 20:16:43.764; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/cluster_results.vm
INFO  - 2018-07-14 20:16:43.768; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/hit_grouped.vm
INFO  - 2018-07-14 20:16:43.776; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/did_you_mean.vm
INFO  - 2018-07-14 20:16:43.782; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/hit_plain.vm
INFO  - 2018-07-14 20:16:43.797; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/browse.vm
INFO  - 2018-07-14 20:16:43.803; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/query_group.vm
INFO  - 2018-07-14 20:16:43.810; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/README.txt
INFO  - 2018-07-14 20:16:43.820; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/tabs.vm
INFO  - 2018-07-14 20:16:43.828; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/footer.vm
INFO  - 2018-07-14 20:16:43.835; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/layout.vm
INFO  - 2018-07-14 20:16:43.839; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/facets.vm
INFO  - 2018-07-14 20:16:43.849; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/pagination_bottom.vm
INFO  - 2018-07-14 20:16:43.859; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/join_doc.vm
INFO  - 2018-07-14 20:16:43.875; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/debug.vm
INFO  - 2018-07-14 20:16:43.895; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/jquery.autocomplete.css
INFO  - 2018-07-14 20:16:43.904; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/facet_pivot.vm
INFO  - 2018-07-14 20:16:43.918; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/header.vm
INFO  - 2018-07-14 20:16:43.926; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/product_doc.vm
INFO  - 2018-07-14 20:16:43.931; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/main.css
INFO  - 2018-07-14 20:16:43.947; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/jquery.autocomplete.js
INFO  - 2018-07-14 20:16:43.959; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/suggest.vm
INFO  - 2018-07-14 20:16:43.969; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/results_list.vm
INFO  - 2018-07-14 20:16:43.981; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/mime_type_lists.vm
INFO  - 2018-07-14 20:16:43.985; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/query_form.vm
INFO  - 2018-07-14 20:16:43.998; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/pagination_top.vm
INFO  - 2018-07-14 20:16:44.003; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/VM_global_library.vm
INFO  - 2018-07-14 20:16:44.018; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/facet_ranges.vm
INFO  - 2018-07-14 20:16:44.022; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/velocity/hit.vm
INFO  - 2018-07-14 20:16:44.031; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/elevate.xml
INFO  - 2018-07-14 20:16:44.041; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/xslt/updateXml.xsl
INFO  - 2018-07-14 20:16:44.057; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/xslt/example_rss.xsl
INFO  - 2018-07-14 20:16:44.063; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/xslt/luke.xsl
INFO  - 2018-07-14 20:16:44.072; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/xslt/example_atom.xsl
INFO  - 2018-07-14 20:16:44.082; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/xslt/example.xsl
INFO  - 2018-07-14 20:16:44.089; org.apache.solr.common.cloud.SolrZkClient; makePath: /configs/myconf/admin-extra.html
INFO  - 2018-07-14 20:16:44.101; org.apache.zookeeper.ZooKeeper; Session: 0x1649855c46a0001 closed

接下来,我们检查下上传成功没有

cd /usr/local/solr-cloud/zookeeper01/bin
sudo ./zkCli.sh 或者指定 zookeeper,如下:
sudo ./zkCli.sh -server 192.168.200.128:2182

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] ls
[zk: localhost:2181(CONNECTED) 1] ls
[zk: localhost:2181(CONNECTED) 2] ls /
[configs, zookeeper]
[zk: localhost:2181(CONNECTED) 3] ls /configs
[myconf]
[zk: localhost:2181(CONNECTED) 4] ls /configs/myconf
[mapping-FoldToASCII.txt, currency.xml, protwords.txt, synonyms.txt, scripts.conf, stopwords.txt, _schema_analysis_synonyms_english.json, velocity, admin-extra.html, update-script.js, _schema_analysis_stopwords_english.json, solrconfig.xml, admin-extra.menu-top.html, elevate.xml, schema.xml, clustering, mapping-ISOLatin1Accent.txt, spellings.txt, _rest_managed.json, xslt, lang, admin-extra.menu-bottom.html]
[zk: localhost:2181(CONNECTED) 5] quit
Quitting...
2018-07-14 20:20:56,838 [myid:] - INFO  [main:ZooKeeper@684] - Session: 0x1649855c46a0002 closed
2018-07-14 20:20:56,839 [myid:] - INFO  [main-EventThread:ClientCnxn$EventThread@512] - EventThread shut down

通过 ls 命令就可以查看当前 zookeeper 管理的配置了。能看到 myconf 里的文件就是 solrhome 配置目录下的文件,上传成功了。

现在就可以写脚本启动 tomcat 了。

cd /usr/local/solr-cloud
sudo vi tomcat-cmd.sh

#!/bin/sh
if [ x"$1" = x ]; then
        echo "no cmd param!"
        exit 1
fi
if [ "$1" != start -a "$1" != stop ]; then
        echo "cmd not found!"
        exit 1
fi
if [ "$1" = start ]; then
        /usr/local/solr-cloud/tomcat01/bin/startup.sh
        /usr/local/solr-cloud/tomcat02/bin/startup.sh
        /usr/local/solr-cloud/tomcat03/bin/startup.sh
        /usr/local/solr-cloud/tomcat04/bin/startup.sh
fi
if [ "$1" = stop ]; then
        /usr/local/solr-cloud/tomcat01/bin/shutdown.sh
        /usr/local/solr-cloud/tomcat02/bin/shutdown.sh
        /usr/local/solr-cloud/tomcat03/bin/shutdown.sh
        /usr/local/solr-cloud/tomcat04/bin/shutdown.sh
fi

好了,我们赋权启动吧。

sudo chmod +x tomcat-cmd.sh
sudo ./tomcat-cmd.sh

跟单机一样,我们可以看看日志,确认是否已经启动,启动完之后,我们可能还要再配置一下防火墙。

与单机一样改同样的配置,加上以下内容即可。

-A INPUT -p tcp -m state --state NEW -m tcp --dport 2182 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 2183 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8180 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8280 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8380 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8480 -j ACCEPT

重启防火墙。

2.3 验证测试

2.3.1 页面验证

我们登陆任意一个 solr 的控制台
http://192.168.200.128:8180/solr/#/
可以看到里面多了个 cloud,点进去,可以看到如下图片内容:
solrJPG
从图中可以看到,8480 的 tomcat 为 leader.

但是这个还不是个合理的集群,这里应该是一个 collection 下有两个 share,每个 share 下还要有两个节点,一主一备。
我们使用 solr URL 修改一下。

http://192.168.200.128:8180/solr/admin/collections?action=CREATE&name=collection2&numShards=2&replicationFactor=2

在浏览器输入以上 URL,加载之后,等待返回成功提示:

name="success">

我们再进入 solr 控制台的 cloud 看看效果
solr2JPG

我们现在有个 collection2 符合我们要求了,我们可以把 collection1 删掉了。同样用 URL 命令

http://192.168.200.128:8180/solr/admin/collections?action=DELETE&name=collection1

执行完再刷新一下 cloud,就只剩 collection2 了。

现在可以继续像单机一样,测试一下分词功能是否正常可用。

2.3.2 代码测试

	@Test
	public void testAddDocument() throws Exception {
		//创建一个CloudSolrServer对象,构造方法中需要传入zookeeper的地址列表
		CloudSolrServer cloudSolrServer = new CloudSolrServer("192.168.200.128:2181,192.168.200.128:2182,192.168.200.128:2183");
		//设置默认的collection
		cloudSolrServer.setDefaultCollection("collection2");
		//创建一个文档对象SolrInputDocument
		SolrInputDocument doc = new SolrInputDocument();
		//向文档中添加域,必须有id域,域的名称必须在schema.xml中定义
		doc.addField("id", "test001");
		doc.addField("item_title", "测试商品2");
		//写入索引数据库
		cloudSolrServer.add(doc);
		//提交
		cloudSolrServer.commit();
	}

执行完后,其实可以在 solr 的 Query 页面查询,
q 栏上填“测试”,df 栏上填"item_title",执行查询就可以查到了。

{ "responseHeader": { "status": 0, "QTime": 885, "params": { "q": "测试", "df": "item_title", "indent": "true", "wt": "json", "_": "1531575293854" } }, "response": { "numFound": 1, "start": 0, "maxScore": 0.15342641, "docs": [ { "id": "test001", "item_title": "测试商品2", "_version_": 1605973005675004000 } ] } }

查询的测试代码类似,只有创建的 solrServer 对象改为 CloudSolrServer 对象。

终于写完了。
腰酸背痛的。休息去咯。

  • Solr
    16 引用 • 22 回帖 • 1 关注
  • Tomcat

    Tomcat 最早是由 Sun Microsystems 开发的一个 Servlet 容器,在 1999 年被捐献给 ASF(Apache Software Foundation),隶属于 Jakarta 项目,现在已经独立为一个顶级项目。Tomcat 主要实现了 JavaEE 中的 Servlet、JSP 规范,同时也提供 HTTP 服务,是市场上非常流行的 Java Web 容器。

    162 引用 • 529 回帖 • 1 关注
  • 集群
    29 引用 • 65 回帖 • 1 关注

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...
  • alanfans

    休息一个小时了,隔壁老王可不休息。

  • someone

    😂 😂 带娃的时候,感觉专心写东西好难