Linux 搭建solr单机服务

solr简介

Solr是一款优秀的基于Lucene的全文检索服务器,它对Lucene进行了扩展,提供了非常丰富的查询语言,并对查询进行了性能优化。

SolrLucene都由Apache Software Foundation(www.apache.org)管理。

Apache Solr 参考指南

环境准备

Linux版本:Linux version 3.8.13-26.1.1.el6uek.x86_64 (gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) )
Solr版本:solr-6.6.3
Jdk环境:1.8.0_161

注意事项

关闭防火墙

1
$ service iptables stop

Solr安装

下载Solr

下载最新版本的Solr

1
$ wget https://mirrors.tuna.tsinghua.edu.cn/apache/lucene/solr/6.6.3/solr-6.6.3.zip

提取zip文件

1
2
$ unzip -xvf solr-6.6.3.zip
$ cd solr-6.6.3

Solr操作

启动服务

说明:加 -force 是因为solr不允许使用 root 进行操作的,其他账户可不加

1
$ bin/solr start -force

响应

1
2
3
4
5
Warning: Available entropy is low. As a result, use of the UUIDField, SSL, or any other features that require
RNG might not work properly. To check for the amount of available entropy, use 'cat /proc/sys/kernel/random/entropy_avail'.
Waiting up to 180 seconds to see Solr running on port 8983 [\]
Started Solr server on port 8983 (pid=12419). Happy searching!

启动Solr与不同的端口,要更改Solr监听端口,可以-p在启动时使用参数

1
$ bin/solr start -p 8984

访问管理UI

浏览器输入 ip:port 即:http://192.168.229.119:8983/solr

如果Solr没有运行,您的浏览器会抱怨说它无法连接到服务器。检查您的端口号,然后重试。

Solr欢迎页面

服务状态

如果您不确定Solr是否在本地运行

1
$ bin/solr status

响应

1
2
3
4
5
6
7
8
9
Found 1 Solr nodes:
Solr process 12419 running on port 8983
{
"solr_home":"/home/kiko/tools/solr-6.6.3/server/solr",
"version":"6.6.3 d1e9bbd333ea55cfa0c75d324424606e857a775b - sarowe - 2018-03-02 15:09:34",
"startTime":"2018-04-27T04:25:39.582Z",
"uptime":"0 days, 1 hours, 46 minutes, 35 seconds",
"memory":"33.6 MB (%6.8) of 490.7 MB"}

表示Solr服务启动正常

创建Solr库

1
$ bin/solr create -c <name>

说明:加 -force 是因为solr不允许使用 root 进行操作的,其他账户可不加

1
$ /home/kiko/tools/solr-6.6.3/bin/solr create -c test -force

响应

1
2
3
4
5
6
7
8
9
10
11
Copying configuration to new core instance directory:
/home/kiko/tools/solr-6.6.3/server/solr/test
Creating new core 'test' using command:
http://localhost:8983/solr/admin/cores?action=CREATE&name=test&instanceDir=test
{
"responseHeader":{
"status":0,
"QTime":2146},
"core":"test"}

浏览器输入 ip:port

http://192.168.229.119:8983/solr

Solr欢迎页面

停止服务

1
$ /home/kiko/tools/solr-6.6.3/bin/solr stop

响应

1
Sending stop command to Solr running on port 8983 ... waiting up to 180 seconds to allow Jetty process 12419 to stop gracefully.

可以使用该-all参数来停止所有运行的Solr实例

1
$ /home/kiko/tools/solr-6.6.3/bin/solr stop -all

本文参考:http://www.ymq.io/2017/08/23/Solr/