当前位置:首页 > 服务端 > Solr Centos6.5下安装solr7.2

Solr Centos6.5下安装solr7.2

2022年11月10日 11:12:30服务端14

部署配置单机版solr

1.把solr-7.2.0/server/solr-webapp里面的webapp拷贝到tomcat 的webapps下,重命名为solr

 
   
cp -r solr-7.2.1/server/solr-webapp/webapp/ /data/soft/tomcat/webapps/
mv webapp/ solr

 
   
 

2.拷贝solr-7.2.1\server\lib\ext 下的jar包以及lib目录下gmetric4j-1.0.7.jar,以metrics开头的jar包拷贝到 tomcat\webapps\solr 项目的WEB-INF\lib下

 
   
cd solr-7.2.1/server/lib/ext/
cp * /data/soft/tomcat/webapps/solr/WEB-INF/lib/
cp gmetric4j-1.0.7.jar metrics-* /data/soft/tomcat/webapps/solr/WEB-INF/lib/

 
   
 

3.拷贝solr-7.2.0\server 下的solr文件夹到其它非中文目录下,重命名为solrhome,我是建立到了/data/soft下

 cd solr-7.2.1/server/
 cp -r solr /data/soft/solrhome
 

Solr Centos6.5下安装solr7.2 _ JavaClub全栈架构师技术笔记

4.修改/data/soft/tomcat/webapps/solr/WEB-INF\web.xml, 找到如下代码,蓝色部分的,/put/your/solr/home/here 改为你自己的solrhome的路径,我的是/data/soft/solrhome路径。

   vim /data/soft/tomcat/webapps/solr/WEB-INF/web.xml,将注释去掉,并将solrhome的目录位置写进去:

 
   
<!--
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/put/your/solr/home/here</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
-->

 
   
 

如下图:

 Solr Centos6.5下安装solr7.2 _ JavaClub全栈架构师技术笔记

5..拷贝solr7.2.1\server\resources下的log4j.properties到/data/soft/tomcat/webapps/solr/WEB-INF\classes,如果WEB-INF下没有classes文件那么就创建一个classes文件夹

 
   
mkdir -p /data/soft/tomcat/webapps/solr/WEB-INF/classes
cp solr-7.2.1/server/resources/log4j.properties  /data/soft/tomcat/webapps/solr/WEB-INF/classes/

 
   
 

6.启动tomcat,访问需要完整路径,我的是http://192.168.241.131:8080/solr/index.html#/

Solr Centos6.5下安装solr7.2 _ JavaClub全栈架构师技术笔记

 看下日志,如果日志有下面这个样式就成功了。

Solr Centos6.5下安装solr7.2 _ JavaClub全栈架构师技术笔记

 在本机上curl一下,发现403,那么估计页面也是这样,如下图。

Solr Centos6.5下安装solr7.2 _ JavaClub全栈架构师技术笔记

Solr Centos6.5下安装solr7.2 _ JavaClub全栈架构师技术笔记

 7.注意:如果出现上图403错误,编辑web.xml照片截图中位置,找到如下代码,将其注释即可。

Solr Centos6.5下安装solr7.2 _ JavaClub全栈架构师技术笔记

 加上注释如下图:

Solr Centos6.5下安装solr7.2 _ JavaClub全栈架构师技术笔记

 

web.xml



<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"
metadata-complete="true"
>

<!-- Any path (name) registered in solrconfig.xml will be sent to that filter -->
<filter>
<filter-name>SolrRequestFilter</filter-name>
<filter-class>org.apache.solr.servlet.SolrDispatchFilter</filter-class>
<!--
Exclude patterns is a list of directories that would be short circuited by the
SolrDispatchFilter. It includes all Admin UI related static content.
NOTE: It is NOT a pattern but only matches the start of the HTTP ServletPath.
-->
<init-param>
<param-name>excludePatterns</param-name>
<param-value>/partials/.+,/libs/.+,/css/.+,/js/.+,/img/.+,/templates/.+</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>SolrRequestFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/home/hadoop/solrhome</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>


<servlet>
<servlet-name>LoadAdminUI</servlet-name>
<servlet-class>org.apache.solr.servlet.LoadAdminUiServlet</servlet-class>
</servlet>

