Solr Centos6.5下安裝solr7.2

部署配置單機版solrcss

1.把solr-7.2.0/server/solr-webapp裏面的webapp拷貝到tomcat 的webapps下,重命名爲solrhtml

 
 
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下java

 
 
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下web

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

blob.png

4.修改/data/soft/tomcat/webapps/solr/WEB-INF\web.xml, 找到以下代碼,藍色部分的,/put/your/solr/home/here 改成你本身的solrhome的路徑,個人是/data/soft/solrhome路徑。express

   vim /data/soft/tomcat/webapps/solr/WEB-INF/web.xml,將註釋去掉,並將solrhome的目錄位置寫進去:apache

 
 
<!-- <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> -->

 
 
 

以下圖:vim

 blob.png

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#/tomcat

blob.png

 看下日誌,若是日誌有下面這個樣式就成功了。app

blob.png

 在本機上curl一下,發現403,那麼估計頁面也是這樣,以下圖。

blob.png

blob.png

 7.注意:若是出現上圖403錯誤,編輯web.xml照片截圖中位置,找到以下代碼,將其註釋便可。

blob.png

 加上註釋以下圖:

blob.png

 

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>



 

 再次刷新瀏覽器,會出現下圖的頁面。blob.png

配置solr的核心內容(core)
1.點擊Core Admin,接着點擊Add Core這項,點完以後會出現問題,可是會自動建立new-core目錄。

blob.png

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,此時會顯示添加成功

 

blob.png

 四、配置中文分析器

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>
 

以下圖:

blob.png

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"/>

 
 
 

以下圖:

blob.png

5.重啓tomcat,就能發現自定義域已經出現

blob.png

6.測試分詞效果

blob.png

 

 轉載自http://www.javashuo.com/article/p-bpskkgsa-ed.html

相關文章
相關標籤/搜索