---
title: "SolrCloud 动态扩容方案"
author: "rayoo"
date: "2015-06-04T16:57:46Z"
tags: []
categories: ["开源软件"]
slug: "solrcloud"
draft: false
lastmod: "2015-06-24T17:56:32Z"
id: 2217076
url: "https://rayoo.iteye.com/blog/2217076"
---

SolrCloud 动态扩容方案

 

**1:改变id的hash策略**

 

使用 implicit 路由,参加: http://www.cnblogs.com/rcfeng/p/4287031.html

 当没有匹配的shards时, 数据将会集中到一个shard

 

http://172.28.4.83:11010/solr/admin/collections?action=CREATE&name=post&router.name=implicit&shards=shard1,shard2,shard3&replicationFactor=3&maxShardsPerNode=1&collection.configName=post&router.field=objectType&async=110

 

http://172.28.4.83:11010/solr/admin/collections?action=REQUESTSTATUS&requestid=110

 

http://172.28.4.83:11060/solr/post\_shard2\_replica1/select?q=\*%3A\*&shards.info=true&shards.tolerant=true&shards=http://172.28.4.83:11050/solr/post\_shard1\_replica1

 

 

http://172.28.4.83:11060/solr/post\_shard2\_replica1/select?q=\*%3A\*&shards.info=true&shards.tolerant=true&shards=http://172.28.4.84:11090/solr/post\_shard2\_replica2

 

 

http://172.28.4.83:11060/solr/post\_shard2\_replica1/select?q=\*%3A\*&shards.info=true&shards.tolerant=true&shards=http://172.28.4.83:11040/solr/post\_shard3\_replica1

 

2:更改别名

 collection1 1---500万  
collection2 500---1000万  
alias:collection{collection1,collection2}  
collection3 1000---1500万  
alias:collection{collection1,collection2,collection3}

 

3:增加shard及拆分shard

发现问题:在内存溢出时, 无法继续,新增的shards一直处于construction状态,使用delete shards命令删不掉:

解决办法:

使用CoreAdmin API 去UNLOAD,注意不能使用 Collections API 去调用

http://172.28.4.83:11070/solr/admin/cores?action=UNLOAD&core=common\_shard1\_1\_replica1&deleteIndex=true&deleteDataDir=true&deleteInstanceDir=true&async=3

http://172.28.4.83:11070/solr/admin/cores?action=REQUESTSTATUS&requestid=3

 

http://172.28.4.83:11010/solr/admin/collections?action=DELETESHARD&shard=shard1\_0&collection=*common*

 

4:重建索引

 新建一个SolrCloud，新的索引好了再切到新的上面

重建索引是指从 DB 中完全导入到新的SolrCloud中