solr_solrcloud创建core及collection

① 使用命令创建core

su -c ‘/usr/local/solr/bin/solr create -c core_bingdu -d /opt/core_bingdu_conf -n core_bingdu -s 3 -rf 2 -port 8983‘ - solr

如果zookeeper管理的集群上面仅有一份配置,那么创建的core都会用这份默认的配置。如果有多份,如果没有执行第6步,随便创建一个core将抛出异常,构建失败!


2) 创建一个collection

 可以使用命令创建,也可以使用api创建

① 使用api创建:

http://192.168.75.102:8983/solr/admin/collections?action=CREATE&name=harvewificollection&numShards=2&replicationFactor=2&maxShardsPerNode=2&collection.configName=harvewifi

name:collection(索引)名称

numShards:分片数

replicationFactor:每个分片的复本数

maxShardsPerNode:每个Solr服务器节点上最大分片数(Solr 4.2新增)

collection.configName:使用的配置文件名

页面输出:

<?xml version="1.0" encoding="UTF-8" ?> 

- <response>

- <lst name="responseHeader">

  <int name="status">0</int> 

  <int name="QTime">17554</int> 

  </lst>

- <lst name="success">

- <lst name="192.168.75.103:8983_solr">

- <lst name="responseHeader">

  <int name="status">0</int> 

  <int name="QTime">7892</int> 

  </lst>

  <str name="core">harvewificollection_shard1_replica2</str> 

  </lst>

- <lst name="192.168.75.103:8983_solr">

- <lst name="responseHeader">

  <int name="status">0</int> 

  <int name="QTime">8027</int> 

  </lst>

  <str name="core">harvewificollection_shard2_replica2</str> 

  </lst>

- <lst name="192.168.75.102:8983_solr">

- <lst name="responseHeader">

  <int name="status">0</int> 

  <int name="QTime">8553</int> 

  </lst>

  <str name="core">harvewificollection_shard2_replica1</str> 

  </lst>

- <lst name="192.168.75.102:8983_solr">

- <lst name="responseHeader">

  <int name="status">0</int> 

  <int name="QTime">8641</int> 

  </lst>

  <str name="core">harvewificollection_shard1_replica1</str> 

  </lst>

  </lst>

  </response>

生成了两个core

 

 

 

② 使用命令创建

solr create -c testcollection2 -d /opt/solrcloud/config-harvewifi -s 2 -rf 2 -n testcollection2conf 

此处略

 

③ 在页面创建

 

没有什么命名要求,直接创建就成功了,默认一个分片。

在另一台机器上也创建一个,其他内容一样,只是shard改名为2

 

添加数据,在另一台机器中能查到,集群成功。

 

网上有说创建core的名称配置文件名称一致才可以,否则会报异常:
org.apache.solr.common.cloud.ZooKeeperException:org.apache.solr.common.cloud.ZooKeeperException: Could not find configName for collection rss found:[solrConfig]

 

但是上面却没有问题,只能猜测,因为现在zk中只有一份配置文件 ,因此就使用它了。如果有两个配置文件,是否还能成功呢?试一下:
config添加到zk中,结果如下:

 

现在有两个config名称了,再来创建一个collection

 

创建失败了,提示找不到配置文件。需要将collection改名为:solrConfig

在另一台机器上也创建一个core名不同,但collection也为solrConfig的索引

 

结果如下:

 

集群创建成功.

结论: zk中有多个config,创建的collection名称需和其中一个config名称相同.