天天看点

solr 5.0.0 bin/start脚本详细解析

参考文档:https://cwiki.apache.org/confluence/display/solr/Solr+Start+Script+Reference#SolrStartScriptReference-SolrCloudMode

环境:

CentOS 6.5, JRE 1.7, Solr 5.0.0, ZooKeeper 3.6

一、启动、停止操作

1. 启动、重启

./bin/solr start [options]

./bin/solr start -help

./bin/solr restart [options]

./bin/solr restart -help

1.1 命令可选项

参数 描述 样例
-a "<string>"    启动Solr时,添加额外的JVM参数                    
bin/solr start -a 
"-Xdebug -Xrunjdwp:transport=dt_socket, 
server=y,suspend=n,address=1044"
           
-cloud

以SolrCloud模式启动Solr

简短写法:-c

 ./bin/solr start -c
-d <dir> 定义server目录,默认是server (

$SOLR_HOME/server

),

一般不会重置这个目录

./bin/solr start -d newServerDir
-e <name>

以样例配置启动Solr

可选项为:

  • cloud
  • techproducts
  • dih
  • schemaless
./bin/solr start -e schemaless      
-f

前端方式启动Solr服务,

运行样例时不可以此方式启动

./bin/solr start -f
-h <hostname> 启动时, 为Solr服务指定hostname, 默认为'localhost' ./bin/solr start -h search.mysolr.com
-m <memory> 启动时, 为JVM指定最小(-Xms)和最大(-Xmx)堆大小  ./bin/solr start -m 1g
-noprompt 启动时,接受一切默认设置,不需要交互确认 ./bin/solr start -e cloud -noprompt
-p <port> 在指定的端口启动Solr服务,默认为'8983' ./bin/solr start -p 8655
-s <dir> 设置solr.solr.home系统属性,默认server/solr. ./bin/solr start -s newHome
-V 启动Solr服务时, 显示冗余信息  ./bin/solr start -V
-z <zkHost>

以ZooKeeper连接串启动Solr服务,本选项只在SolrCloud运行模型下使用;

如果不指定本选项,则启动Solr内嵌的ZooKeeper 实例

./bin/solr start -c -z server1:2181,server2:2181

启动时,默认设置如何,以下两个启动命令效果一样:

./bin/solr start

./bin/solr start -h localhost -p 8983 -d server -s solr -m 512m

1.2 设置JAVA系统属性

bin/solr脚本可以传递任何以'-D'开始的参数到JVM

eg.

./bin/solr start -Dsolr.autoSoftCommit.maxTime=3000

1.3 SolrCloud模式

'-c'和'-cloud'两个选项是等价的:

./bin/solr start -c

./bin/solr start -cloud

以SolrCloud模式启动Solr服务时,如果指定了ZooKeeper连接串,(如,-z 192.168.1.4:2181),Solr则会连接到指定的ZooKeeper实例,并加入到集群;如果没有指定'-z', Solr则会启动内嵌的一个ZooKeeper实例,监听在端口——Solr端口+1000,(如,如果Solr端口为8983, 则内嵌ZooKeeper端口为9933)

注意:

如果ZooKeeper连接串使用了chroot, (如,localhost:2181/solr), 那么在加入到SolrCloud之前,你需要引导 /solr  ZooKeeper节点, 使用Solr包自带的zkcli.sh脚本,例如:

server/scripts/cloud-scripts/zkcli.sh -zkhost localhost:2181/solr -cmd bootstrap -solrhome server/solr
           

1.4  运行样例配置

./bin/solr start -e <name>

样例配置方便你快速学习Solr,主要提供提供了以下几种样例:

cloud 本样例在单机上启动了1到4个节点的SolrCloud集群,当你选择以交互式会话的方式启动服务时,它将引导你选择集群的节点数,端口,创建的collection名称

techproducts 本样例在单机上以独立模式启动了Solr服务,使用了为$SOLR_HOME/example/exampledocs 目录中文档设计好的scheme.xml, 配置目录(configset)为$SOLR_HOME/server/solr/configsets/sample_techproducts_configs

dih 本样例在单机上以独立模式启动Solr服务,并且开启了 DataImportHandler (DIH) , 另外,为多种数据类型(如, database contents, email, RSS feeds, 等)提供了预配置好的样例dataconfig.xml

schemaless 本样例在单机上以独立模式启动Solr服务,并且使用了managed schema, 提供了一个最小化的预定义的Scheme. 在索引文档时,Solr会根据提交的文档自动判断字段类型并动态的添加字段到Schem, 对应的配置目录为$SOLR_HOME/server/solr/configsets/data_driven_schema_configs.

