solr 常用命令

1.启动和关闭

a.启动和重启

启动和重启命令有很多选项让你运行在SolrCloud模式,使用示例配置,以hostname为开头或者非默认端口,指向本地ZooKeeper。

bin/solr start [options]
bin/solr start -help
bin/solr restart [options]
bin/solr restart -help

当使用重启命令,必须传入当初启动时的所有参数。Solr重启之前将被关闭。如果没有节点正在运行,restart将跳过关闭,直接启动Solr。

可用参数

参数描述示例
-a "<string>"

使用JVM参数启动Solr,例如-X。

如果传入以"-D"开头的JVM参数,则可以删除-a选项

bin/solr start -a "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044"
-cloud

如果以SolrCloud模式启动,将启动包含Solr的内置ZooKeeper实例

可简写为-c

bin/solr start -c
-d <dir>定义服务器目录,默认值是$SOLR_HOME/server。一般不定义这个选项。通常情况是每个实例使用相同服务器目录并且使用唯一的Solr home目录bin/solr start -d newServerDir
-e <name>

使用示例配置启动Solr。这些示例用来帮助你更快入门Solr,或者尝试特性。

可用选项有:clound、techproducts、dih、schemaless

bin/solr start -e schemaless
-f在前台启动Solr;使用-e选项时不能使用这个选项bin/solr start -f
-h <hostname>使用自定义hostname启动Solr,默认值'localhost'bin/solr start -h search.mysolr.com
-m <memory>使用自定义值作为JVM的最小和最大堆值bin/solr start -m 1g
-noprompt

无提示,默认完全接受

示例:当使用-cloud时,会有交互式引导你多个选项,如果你想都默认接收,只需要使用这个选项

bin/solr start -e cloud -noprompt
-p <port>指定端口bin/solr start -p 8655
-s <dir>

设置solr.solr.home系统属性。Solr将在该目录下创建core目录。这将允许你在相同host上跑多个实例,使用相同服务器目录,使用-d选项

一旦设置,指定目录需要包含solr.xml文件,除非solr.xml在ZooKeeper中存在,默认值是server/solr

当运行示例(-e)时,该参数将被忽略,因为solr.solr.home取决于哪个示例在跑

bin/solr start -s newHome
-V打印冗余信息bin/solr start -V
-z <zkHost>使用自定义ZooKeeper connection string启动Solr。该选项只能在-c选项,即SolrCloud模式下使用。如果该选项未提供,Solr将启动内置ZooKeeper实例bin/solr start -c -z server1:2181,server2:2181

为了强调默认设置是如何起作用的,花点时间了解下面的命令:

bin/solr start
bin/solr start -h localhost -p 8983 -d server

没有必要定义所有选项,因为有些默认就可以了。

b.设置Java系统属性

使用-D给JVM传入属性

示例:设置自动soft-commit频率为3秒

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

c.SolrCloud模式

bin/solr start -c/cloud

如果指定ZooKeeper连接字符串,例如"-z 192.168.1.4:2181",Solr将连接到ZooKeeper并加入集群。如果以cloud模式启动,但没有指定-z选项,则Solr启动内置ZooKeeper服务器,坚挺在Solr端口+1000,例如Solr在端口8983,则内置ZooKeeper监听在端口9983

d.使用示例配置运行

bin/solr start -e <name>
  • cloud:在一个机器上启动1-4节点的SolrCloud集群。
  • techproducts:以standalone模式启动。由于没有SolrCloud,也没有启动schemaless模式,因此fields必须显式地定义在schema.xml中。配置文件的目录在$SOLR_HOME/server/solr/configsets/sample_techproducts_configs
  • dih:以standalone模式启动。使用DataImportHandler(DIH)和一些dataconfig.xml文件
  • schemaless:以standalone模式启动。使用托管schema(将在后文讲解),提供最小化配置。Solr将运行在Schemaless模式,Solr将在运行时创建fields并猜测field类型。配置文件在$SOLR_HOME/server/solr/configsets/data_driver_schema.configs

注意:运行在前台(-f)选项在使用-e选项失效,因为脚本需要执行额外任务。

e.停止

stop命令向正在运行的Solr节点发送STOP请求,该命令等待5s让Solr顺滑停止,之后会强制杀进程(kill -9)

bin/solr stop [options]
bin/solr stop -help

f.可用参数

参数描述示例
-p <port>在指定端口关闭Solr。如果正在运行多个实例或者SolrCloud模式,你需要分别指定端口关闭或者使用-all选项bin/solr stop -p 8983
-all关闭所有运行的Solrbin/solr stop -all
-k <key>Stop key用来防止误关闭,默认值是"solrrocks"bin/solr stop -k solrrocks

2.查看信息

a.版本

bin/solr version

b.状态

status命令行展示基本的JSON格式的信息。status命令行使用SOLR-PID-DIR环境变量来定位Solr进程号文件来找到运行的Solr实例,SOLR-PID-DIR默认值是bin目录

bin/solr status

输出

Found 1 Solr nodes:

Solr process 975 running on port 8983
{
  "solr_home":"/Users/hs/package/solr/server/solr",
  "version":"5.4.1 1725212 - jpountz - 2016-01-18 11:51:45",
  "startTime":"2016-02-14T02:06:05.35Z",
  "uptime":"0 days, 0 hours, 0 minutes, 13 seconds",
  "memory":"36 MB (%7.3) of 490.7 MB"}

