Solr入门学习(一) —— Solr 的安装、启动与关闭

Server : Ubuntu 16.04
Java Version : 1.8
Solr Version : 7.4.0


Solr 下载与安装

首先,到 http://lucene.apache.org/solr/downloads.html 获取 Solr 的下载地址,然后使用 wget 命令下载到服务器上。

wget http://mirror.bit.edu.cn/apache/lucene/solr/7.4.0/solr-7.4.0.tgz

下载完成后解压文件。

tar -zxvf solr-7.4.0.tgz

查看当前目录,发现 Solr 已安装到本地。

root@panda:/usr/local/java# ls
activemq  hadoop  jdk1.8.0_161  kafka  solr-7.4.0  zookeeper


Solr 的启动

为了启动 Solr,我们需要到 Solr 安装文件下的 bin 目录里执行启动脚本,如下所示:

cd /usr/local/java/solr-7.4.0/bin/
./solr start -e cloud

该命令会在本地启动 Solr 集群。

不过,输入该命令后,Solr 不会马上启动,还有几个步骤需要完成。

1. 设置节点数

执行启动命令后,Solr 首先会显示提示语:

Welcome to the SolrCloud example!

This interactive session will help you launch a SolrCloud cluster on your local workstation.
To begin, how many Solr nodes would you like to run in your local cluster? (specify 1-4 nodes) [2]:

这边要求我们设置启动节点数,默认是 2。这里我们直接按 ENTER 键选择默认选项。

2.设置端口号

接着,Solr 提示我们设置端口号:

扫描二维码关注公众号,回复: 2752924 查看本文章
Ok, let's start up 2 Solr nodes for your example SolrCloud cluster.
Please enter the port for node1 [8983]:

如果 Solr 默认端口没有被占用且我们没有特殊需求,直接按 ENTER 选择默认端口即可。

此时,Solr 会为我们的两个节点分别分配默认端口号 89837857,并在两个节点上初始化实例。此外,Solr 还会启动内置的 Zookeeper,并将以上两个节点注册到 Zookeeper 上。成功运行的信息如下:

Starting up Solr on port 8983 using command:
"/usr/local/java/solr-7.4.0/bin/solr" start -cloud -p 8983 -s "/usr/local/java/solr-7.4.0/example/cloud/node1/solr"

Waiting up to 180 seconds to see Solr running on port 8983 [\]  
Started Solr server on port 8983 (pid=1898). Happy searching!

Starting up Solr on port 7574 using command:
"/usr/local/java/solr-7.4.0/bin/solr" start -cloud -p 7574 -s "/usr/local/java/solr-7.4.0/example/cloud/node2/solr" -z localhost:9983

Waiting up to 180 seconds to see Solr running on port 7574 [\]  
Started Solr server on port 7574 (pid=2105). Happy searching!

- 2018-08-10 17:05:06.693; org.apache.solr.client.solrj.impl.ZkClientClusterStateProvider; Cluster at localhost:9983 ready
3.创建集合

启动成功后,Solr 会提示你创建集合,这里我们输入 testCollection 并按 ENTER 键确认。

Now let's create a new collection for indexing documents in your 2-node cluster.
Please provide a name for your new collection: [gettingstarted] 
testCollection

接着,Solr 会提示你设置分片数和副本数,这里直接都按默认处理。

4.指定配置

创建集合后,Solr 会要求你指定配置文件集。

Please choose a configuration for the testCollection collection, available options are:
_default or sample_techproducts_configs [_default]

关于这个配置文件集,官网给的说明是这样:

A collection must have a configSet, which at a minimum includes the two main configuration files for Solr: the schema file (named either managed-schema or schema.xml), and solrconfig.xml.

意思就是,每个集合必须指定一个 configSet,且这个 configSet 至少要包含两个主要的配置文件 managed-schemaschema.xml

这里我们注意到,Solr 提示我们目前有两个可用的配置文件集选项,分别是 _defaultsample_techproducts_configs。这两者实际上是 Solr 预设好的配置文件集,用户可用直接使用。由于后续示例需要,这里我们选择 sample_techproducts_configs,按 ENTER 键确认。

至此,Solr 启动成功,我们可以看到如下信息输出:

Created collection 'testCollection' with 2 shard(s), 2 replica(s) with config-set 'testCollection'

Enabling auto soft-commits with maxTime 3 secs using the Config API

POSTing request to Config API: http://localhost:8983/solr/testCollection/config
{"set-property":{"updateHandler.autoSoftCommit.maxTime":"3000"}}
Successfully set-property updateHandler.autoSoftCommit.maxTime to 3000