2. 状态检查

status命令会以JSON格式显示本系统上所有在运行的Solr服务实例, 通过SOLR_PID_DIR环境变量定位Solr服务进程PID的存储文件,进而发现Solr服务实例。 默认SOLR_PID_DIR在bin目录下。

以下是在单机集群上运行status的样例:

Found 2 Solr nodes: 

 

Solr process 39920 running on port 7574

{

  "solr_home":"/Applications/Solr/solr-5.0.0/example/cloud/node2/solr/",

  "version":"5.0.0 1658469 - anshumgupta - 2015-02-09 09:54:36",

  "startTime":"2015-02-10T17:19:54.739Z",

  "uptime":"1 days, 23 hours, 55 minutes, 48 seconds",

  "memory":"77.2 MB (%15.7) of 490.7 MB",

  "cloud":{

    "ZooKeeper":"localhost:9865",

    "liveNodes":"2",

    "collections":"2"}}

 

Solr process 39827 running on port 8865

{

  "solr_home":"/Applications/Solr/solr-5.0.0/example/cloud/node1/solr/",

  "version":"5.0.0 1658469 - anshumgupta - 2015-02-09 09:54:36",

  "startTime":"2015-02-10T17:19:49.057Z",

  "uptime":"1 days, 23 hours, 55 minutes, 54 seconds",

  "memory":"94.2 MB (%19.2) of 490.7 MB",

  "cloud":{

    "ZooKeeper":"localhost:9865",

    "liveNodes":"2",

    "collections":"2"}}
           

3. 停止

stop命令会发送一个STOP请求到一个运行的Solr节点,请求节点优雅的停止;该命令会等待节点优雅停止,5秒后未停止,则执行强制杀死服务进程(kill -9).

./bin/solr stop [options]

./bin/solr stop -help

3.1 命令可选项

参数 描述 样例

-p

<port>                                         

停止运行在指定端口的服务                                       
<pre class="html" name="code">./bin/solr stop -p 8983
           
-k <key> 停止KEY, 用于防止Solr意外停止,默认是“solrrocks”
<pre class="html" name="code">./bin/solr stop -k solrrocks
           
-all 停止所有有效PID的Solr服务进程
<pre class="html" name="code">./bin/solr stop -all
           

4. 健康检查

在SolrCloud模式下,healthcheck会为指定的collection生成一份JSON格式的体检报告;内容为该集合中所有shard的每个replica的状态信息,包括提交的文档数和当前的状态信息。

./bin/solr healthcheck [options]

./bin/solr healthcheck -help

4.1 命令可选项

参数 描述 样例
-c <collection>                  希望体检的collection名称(必须)                                             
./bin/solr healthcheck -c gettingstarted
           
-z <zkhost> ZooKeeper连接串,默认为Solr端口+1000
<pre class="html" name="code">./bin/solr healthcheck -z localhost:2181
           

以下是一份2个节点,并且使用内嵌ZooKeeper的体检请求和响应:

$ ./bin/solr healthcheck -c gettingstarted -z localhost:9865

 

{

  "collection":"gettingstarted",

  "status":"healthy",

  "numDocs":0,

  "numShards":2,

  "shards":[

    {

      "shard":"shard1",

      "status":"healthy",

      "replicas":[

        {

          "name":"core_node1",

          "url":"http://10.0.1.10:8865/solr/gettingstarted_shard1_replica2/",

          "numDocs":0,

          "status":"active",

          "uptime":"2 days, 1 hours, 18 minutes, 48 seconds",

          "memory":"25.6 MB (%5.2) of 490.7 MB",

          "leader":true},

        {

          "name":"core_node4",

          "url":"http://10.0.1.10:7574/solr/gettingstarted_shard1_replica1/",

          "numDocs":0,

          "status":"active",

          "uptime":"2 days, 1 hours, 18 minutes, 42 seconds",

          "memory":"95.3 MB (%19.4) of 490.7 MB"}]},

    {

      "shard":"shard2",

      "status":"healthy",

      "replicas":[

        {

          "name":"core_node2",

          "url":"http://10.0.1.10:8865/solr/gettingstarted_shard2_replica2/",

          "numDocs":0,

          "status":"active",

          "uptime":"2 days, 1 hours, 18 minutes, 48 seconds",

          "memory":"25.8 MB (%5.3) of 490.7 MB"},

        {

          "name":"core_node3",

          "url":"http://10.0.1.10:7574/solr/gettingstarted_shard2_replica1/",

          "numDocs":0,

          "status":"active",

          "uptime":"2 days, 1 hours, 18 minutes, 42 seconds",

          "memory":"95.4 MB (%19.4) of 490.7 MB",

          "leader":true}]}]}
           

