SolrCloud Collection 创建

环境版本: CDH 5.12.0; Solr 4.10.3


CDH搭建SolrCloud集群十分方便,添加服务->solr->选择主机->next即可

在SolrCloud中,跨多个节点的索引分割称为集合(collection),见下图:

这里写图片描述


[root@DXHY-YFEB-01 solr]# pwd
/var/lib/solr
[root@DXHY-YFEB-01 solr]# mv Invoice_bak/ test_invoice
[root@DXHY-YFEB-01 solr]# ls

#创建 collection 实例并将配置文件上传到 zookeeper
[root@DXHY-YFEB-01 solr]# solrctl instancedir --create test_invoice ./test_invoice

#在Zookeeper查看配置文件
[root@DXHY-YFEB-01 solr]# zookeeper-client
[zk: localhost:2181(CONNECTED) 1] ls /solr
[configs, overseer, aliases.json, live_nodes, collections, overseer_elect, clusterstate.json, solr.xml, zkdtsm, clusterprops.json, token]
[zk: localhost:2181(CONNECTED) 2] ls /solr/configs
[realestate, schemalessTemplateSecure, managedTemplate, schemalessTemplate, predefinedTemplate, managedTemplateSecure, predefinedTemplateSecure, test_invoice]

#查看上传的实体
[root@DXHY-YFEB-01 solr]# solrctl instancedir --list 
managedTemplate
managedTemplateSecure
predefinedTemplate
predefinedTemplateSecure
realestate
schemalessTemplate
schemalessTemplateSecure
solrtest
test_invoice

#创建 collection
[root@DXHY-YFEB-01 solr]# solrctl collection --create test_invoice -s 2 -c test_invoice -r 2 -m 3
#如果新集合可以使用与现有集合一样的配置文件,不需重新复制上传
[root@DXHY-YFEB-01 solr]# solrctl collection --create test_invoice2 -s 2 -c test_invoice -r 2 -m 3
#-c   -s   -r   -m 
#注意:numShards*replicationFactor <= maxShardsPerNode*numNode

#更新配置,更新后新建的索引会按更新后的配置创建,之前的不变。
[root@DXHY-YFEB-01 solr-doc-4.10.3+cdh5.12.0+513]# solrctl instancedir --update test_invoice ./test_invoice
Uploading configs from ./realestate/conf to DXHY-YFEB-03:2181,DXHY-YFEB-01:2181,DXHY-YFEB-02:2181/solr. This may take up to a minute.
[root@DXHY-YFEB-01 solr-doc-4.10.3+cdh5.12.0+513]# solrctl collection --reload test_invoice

这里写图片描述


Solr5 Collection的创建
注意:solr5弃用了solr4的很多字段类型,solrconfig.xml配置也不一样,需修改schema.xml与solrconfig.xml文件

[root@Slave1 bin]# ./solr create_collection -c test_invoice -d ../server/solr/configsets/Invoice_bak/ -s 2 -replicationFactor 2

Connecting to ZooKeeper at slave2.hadoop:2181,slave3.hadoop:2181,slave1.hadoop:2181/solr ...
Uploading /opt/solr/solr-5.3.0/bin/../server/solr/configsets/Invoice_bak/conf for config test_invoice to ZooKeeper at slave2.hadoop:2181,slave3.hadoop:2181,slave1.hadoop:2181/solr

Creating new collection 'test_invoice' using command:
http://localhost:8983/solr/admin/collections?action=CREATE&name=test_invoice&numShards=2&replicationFactor=2&maxShardsPerNode=2&collection.configName=test_invoice

{
  "responseHeader":{
    "status":0,
    "QTime":3678},
  "success":{"":{
      "responseHeader":{
        "status":0,
        "QTime":3508},
      "core":"test_invoice_shard1_replica1"}}}

这里写图片描述

[root@Slave1 bin]# ./solr create_collection -help

