solr-control-script-reference.html#
collections-and-cores
create命令检测solr正在运行的模式(独立模式或solrcloud模式),然后根据模式创建核心或集合。
bin/solr create [options]
bin/solr create -help
创建核心或集合参数
-c <name>
要创建的核心或集合的名称(必需)。
-d <confdir>
The configuration directory. This defaults to basic_configs.
Example: bin/solr create -d basic_configs
-n <configName>
The configuration name. This defaults to the same name as the core or collection.
Example: bin/solr create -n basic
-p <port>
要向其发送create命令的本地solr实例的端口;默认情况下,脚本尝试通过查找正在运行的solr实例来检测端口。
如果您在同一台主机上运行多个独立的solr实例,那么此选项非常有用,因此需要您具体说明在哪个实例中创建核心。
Example: bin/solr create -p 8983
-s <shards> or -shards
Number of shards to split a collection into, default is 1; only applies when Solr is running in SolrCloud mode.
-s <shards> or -shards
Number of shards to split a collection into, default is 1; only applies when Solr is running in SolrCloud mode.
Example: bin/solr create -s 2
-rf <replicas> or -replicationFactor
Number of copies of each document in the collection. The default is 1 (no replication).
Example: bin/solr create -rf 2
Configuration Directories and SolrCloud
在solrcloud中创建集合之前,必须将集合使用的配置目录上载到zookeeper。create命令支持集合和配置目录如何工作的几个用例。您需要做的主要决定是,是否应该跨多个集合共享ZooKeeper中的配置目录。
让我们通过几个例子来说明配置目录如何在solrcloud中工作。
首先,如果不提供-d或-n选项,则默认配置($solr_home/server/solr/configsets/_default/conf)将使用与集合相同的名称上载到ZooKeeper。
例如,以下命令将导致将默认配置上载到zookeeper中/configs/contacts:
bin/solr create-c contacts。
如果使用bin/solr create-c contacts2创建另一个集合,则会将默认目录的另一个副本上载到/configs/contacts2下的zookeeper。
对contacts集合的配置所做的任何更改都不会影响contacts2集合。简单地说,默认行为为您创建的每个集合创建配置目录的唯一副本。
您可以使用-n选项覆盖ZooKeeper中为配置目录指定的名称。例如,命令bin/solr create-c logs-d _default-n basic将把server/solr/configsets/_default/conf目录上载到zookeeper as/configs/basic。
注意,我们使用-d选项来指定与默认配置不同的配置。solr在server/solr/configsets下提供了几个内置配置。但是,您也可以使用-d选项提供到您自己的配置目录的路径。例如,命令bin/solr create-c mycoll-d /tmp/myconfigs将把/tmp/myconfigs上传到/configs/mycoll下的zookeeper中。
要重申,除非使用-n选项重写配置目录,否则配置目录将以集合命名。
其他集合可以通过使用-n选项指定共享配置的名称来共享相同的配置。
其他集合可以通过使用-n选项指定共享配置的名称来共享相同的配置。例如,以下命令将创建一个新集合,该集合共享先前创建的基本配置:bin/solr create-c logs2-n basic
Data-driven Schema and Shared Configuration
数据驱动模式和共享配置
默认模式可以随着数据的索引而变化,因为它具有无模式功能(即,对模式的数据驱动更改)。因此,我们建议您不要在集合之间共享数据驱动的配置,除非您确定所有集合都应继承将数据索引到其中一个集合时所做的更改。如果集合名称为myCollection,则可以通过以下方式关闭集合的无模式功能(即对架构的数据驱动更改)
bin/solr config -c mycollection -p 8983 -action set-user-property -property update.autoCreateFields -value false
Delete Core or Collection
delete命令检测solr正在运行的模式(standalone或solrcloud),然后根据需要删除指定的核心(standalone)或集合(solrcloud)。
bin/solr delete [options]
bin/solr delete -help
如果在solrcloud模式下运行,则delete命令检查正在删除的集合使用的配置目录是否正被其他集合使用。如果没有,那么配置目录也会从ZooKeeper中删除。
例如,如果使用bin/solr create-c contacts创建了一个集合,则delete命令bin/solr delete-c contacts将检查/configs/contacts配置目录是否正由任何其他集合使用。如果没有,则从zookeeper中删除/configs/contacts目录。
Delete Core or Collection Parameters
-c <name>
Name of the core / collection to delete (required).
Example: bin/solr delete -c mycoll
-deleteConfig
配置目录是否也应该从ZooKeeper中删除。默认值为true。
如果另一个集合正在使用配置目录,则即使将-deleteconfig传递为true,也不会删除该目录。
Example: bin/solr delete -deleteConfig false
-p <port>
要将删除命令发送到的本地solr实例的端口。默认情况下,脚本尝试通过查找运行的solr实例来检测端口。
如果您在同一台主机上运行多个独立的solr实例,那么此选项非常有用,因此需要您具体说明从哪个实例中删除核心。
Example: bin/solr delete -p 8983
认证
bin/solr脚本允许启用或禁用基本身份验证,允许您从命令行配置身份验证。当前,此脚本仅启用基本身份验证,并且仅在使用solrcloud模式时可用。
Enabling Basic Authentication
命令bin/solr auth enable将solr配置为在使用bin/solr和任何API请求访问用户界面时使用基本身份验证。
bin/solr 创建security.json文件并将其上载到zookeeper。security.json文件将类似于:auth enable命令进行了若干更改以启用基本身份验证:
{
"authentication":{
"blockUnknown": false,
"class":"solr.BasicAuthPlugin",
"credentials":{"user":"vgGVo69YJeUg/O6AcFiowWsdyOUdqfQvOLsrpIPMCzk= 7iTnaKOWe+Uj5ZfGoKKK2G6hrcF10h6xezMQK+LBvpI="}
},
"authorization":{
"class":"solr.RuleBasedAuthorizationPlugin",
"permissions":[
{"name":"security-edit", "role":"admin"},
{"name":"collection-admin-edit", "role":"admin"},
{"name":"core-admin-edit", "role":"admin"}
],
"user-role":{"user":"admin"}
}
}
在bin/solr.in.sh或bin\solr.in.cmd中添加两行以设置身份验证类型和basicauth.conf的路径:
# The following lines added by ./solr for enabling BasicAuth
SOLR_AUTH_TYPE="basic"
SOLR_AUTHENTICATION_OPTS="-Dsolr.httpclient.config=/path/to/solr-7.5.0/server/solr/basicAuth.conf"
创建文件server/solr/basicauth.conf以存储与bin/solr命令一起使用的凭证信息。
该命令采用以下参数:
-credentials
The username and password in the format of username:password of the initial user.
如果不希望将用户名和密码作为参数传递给脚本,则可以选择-prompt选项。必须指定-credentials或-prompt。
-prompt
如果首选prompt,则将true作为参数传递,以请求脚本提示用户输入用户名和密码。
必须指定-credentials或-prompt。
-blockUnknown
When true, blocks all unauthenticated users from accessing Solr. This defaults to false, which means unauthenticated users will still be able to access Solr.
-updateIncludeFileOnly
如果为true,则只更新bin/solr.in.sh或bin\solr.in.cmd中的设置,而不创建security.json。
-z
定义ZooKeeper连接字符串。如果您想在所有solr节点都出现之前启用身份验证,这很有用。如果zk_主机在solr.in.sh或solr.in.cmd中定义,则不需要。
-d
定义solr服务器目录,默认为$solr_home/server。通常不需要覆盖默认值,只有在自定义了$solr_主目录路径时才需要。
-s
定义solr.solr.home的位置,默认为server/solr。如果同一主机上有多个solr实例,或者您自定义了$solr_主目录路径,则可能需要定义此路径。
Disabling Basic Authentication
您可以使用bin/solr auth disable禁用基本身份验证。
如果-updateCincludeFileOnly选项设置为true,则仅更新bin/solr.in.sh或bin\solr.in.cmd中的设置,并且不会删除security.json。
如果-updateIncludeFileOnly选项设置为false,则会更新bin/solr.in.sh或bin\solr.in.cmd中的设置,并删除security.json。但是,basicauth.conf文件不会用任何一个选项删除。
Set or Unset Configuration Properties
bin/solr脚本启用配置API的子集:(取消设置)设置公共属性和(取消设置)设置用户定义的属性。
bin/solr config [options]
bin/solr config -help