1.登陸solr其中一個實例所在的主機apache
2.生成配置文件
$ solrctl instancedir --generate $HOME/solr_configs
修改solrconfig.xml 和 schema.xml
3.上傳配置到zk
$ solrctl instancedir --create <collection_name> $HOME/solr_configs
查看
$ solrctl instancedir --list
4.建立collectionsbash
隱式路由
$ solrctl collection --create <collection_name> -s <shard_count> -r <replica_count> -m <count>服務器
solrctl instancedir --generate $HOME/suggest solrctl instancedir --create suggest $HOME/suggest solrctl collection --create suggest -s 2 -r 2 -m 2 solrctl instancedir --update suggest $HOME/suggest solrctl collection --reload suggest
或者:code
顯式路由的router
http://10.90.16.156:8983/solr/admin/collections?action=CREATE&name=goods&router.name=implicit&shards=shard1&replicationFactor=2&router.field=category&maxShardsPerNode=2xml
maxShardsPerNode默認爲1,須要根據實際狀況調整,若是隻有2臺服務器,那麼會出現以下錯誤:blog
<?xml version="1.0" encoding="UTF-8" ?> <response> <lst name="responseHeader"> <int name="status">400</int> <int name="QTime">25</int> </lst> <str name="Operation createshard caused exception:">org.apache.solr.common.SolrException:org.apache.solr.common.SolrException: Cannot create collection goods. No live Solr-instances</str> <lst name="exception"> <str name="msg">Cannot create collection goods. No live Solr-instances</str> <int name="rspCode">400</int> </lst> <lst name="error"> <lst name="metadata"> <str name="error-class">org.apache.solr.common.SolrException</str> <str name="root-error-class">org.apache.solr.common.SolrException</str> </lst> <str name="msg">Cannot create collection goods. No live Solr-instances</str> <int name="code">400</int> </lst> </response>
5.增長shardci
http://10.90.16.156:8983/solr/admin/collections?action=CREATESHARD&shard=shard2&collection=goods&replicationFactor=2路由