<servlet>
<servlet-name>SolrRestApi</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.application</param-name>
<param-value>org.apache.solr.rest.SolrSchemaRestApi</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>LoadAdminUI</servlet-name>
<url-pattern>/index.html</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>SolrRestApi</servlet-name>
<url-pattern>/schema/*</url-pattern>
</servlet-mapping>

<mime-mapping>
<extension>.xsl</extension>
<!-- per http://www.w3.org/TR/2006/PR-xslt20-20061121/ -->
<mime-type>application/xslt+xml</mime-type>
</mime-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

<!-- Get rid of error message -->
<!--<security-constraint>
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"
metadata-complete="true"
>

<!-- Any path (name) registered in solrconfig.xml will be sent to that filter -->
<filter>
<filter-name>SolrRequestFilter</filter-name>
<filter-class>org.apache.solr.servlet.SolrDispatchFilter</filter-class>
<!--
Exclude patterns is a list of directories that would be short circuited by the
SolrDispatchFilter. It includes all Admin UI related static content.
NOTE: It is NOT a pattern but only matches the start of the HTTP ServletPath.
-->
<init-param>
<param-name>excludePatterns</param-name>
<param-value>/partials/.+,/libs/.+,/css/.+,/js/.+,/img/.+,/templates/.+</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>SolrRequestFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/home/hadoop/solrhome</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>


<servlet>
<servlet-name>LoadAdminUI</servlet-name>
<servlet-class>org.apache.solr.servlet.LoadAdminUiServlet</servlet-class>
</servlet>

<servlet>
<servlet-name>SolrRestApi</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.application</param-name>
<param-value>org.apache.solr.rest.SolrSchemaRestApi</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>LoadAdminUI</servlet-name>
<url-pattern>/index.html</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>SolrRestApi</servlet-name>
<url-pattern>/schema/*</url-pattern>
</servlet-mapping>

<mime-mapping>
<extension>.xsl</extension>
<!-- per http://www.w3.org/TR/2006/PR-xslt20-20061121/ -->
<mime-type>application/xslt+xml</mime-type>
</mime-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

<!-- Get rid of error message -->
<!--<security-constraint>
<web-resource-collection>
<web-resource-name>Disable TRACE</web-resource-name>
<url-pattern>/</url-pattern>
<http-method>TRACE</http-method>
</web-resource-collection>
<auth-constraint/>
</security-constraint>-->
<security-constraint>
<web-resource-collection>
<web-resource-name>Enable everything but TRACE</web-resource-name>
<url-pattern>/</url-pattern>
<http-method-omission>TRACE</http-method-omission>
</web-resource-collection>
</security-constraint>

<!--
RedirectServlet can be used to redirect old endpoints to a new location to support back compatibility.
Example below
-->
<!--
<servlet>
<servlet-name>RedirectOldZookeeper</servlet-name>
<servlet-class>org.apache.solr.servlet.RedirectServlet</servlet-class>
<init-param>
<param-name>destination</param-name>
<param-value>${context}/admin/zookeeper</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>RedirectOldZookeeper</servlet-name>
<url-pattern>/zookeeper</url-pattern>
</servlet-mapping>
-->
</web-app>



 

 再次刷新浏览器,会出现下图的页面。Solr Centos6.5下安装solr7.2 _ JavaClub全栈架构师技术笔记

配置solr的核心内容(core)
1.点击Core Admin,接着点击Add Core这项,点完之后会出现问题,但是会自动创建new-core目录。

Solr Centos6.5下安装solr7.2 _ JavaClub全栈架构师技术笔记

2.报错,提示缺少配置文件:Error CREATEing SolrCore 'new_core': Unable to create core [new_core] Caused by: Can't find resource 'solrconfig.xml' in classpath or '/data/soft/solrhome/new_core'

解决方法:拷贝server/solr/configsets/_default/下的conf文件夹到solrhome/new_core文件夹下

 
   
cp -r solr-7.2.1/server/solr/configsets/_default/conf  /data/soft/solrhome/new_core/

 
   
 

3.点击Add Core,此时会显示添加成功

 

Solr Centos6.5下安装solr7.2 _ JavaClub全栈架构师技术笔记

 4、配置中文分析器

1.拷贝dist文件夹里的solr-dataimporthandler-7.2.0.jar
 
   
cp  solr-7.2.1/dist/solr-dataimporthandler-7.2.1.jar /data/soft/tomcat/webapps/solr/WEB-INF/lib/

 
   
 

2.拷贝lucene-libs文件夹里的中文分析器的jar包

 
   
cp  solr-7.2.1/contrib//analysis-extras/lucene-libs/* /data/soft/tomcat/webapps/solr/WEB-INF/lib/

 
   
 
 
   
 vim solrhome/new_core/conf/managed-schema



<!-- ChineseAnalyzer -->
<fieldType name="text_ik" class="solr.TextField" positionIncrementGap="100"> <analyzer type="index"> <tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/> </analyzer> <analyzer type="query"> <tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/> </analyzer> </fieldType>
 

如下图:

Solr Centos6.5下安装solr7.2 _ JavaClub全栈架构师技术笔记

4.自定义搜索业务域

 
   
<field name="item_title" type="text_ik" indexed="true" stored="true"/> <field name="item_sell_point" type="text_ik" indexed="true" stored="true"/> <field name="item_price" type="plong" indexed="true" stored="true"/> <field name="item_image" type="string" indexed="false" stored="true" /> <field name="item_category_name" type="string" indexed="true" stored="true" /> <field name="item_desc" type="text_ik" indexed="true" stored="false" /> <field name="item_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/> <copyField source="item_title" dest="item_keywords"/> <copyField source="item_sell_point" dest="item_keywords"/> <copyField source="item_category_name" dest="item_keywords"/> <copyField source="item_desc" dest="item_keywords"/>

 
   
 

如下图:

Solr Centos6.5下安装solr7.2 _ JavaClub全栈架构师技术笔记

5.重启tomcat,就能发现自定义域已经出现

Solr Centos6.5下安装solr7.2 _ JavaClub全栈架构师技术笔记

6.测试分词效果

Solr Centos6.5下安装solr7.2 _ JavaClub全栈架构师技术笔记

 

 转载自https://blog.51cto.com/12889016/2103167

作者:Transkai
来源链接:https://www.cnblogs.com/Transkai/p/11018775.html

版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。


本文链接:https://www.javaclub.cn/server/69244.html

标签: SolrCentOS
分享给朋友: