solr企业级搜索引擎的安装与配置

一、solr的概念和功能

1、solr是将整个索引操作功能封装好了的搜索引擎系统(企业级搜索引擎产品)

2、solr可以部署到单独的服务器上(WEB服务),它可以提供服务,我们的业务系统就只要发送请求,接收响应即可,降低了业务系统的负载

3、solr部署在专门的服务器上,它的索引库就不会受业务系统服务器存储空间的限制

4、solr支持分布式集群,索引服务的容量和能力可以线性扩展

solr的工作机制:

1、solr就是在lucene工具包的基础之上进行了封装,而且是以web服务的形式对外提供索引功能

2、业务系统需要使用到索引的功能(建索引,查索引)时,只要发出http请求,并将返回数据进行解析即可

Solr 是Apache下的一个顶级开源项目,采用Java开发,它是基于Lucene的全文搜索服务器。Solr提供了比Lucene更为丰富的查询语言,同时实现了可配置、可扩展,并对索引、搜索性能进行了优化。

Solr可以独立运行,运行在Jetty、Tomcat等这些Servlet容器中,Solr 索引的实现方法很简单,用 POST 方法向 Solr 服务器发送一个描述 Field 及其内容的 XML 文档,Solr根据xml文档添加、删除、更新索引 。Solr 搜索只需要发送 HTTP GET 请求,然后对 Solr 返回Xml、json等格式的查询结果进行解析,组织页面布局。Solr不提供构建UI的功能,Solr提供了一个管理界面,通过管理界面可以查询Solr的配置和运行情况。

就是一个web工程

Solr和lucene区别

Lucene是一个开放源代码的全文检索引擎工具包,它不是一个完整的全文检索引擎,Lucene提供了完整的查询引擎和索引引擎,目的是为软件开发人员提供一个简单易用的工具包,以方便的在目标系统中实现全文检索的功能,或者以Lucene为基础构建全文检索引擎。

Solr的目标是打造一款企业级的搜索引擎系统,它是一个搜索引擎服务,可以独立运行,通过Solr可以非常快速的构建企业的搜索引擎,通过Solr也可以高效的完成站内搜索功能。

Solr的下载

http://lucene.apache.org/

最新版本为8.5.0

本次安装版本是8.1.0

二、安装步骤

1、解压安装包

[root@harlan tools]# tar -xf solr-8.1.0.tgz 
[root@harlan tools]# mv solr-8.1.0 /application/

 [root@harlan application]# ls
   solr-8.1.0 
  [root@harlan application]# ln -s solr-8.1.0 solr
  [root@harlan application]# ll
  总用量 0
  lrwxrwxrwx 1 root root 10 5月 9 11:18 solr -> solr-8.1.0

2、安装包里面有完整的依赖,解压后可以直接启动

[root@harlan application]# /application/solr/bin/solr start
*** [WARN] ***  Your Max Processes Limit is currently 14989. 
 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
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'

上述提示是使用root帐户启动时,必须在启动命令后面加上参数" -force ",再次带上参数启动

[root@harlan application]# /application/solr/bin/solr start -force
*** [WARN] ***  Your Max Processes Limit is currently 14989. 
 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
NOTE: Please install lsof as this script needs it to determine if Solr is listening on port 8983.

Started Solr server on port 8983 (pid=80610). Happy searching!

由上述命令可知,solr已启动成功,http访问端口为:8983

3、在浏览器上访问:http://本机IP:8983 如出现下图,说明solr启动成功。

 三、创建core

 1、创建一个core,并将安装包中的example中的配置文件复制过去

# 创建 core 目录在
mkdir -p /application/solr/server/solr/mycore
# 复制例子配置文件到新建 core 目录下

[root@harlan solr]# cp -rf /application/solr/example/example-DIH/solr/solr/* /application/solr/server/solr/mycore/

2、根据修改后的core来添加core.如下图所示:

 

 三、使用中文分词

 1、Solr 不能对中文进行分词,ikanalyzer可以

 2、下载ikanalyzer

下载地址:https://search.maven.org/search?q=com.github.magese

 下载7.x的版本

将下载的jar文件拷贝到/application/solr/server/solr-weapps/weapps/WEB-INF/lib/

[root@harlan tools]# cp ik-analyzer-solr7-7.x.jar /application/solr/server/solr-webapp/webapp/WEB-INF/lib/

3、修改mycore目录下的managed-schema文件,在其中添加以下内容。将ik-analyzer分词器在浏览器上启用起来。

<!-- ik分词器 -->
        <fieldType name="text_ik" class="solr.TextField">
          <analyzer type="index">
                  <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="false" conf="ik.conf"/>
                  <filter class="solr.LowerCaseFilterFactory"/>
          </analyzer>
          <analyzer type="query">
                  <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="true" conf="ik.conf"/>
                  <filter class="solr.LowerCaseFilterFactory"/>
          </analyzer>
        </fieldType>

4、重启solr

[root@harlan tools]# /application/solr/bin/solr restart -force
*** [WARN] ***  Your Max Processes Limit is currently 14989. 
 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
Sending stop command to Solr running on port 8983 ... waiting up to 180 seconds to allow Jetty process 80610 to stop gracefully.
NOTE: Please install lsof as this script needs it to determine if Solr is listening on port 8983.

5、重新访问浏览器

 

原文地址:https://www.cnblogs.com/eeexu123/p/12856972.html