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名稱相同.