SolrCloud example running, please visit: http://localhost:8983/solr

现在,我们可以通过 http://localhost:8983/solr 访问 Solr 的 Web 管理页面了!

注:启动过程中遇到 N 个问题,均记录在文章底部。


Solr 的关闭与重启

关闭 Solr 是一件比较简单的事情,只需执行以下命令即可:

panda@panda:/usr/local/java/solr-7.4.0/bin# ./solr stop -all
Sending stop command to Solr running on port 8983 ... waiting up to 180 seconds to allow Jetty process 1898 to stop gracefully.
Sending stop command to Solr running on port 7574 ... waiting up to 180 seconds to allow Jetty process 2105 to stop gracefully.

如果想针对某端口进行关闭,只需加入端口参数与端口号:

solr stop -p 8983

但是,Solr 的重启和我们的初次启动略有不同。

首先,我们要启动第一个节点:

panda@panda:/usr/local/java/solr-7.4.0/bin$ ./solr start -c -p 8983 -s ../example/cloud/node1/solr
Waiting up to 180 seconds to see Solr running on port 8983 [\]  
Started Solr server on port 8983 (pid=16514). Happy searching!

第一个节点启动成功后,我们开始启动第二个节点,并告诉它如何连接 Zookeeper:

panda:/usr/local/java/solr-7.4.0/bin$ ./solr start -c -p 7574 -s ../example/cloud/node2/solr -z localhost:9983
Waiting up to 180 seconds to see Solr running on port 7574 [\]  
Started Solr server on port 7574 (pid=16735). Happy searching!

现在,我们可以继续使用 Solr 了!


遇到的问题

问题1:Max Processes Limit

笔者用的服务器是阿里云的超低配版本,默认的最大限制用户进程数是 7857,因此在启动 Solr 时就马上看到警告:

*** [WARN] ***  Your Max Processes Limit is currently 7857. 
 It should be set to 65000 to avoid operational disruption. 
 If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh

原本想只是一个警告罢了,忽略就好,结果还是 GG 了。

ERROR: Failed to start Solr using command: "/usr/local/java/solr-7.4.0/bin/solr" start -cloud -p 8983 -s "/usr/local/java/solr-7.4.0/example/cloud/node1/solr" Exception : org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)

既然这样,那就只能正视问题了。

首先,查看一下系统限制的最大用户进程数:

root@panda:/# ulimit -u
7857

确认是 7857 没错了。

那么现在,我们需要解决的就是更改这个默认值。在笔者的环境中,max user processes 可以在 /etc/security/limits.conf 文件中进行设置,格式为<domain> <type> <item> <value>,详情如下:

root soft nproc 65535
root hard nproc 65535
* soft nproc 65535
* hard nproc 65535

保存后重启会话,发现该值已经变成 65535 了。

root@panda:~# ulimit -u
65535

注:CentOS 的配置文件似乎在 /etc/security/limits.d 文件夹下。

问题2:不能使用 root 用户

解决了上一个问题后,笔者欢快地重新尝试启动 Solr:

WARNING: Starting Solr as the root user is a security risk and not considered best practice. Exiting.
         Please consult the Reference Guide. To override this check, start with argument '-force'

ERROR: Failed to start Solr using command: "/usr/local/java/solr-7.4.0/bin/solr" start -cloud -p 8983 -s "/usr/local/java/solr-7.4.0/example/cloud/node1/solr" Exception : org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)

orz,结果告诉笔者不能用 root 用户启动 Solr。当然,可以使用 -force 参数强行跳过这个检测,但既然官方说这样做不好,那就乖乖听话吧。(换用户就换用户,您开心就好。)

su panda
问题3:文件读写权限

笔者又满心欢喜地重新尝试启动 Solr:

ERROR: Logs directory /usr/local/java/solr-7.4.0/example/cloud/node1/solr/../logs could not be created. Exiting

ERROR: Failed to start Solr using command: "/usr/local/java/solr-7.4.0/bin/solr" start -cloud -p 8983 -s "/usr/local/java/solr-7.4.0/example/cloud/node1/solr" Exception : org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)

结果被告知没有权限创建日志文件。

好吧,才想起来自己现在不是 root 用户,要先为 Solr 文件夹设置文件读写权限。

root@panda:/usr/local/java# chmod -R 777 solr-7.4.0/

OK,至此所有问题都解决啦!

猜你喜欢

转载自blog.csdn.net/magicpenta/article/details/81631158