本文是在阅读Apache Solr 8.5.1官方文档的随笔。
文章目录
下载
官网https://lucene.apache.org/solr/downloads.html下载最新版本。下载后解压。
启动和停止
以下的命令都是从官网复制的,Windows需要进入到bin
目录。
启动
bin/solr.cmd start
,启动后的端口是8983
,也可以指定端口号。
bin/solr start -p 8983
,如果没有指定,默认是8983
。
bin/solr restart -p 8983
,必须指定端口号。
以下两条命令等价:
bin/solr start
bin/solr start -h localhost -p 8983 -d server -s solr -m 512m
参数
-d <dir>
定义一个服务器目录,默认为server
($SOLR_HOME/server
)。当在同一台主机上运行多个Solr实例时,更常见的做法是对每个实例使用相同的服务器目录,并使用-s选项使用唯一的Solr主目录。
Example: bin/solr start -d newServerDir
-h <hostname>
Start Solr with the defined hostname. If this is not specified, ‘localhost’ will be assumed.
Example: bin/solr start -h search.mysolr.com
-m <memory>
Start Solr with the defined value as the min (-Xms) and max (-Xmx) heap size for the JVM.
Example: bin/solr start -m 1g
-s <dir>
设置solr.solr.home
系统属性,Solr将在这个目录下创建core目录。这允许您在同一主机上运行多个Solr实例,同时使用-d参数重复使用同一服务器目录集。
指定的目录应该包含一个solr.xml
文件。除非solr.xml
在Zookeeper中已存在。默认值是server/solr
。
如果使用了-e
参数,那么会忽略-s
参数,solr.solr.home
依赖于运行哪个实例。
Example: bin/solr start -s newHome
设置Java系统参数
bin/solr
脚本将把任何以-D
开头的附加参数传递给JVM,允许您设置任意的Java系统属性。例如:bin/solr start -Dsolr.autoSoftCommit.maxTime=3000
。
停止
bin/solr stop -p 8983
停止端口为8983
的Solr实例。
参数
-p <port>
如果运行多个实例,或者以SolrCloud模式运行,那么需要在单独的请求中指定端口,或者使用-all选项。
Example: bin/solr stop -p 8983
-all
停止所有正常运行的Solr实例。
Example: bin/solr stop -all
版本
version
命令返回当前安装的Solr版本。
shell $ bin/solr version 8.5.1
Collections and Cores
Create a Core or Collection
bin/solr create [options]
bin/solr create -help
Create Core or Collection Parameters
-c <name>
Name of the core or collection to create (required).
Example: bin/solr create -c mycollection
-d <confdir>
The configuration directory. This defaults to _default
.
Example: bin/solr create -d _default
-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实例,需要指定在哪个实例中创建core。
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.
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
Delete Core or Collection
bin/solr delete [options]
bin/solr delete -help
Delete Core or Collection Parameters
-c <name>
Name of the core / collection to delete (required).
Example: bin/solr delete -c mycoll
-deleteConfig
Whether or not the configuration directory should also be deleted from ZooKeeper. The default is true
.
If the configuration directory is being used by another collection, then it will not be deleted even if you pass -deleteConfig
as true
.
Example: bin/solr delete -deleteConfig false
-p <port>
将删除命令发送到本地Solr实例的端口。在默认情况下,脚本尝试通过查找运行的Solr实例来检测端口。如果一台主机运行多个独立的Solr实例,需要指定在哪个实例中删除core。
Example: bin/solr delete -p 8983
Solr Home
当SOlr运行时,它需要访问一个主目录。
如果是第一次安装,主目录是server/solr
。一些命令也会改变主目录(例如,如果你执行bin/solr start -e cloud
,你的主目录将变成example/cloud
)。
主目录包含重要的配置信息,是Solr存储索引的位置。单例和集群时的主目录不同。
单例:
<solr-home-directory>/
solr.xml
core_name1/
core.properties
conf/
solrconfig.xml
managed-schema
data/
core_name2/
core.properties
conf/
solrconfig.xml
managed-schema
data/
集群
<solr-home-directory>/
solr.xml
core_name1/
core.properties
data/
core_name2/
core.properties
data/
Configuration Files
在Solr Home中,有这些文件:
-
solr.xml
指定Solr服务器实例的配置选项。关于solr.xml
的更多信息,查看Solr Cores and solr.xml。 -
Per Solr Core:
core.properties
为每个core定义特定的属性,比如name,core所属的collection,schema的位置,其他参数等。关于core.properties
的更多信息,查看Defining core.properties。solrconfig.xml
控制高级行为。例如,您可以为数据目录指定一个备用位置。关于solrconfig.xml
的更多信息,查看Configuring solrconfig.xml。managed-schema
(或者schema.xml
)描述您将要求Solr索引的文档。Schema将document定义为collection of fields。在这里可以定义字段和字段类型。字段类型定义功能强大,包括有关Solr如何处理传入字段值和查询值的信息。关于Solr Schema的更多信息,查看Documents, Fields, and Schema Design和Schema API。data/
包含低级索引文件的目录。