c.健康检测

前提是SolrCloud模式启动。健康检测报告提供关于对于所有shards的每个replica的状态,包括提交文档的个数和当前状态

bin/solr healthcheck [options]
bin/solr healthcheck -help

d.可用参数

参数描述示例
-c <collection>运行健康监测的集群对象名称bin/solr healthcheck -c gettingstarted
-z <zkhost>ZooKeeper connection string,默认值是localhost:8983。如果不是8983,需要指定端口,默认是Solr端口+1000bin/solr healthcheck -z localhost:2181

下面是一个健康检测示例


./solr healthcheck -c gettingstarted -z localhost:9983

输出为

{
  "collection":"gettingstarted",
  "status":"healthy",
  "numDocs":0,
  "numShards":2,
  "shards":[
    {
      "shard":"shard1",
      "status":"healthy",
      "replicas":[
        {
          "name":"core_node2",
          "url":"http://10.8.204.89:8983/solr/gettingstarted_shard1_replica1/",
          "numDocs":0,
          "status":"active",
          "uptime":"0 days, 0 hours, 4 minutes, 27 seconds",
          "memory":"85.6 MB (%17.5) of 490.7 MB",
          "leader":true},
        {
          "name":"core_node3",
          "url":"http://10.8.204.89:7574/solr/gettingstarted_shard1_replica2/",
          "numDocs":0,
          "status":"active",
          "uptime":"0 days, 0 hours, 4 minutes, 21 seconds",
          "memory":"41.4 MB (%8.4) of 490.7 MB"}]},
    {
      "shard":"shard2",
      "status":"healthy",
      "replicas":[
        {
          "name":"core_node1",
          "url":"http://10.8.204.89:8983/solr/gettingstarted_shard2_replica1/",
          "numDocs":0,
          "status":"active",
          "uptime":"0 days, 0 hours, 4 minutes, 27 seconds",
          "memory":"85.9 MB (%17.5) of 490.7 MB",
          "leader":true},
        {
          "name":"core_node4",
          "url":"http://10.8.204.89:7574/solr/gettingstarted_shard2_replica2/",
          "numDocs":0,
          "status":"active",
          "uptime":"0 days, 0 hours, 4 minutes, 21 seconds",
          "memory":"41.4 MB (%8.4) of 490.7 MB"}]}]}

3.Collections和Cores

a.创建

注意:执行create命令的用户要和启动Solr的用户一致

create命令行会检测到Solr的运行状态(standalone或SolrCloud),根据状态创建core或collection

bin/solr create options
bin/solr create -help

可用参数

参数描述示例
-c <name>创建core或collection的名称bin/solr create -c mycollection
-d <confdir>配置目录,默认值是data_driven_schema_configsbin/solr create -d basic_configs
-n <configName>配置文件名。默认和core或collection同名bin/solr create -n basic
-p <port>指定Solr端口。当运行多个standalone实例时需要指定bin/solr create -p 8983

-s <shards>

-shards

分割collection为shards的数量,默认1。前提是SolrCloud模式bin/solr create -s 2

-rf <replicas>

-replicationFactor

集群中每个document的拷贝数量,默认值1(没有replication)bin/solr create -rf 2

4.配置目录和SolrCloud

在创建SolrCloud集群前,使用的配置目录必须上传到ZooKeeper。需要你做主要决定的是在ZooKeeper中的配置目录是否应该分享到多个集群。下面通过示例来了解配置目录是如何在SolrCloud中工作的。

首先,如果没有提供-d或-n选项,默认配置($SOLR_HOME/server/solr/configsets/data_driven_schema_cinfigs/conf)被上传到ZooKeeper,使用和集群相同的名称。例如,下面的命令将导致data-driven_schema_configs配置被上传到ZooKeeper

bin/solr create -c contacts

如果创建另一个集群

bin/solr create -c contacts2

另一个data_driven_schema_configs的拷贝将被上传到ZooKeeper,在/configs/contacts2下。对contacts集群做的变化不会影响contacts2。简而言之,默认为每个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下。然而,你也可以提供你自己的配置目录路径。示例:

bin/solr create -c mycoll -d /tmp/myconfigs

将上传/tmp/myconfigs到ZooKeeper目录/configs/mycoll下。再次重申,配置目录的名称和集群一致,除非使用-n指定

其他集群可以共享配置,使用-n选项。示例:创建一个共享之前创建的basic配置的新集群

bin/solr create -c logs2 -n basic

a.Data-driven schema和共享配置

data_driven_schema_configs将转变为索引数据。因此,建议不要共享配置,除非确定所有集群应该继承一个集群的索引变化。

b.Delete

delete命令行检测到Solr的运行模式,delete core或collection

bin/solr delete [options]
bin/solr delete -help

如果在SolrCloud模式,delete命令行检查配置目录是否有其他集群使用,如果没有,也将从ZooKeeper中被删除。

可用参数

参数描述示例
-c <name>core/collection名称bin/solr delete -c mycoll
-deleteConfig <trueIfalse>

从ZooKeeper删除配置目录,默认值为true

如果配置目录被其他集群使用,指定true也不会被删除

bin/solr delete -deleteConfig false
-p <port>多个standalone实例时有用bin/solr delete -p 8983

 

转载于:https://www.cnblogs.com/studyhs/p/5181808.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值