---
title: "windows下solr6的solrcloud使用"
author: "theseus"
date: "2016-10-12T12:01:49Z"
tags: []
categories: ["开源软件"]
slug: "windows-solr6-solrcloud"
draft: false
lastmod: "2016-10-14T10:36:03Z"
id: 2330058
url: "https://theseus.iteye.com/blog/2330058"
---

solr版本：solr-6.0.1

**本地启动solr的集群，根据官方手册指导执行以下命令**

D:\\solr-6.0.1\\bin&gt;solr.cmd -e cloud

该命令将默认启动两个端口的solr实例，8983,7574，同时启动内置的zookeeper服务，默认端口为9983.

控制台输出信息：

Welcome to the SolrCloud example!

This interactive session will help you launch a SolrCloud cluster on your local

workstation.

To begin, how many Solr nodes would you like to run in your local cluster? (spec

ify 1-4 nodes) \[2]:        

Ok, let's start up 2 Solr nodes for your example SolrCloud cluster.

Please enter the port for node1 \[8983]:

Please enter the port for node2 \[7574]:

**接着自动创建两个节点，其路径为：**

Creating Solr home directory D:\\solr-6.0.1\\example\\cloud\\node1\\solr

Cloning D:\\solr-6.0.1\\example\\cloud\\node1 into  D:\\solr-6.0.1\\example\\cloud\\node2

**节点启动命令为：**

    Starting up Solr on port 8983 using command:

D:\\solr-6.0.1\\bin\\solr.cmd start -cloud -p 8983 -s "D:\\solr-6.0.1\\example\\cloud\\node1\\solr"

Waiting up to 30 to see Solr running on port 8983 

Starting up Solr on port 7574 using command:

D:\\solr-6.0.1\\bin\\solr.cmd start -cloud -p 7574 -s "D:\\solr-6.0.1\\example\\cloud\\

node2\\solr" -z localhost:9983

**默认的分片值为2，每个分片2个节点**

How many shards would you like to split gettingstarted into? \[2]

2

How many replicas per shard would you like to create? \[2]

2

**创建solr配置，默认名称为：gettingstarted，配置文件可以从**

basic\_configs, data\_driven\_schema\_configs, or sample\_techproducts\_configs [data_

driven\_schema\_configs]中选择，默认为data\_driven\_schema\_configs

**上传配置到zookeeper，其路径为：/configs/gettingstarted**

**可通过zk客户端脚本连接查看：**

D:\\zookeeper-3.4.8\\bin&gt;zkCli.cmd -server localhost:9983

\[zk: localhost:9983(CONNECTED) 1] ls /configs/gettingstarted/

 

currency.xml         managed-schema       protwords.txt

solrconfig.xml       synonyms.txt         elevate.xml

configoverlay.json   stopwords.txt        lang

params.json

**等待创建名为gettingstarted的collection**

Creating new collection 'gettingstarted' using command:

http://localhost:8983/solr/admin/collections?action=CREATE&name=gettingstarted&n

umShards=2&replicationFactor=2&maxShardsPerNode=2&collection.configName=gettings

tarted

 

{

  "responseHeader":{

    "status":0,

    "QTime":17386},

  "success":{

    "127.0.0.1:8983\_solr":{

      "responseHeader":{

        "status":0,

        "QTime":7119},

      "core":"gettingstarted\_shard1\_replica2"},

    "127.0.0.1:7574\_solr":{

      "responseHeader":{

        "status":0,

        "QTime":7400},

      "core":"gettingstarted\_shard1\_replica1"}}}

**完成后可以在浏览器输入[http://localhost:8983/solr](http://localhost:8983/solr)查看结果**

![](http://dl2.iteye.com/upload/attachment/0120/5738/680a371c-8634-39ec-ae3c-bcac8192c89d.png)  
   
 

**为分片增加节点**

在D:\\solr-6.0.1\\example\\cloud路径下创建node3\\solr文件夹，复制D:\\solr-6.0.1\\server\\solr下的solr.xml文件到node3\\solr下，启动该节点实例：

D:\\solr-6.0.1&gt;bin\\solr.cmd -cloud -s example\\cloud\\node3\\solr -p 8987 -z localhost:9983

Waiting up to 30 to see Solr running on port 8987

Started Solr server on port 8987. Happy searching!

做collection菜单中即可对分片添加活动节点，如图所示

![](http://dl2.iteye.com/upload/attachment/0120/5740/cf68bdfa-20b6-3f59-8550-75d4f16b17e8.png)  
   
 

添加后的结果为：

![](http://dl2.iteye.com/upload/attachment/0120/5742/c187a943-1978-3886-954d-6db021493ce7.png)  
   
 

另外一个分片操作相同。

**创建新的配置**

上传配置文件到zookeeper，可以使用solr的zkcli脚本，windows操作如下：新建名为test的配置，使用D:\\solr-6.0.1\\server\\solr\\configsets\\basic\_configs下的配置文件

**D:\\solr-6.0.1\\server\\scripts\\cloud-scripts&gt;zkcli.bat -cmd upconfig -zkhost local**

**host:9983 -confname test -confdir ..\\..\\solr\\configsets\\basic\_configs\\conf**

执行命令后，新建名为test的配置

**\[zk: localhost:9983(CONNECTED) 3] ls /configs/test**

[currency.xml, managed-schema, protwords.txt, solrconfig.xml, synonyms.txt, stop

words.txt, \_rest\_managed.json, lang]

新建collection，如图

![](http://dl2.iteye.com/upload/attachment/0120/5744/3dfe5990-bacf-3278-8e8f-76d1139ac886.png)  
   
 

         创建成功后如下：

 

![](http://dl2.iteye.com/upload/attachment/0120/5746/9d225dee-e891-3659-bcd4-566d86ea57f6.png)