Usage: solr create_collection [-c collection] [-d confdir] [-n configName] [-shards #] [-replicationFactor #] [-p port]

  -c          Name of collection to create

  -d             Configuration directory to copy when creating the new collection, built-in options are:

      basic_configs: Minimal Solr configuration
      data_driven_schema_configs: Managed schema with field-guessing support enabled
      sample_techproducts_configs: Example configuration with many optional features enabled to
         demonstrate the full power of Solr

      If not specified, default is: data_driven_schema_configs

      Alternatively, you can pass the path to your own configuration directory instead of using
      one of the built-in configurations, such as: bin/solr create_collection -c mycoll -d /tmp/myconfig

      By default the script will upload the specified confdir directory into ZooKeeper using the same
      name as the collection (-c) option. Alternatively, if you want to reuse an existing directory
      or create a confdir in ZooKeeper that can be shared by multiple collections, use the -n option

  -n          Name the configuration directory in ZooKeeper; by default, the configuration
                            will be uploaded to ZooKeeper using the collection name (-c), but if you want
                            to use an existing directory or override the name of the configuration in
                            ZooKeeper, then use the -c option.

  -shards <#>             Number of shards to split the collection into; default is 1

  -replicationFactor <#>  Number of copies of each document in the collection, default is 1 (no replication)

  -p                Port of a local Solr instance where you want to create the new collection
                            If not specified, the script will search the local system for a running
                            Solr instance and will use the port of the first server it finds.

备注:

solrctl命令
solrctl [options] command [command-arg] [command [command-arg]] ...  
可选参数有:  
--solr:指定 SolrCloud 的 web API,如果在 SolrCloud 集群之外的节点运行命令,就需要指定该参数。  
--zk:指定 zk 集群solr目录。  
--help:打印帮助信息。  
--quiet:静默模式运行。  

command 命令有:  
init [--force]:初始化配置。  
instancedir:维护实体目录。可选的参数有:  
--generate path  
--create name path  
--update name path  
--get name path  
--delete name  
--list  


collection:维护 collections。可选的参数有:  
--create name -s  [-c ] [-r ] [-m ] [-n ]]  
--delete name: Deletes a collection.  
--reload name: Reloads a collection.  
--stat name: Outputs SolrCloud specific run-time information fora collection.  
--list: Lists all collections registered in SolrCloud.  
--deletedocs name: Purges all indexed documents from a collection.  


core:维护 cores。可选的参数有:  
--create name [-p name=value]...]  
--reload name: Reloads a core.  
--unload name: Unloads a core.  
--status name: Prints status of a core.  


cluster:维护集群配置信息。可选的参数有:  
--get-solrxml file  
--put-solrxml file

#全的参数列表
[root@DXHY-YFEB-03 kylin]# solrctl --help

usage: /opt/cloudera/parcels/CDH-5.12.0-1.cdh5.12.0.p0.29/bin/../lib/solr/bin/solrctl.sh [options] command [command-arg] [command [command-arg]] ...

Options:
    --solr solr_uri
    --zk   zk_ensemble
    --jaas jaas.conf
    --help
    --quiet
    --debug Prints error output of calls
    --trace Prints executed commands

Commands:
    init        [--force]

    instancedir [--generate path [-schemaless]]
                [--create name path]
                [--update name path]
                [--get name path]
                [--delete name]
                [--list]

    config      [--create name baseConfig [-p name=value]...]
                [--delete name]

    collection  [--create name -s 
                              [-a Create collection with autoAddReplicas=true]
                              [-c ]
                              [-r ]
                              [-m ]
                              [-n ]]
                [--delete name]
                [--reload name]
                [--stat name]
                [--deletedocs name]
                [--list]
                [--create-snapshot snapshotName -c ]
                [--delete-snapshot snapshotName -c ]
                [--list-snapshots collectionName]
                [--describe-snapshot snapshotName -c ]
                [--prepare-snapshot-export snapshotName -c  -d  [-p ]]
                [--export-snapshot snapshotName [-s ] [-c ] -d ]
                [--restore name  -b  -l  -i 
                                 [-a Restore collection with autoAddReplicas=true]
                                 [-c ]
                                 [-r ]
                                 [-m ]]
                [--request-status requestId]

    core        [--create name [-p name=value]...]
                [--reload name]
                [--unload name]
                [--status name]

    cluster     [--get-solrxml file]
                [--put-solrxml file]
                [--set-property name value]
                [--remove-property name]
                [--get-clusterstate file]

    sentry      [--create-role role]
                [--drop-role role]
                [--add-role-group role group]
                [--delete-role-group role group]
                [--list-roles [-g group]]
                [--grant-privilege role privilege]
                [--revoke-privilege role privilege]
                [--list-privileges role]
                [--convert-policy-file file [-dry-run]]

参考链接:http://blog.csdn.net/kissmelove01/article/details/45043955

你可能感兴趣的:(大数据动物园,Solr)