二、Collection、Core操作

bin/solr脚本也能够帮助你创建collections(运行在SolrCloud模式)或者cores(运行在独立模式), 或者删除collections。

1. 创建

bin/solr create命令自动检测运行模式(SolrCloud或standalone),然后根据模式执行创建collection还是core.

./bin/solr create options

./bin/solr create -help

1.1 命令可选项

参数 描述 样例
-c <name> 创建的collection或core的名称(必须)                                             
<pre class="html" name="code">./bin/solr create -c mycollection
           
-d <confdir> 配置文件目录,默认为data_driven_schema_configs    
<pre class="html" name="code">./bin/solr create -d basic_configs
           
-n <configName> 配置名称,默认与collection或core相同
<pre class="html" name="code">./bin/solr create -n basic
           
-p <port> 命令发送到的运行实例的端口,默认脚本会根据运行实例自动检测端口
<pre class="html" name="code">./bin/solr create -p 8983
           

-s <shards>

-shards

collection被切割的shard数,默认为1;此参数只在solrCloud模式下有效
<pre class="html" name="code">./bin/solr create -s 2
           

-rf <replicas>

-replicationFactor

collection中每篇文档的备份数,默认为1(没有备份)
<pre class="html" name="code">./bin/solr -rf 2
           

1.2 配置目录和SolrCloud

在SolrCloud中创建collection之前,我们必须把collection用到的配置目录上传到ZooKeeper实例;create命令提供了几种collction与配置目录的工作方案,你最主要考虑是否决定让配置目录在多个collection之间共享。以下讲解几个样例,说明collection与配置目录如何工作的:

首先,如果你不指定-d或者-n选项,则默认的配置($SOLR_HOME/server/solr/configsets/data_driven_schema_configs/conf)会以collection相同的名称上传到ZooKeeper。例如,./bin/solr create -c contacts, 此命令将data_driven_schema_configs配置上传到ZooKeeper的/configs/contacts目录下。

如果你通过命令./bin/solr create -c contacts2,创建另外一个集合contacts2, 则data_driven_schema_configs的另一份拷贝被上传到ZooKeeper的/configs/contacts2目录下;对contacts配置的任何修改都不会影响到contacts2;简言之,创建collection时,默认会为每个新的collection创建一个独立的配置副本。

你可以使用-n选项,为上传到ZooKeeper中的配置命名。例如,命令./bin/solr create -c logs -d basic_configs -n basic会将 

server/solr/configsets/basic_configs/conf配置目录上传到ZooKeeper的

/configs/basic下。

我们可以使用-d选项指定非默认的配置, solr在server/solr/configsets下提供了一些内建的配置,你也可以通过-d选项指定自己的配置。例如,命令./bin/solr create -c mycoll -d /tmp/myconfigs会上传本地/tmp/myconfigs目录到ZooKeeper的/configs/mycoll,另外,ZooKeeper中的配置名称与collection相同,除非你使用了-n选项重新命名。

别的collections可以通过-n选项指定共享的配置,例如,命令./bin/solr create -c logs2 -n basic将创建logs2集合,并共享basic配置。

1.3 数据驱动的Scheme和共享配置

数据驱动的Scheme(data_driven_schema_configs)会随着索引的数据动态变化,因此,我们不建议你在collection之间共享数据驱动的Scheme,除非你确定各个collection继承共享配置集合中任何一个collection的变化。

2. 删除

delete命令自动检测服务运行模式(SolrCloud或Standalone),并执行相应的删除collection(SolrCloud模式)或者core(Standalone模式)操作。

./bin/solr delete [options]

./bin/solr delete -help

</pre><pre class="html" name="code">如果运行在SolrCloud模式,delete命令会检查待删除collection使用的配置是否被其他collection共享,如果有,则不删除ZooKeeper中对应的配置,否则,直接删除ZooKeeper的配置。
           

2.1 命令可选项

参数 描述 样例
-c <name> 删除的core或collection名称(必须)                                                     
<pre class="html" name="code">./bin/solr delete -c mycoll
           
-deleteConfig <true|false>

是否从ZooKeeper中删除配置,默认为true.

如果配置被其它collection共享,则即使true,也不会删除

<pre class="html" name="code">./bin/solr delete -deleteConfig false
           
-p <port> 命令发送到的本地运行Solr实例端口,默认脚本会根据运行实例检查端口
<pre class="html" name="code">./bin/solr delete -p 8983