CentOS7安装部署Solr
相关说明
-
centOS版本
linux查看系统版本命令:
cat /etc/redhat-release[root@localhost /]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [root@localhost /]# -
在安装部署Solr之前请确认安装JDK1.8以上和Tomcat8以上,tomcat可以不用安装使用solr自带的jetty
本教程使用的是JDK1.8和tomcat9.0.76,tomcat开发端口为端口为8001,也就是tomcat是提前配置好的
路径解释:
- /usr/local/hy/tomcat9/tomcatsolr/ #tomcat目录端口8001
- /usr/local/hy/solr7/ #solr上传到的目录
获取安装包并解压
-
官网获取下载地址并获取安装包
下载地址: archive.apache.org/dist/lucene…
从官网下载到合适的安装包后上传到linux安装目录.
-
进入安装目录解压,在解压完成之后可以选择把压缩包删除
tar -zxvf solr-7.3.1.tgz
部署配置solr
-
把solr-7.3.1/server/solr-webapp里面的webapp拷贝到tomcat 的webapps下,重命名为solr
cp -r /usr/local/hy/solr7/solr-7.3.1/server/solr-webapp/webapp/ /usr/local/hy/tomcat9/tomcatsolr/webapps/
cd /usr/local/hy/tomcat9/tomcatsolr/webapps/
mv webapp solr
-
拷贝solr-7.3.1\server\lib\ext 下的jar包以及lib目录下gmetric4j-1.0.7.jar,以metrics开头的jar包拷贝到 tomcat\webapps\solr 项目的WEB-INF\lib下
cd /usr/local/hy/solr7/solr-7.3.1/server/lib/ext/ cp * /usr/local/hy/tomcat9/tomcatsolr/webapps/solr/WEB-INF/lib/ cd ../ cp gmetric4j-1.0.7.jar metrics-* /usr/local/hy/tomcat9/tomcatsolr/webapps/solr/WEB-INF/lib/
-
拷贝solr-7.3.1\server 下的solr文件夹到其它非中文目录下,重命名为solrhome
cd /usr/local/hy/solr7/solr-7.3.1/server/ cp -r solr /usr/local/hy/tomcat9/tomcatsolr/ cd /usr/local/hy/tomcat9/tomcatsolr/ mv solr solrhome
-
修改/usr/local/hy/tomcat9/tomcatsolr/webapps/solr/WEB-INF/web.xml, 找到如下代码,将注释去掉,并将solrhome的目录位置写进去。找到Disable TRACE把第二个代码块中的代码注释掉。
cd /usr/local/hy/tomcat9/tomcatsolr/webapps/solr/WEB-INF/ vim web.xml
<env-entry> <env-entry-name>solr/home</env-entry-name> <env-entry-value>/usr/local/hy/tomcat9/tomcatsolr/solrhome</env-entry-value> <env-entry-type>java.lang.String</env-entry-type> </env-entry><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> -
.拷贝solr-7.3.1\server\resources下的log4j.properties到/usr/local/hy/tomcat9/tomcatsolr/webapps/solr/WEB-INF\classes,如果WEB-INF下没有classes文件那么就创建一个classes文件夹
mkdir clases cp /usr/local/hy/solr7/solr-7.3.1/server/resources/log4j.properties /usr/local/hy/tomcat9/tomcatsolr/webapps/solr/WEB-INF/classes cp -r /usr/local/hy/solr7/solr-7.3.1/server/solr/configsets/_default/conf /usr/local/hy/tomcat9/tomcatsolr/solrhome/new_core/
配置ik分词器
-
拷贝dist文件夹里的solr-dataimporthandler-7.2.0.jar
cp /usr/local/hy/solr7/solr-7.3.1/dist/solr-dataimporthandler-7.3.1.jar /usr/local/hy/tomcat9/tomcatsolr/webapps/solr/WEB-INF/lib/
-
拷贝lucene-libs文件夹里的中文分析器的jar包
cp /usr/local/hy/solr7/solr-7.3.1/contrib/analysis-extras/lucene-libs/* /usr/local/hy/tomcat9/tomcatsolr/webapps/solr/WEB-INF/lib/
-
引入Jar包,编辑/usr/local/hy/tomcat9/tomcatsolr/solrhome/new_core/conf/managed-schema文件,添加代码块中的代码
vim /usr/local/hy/tomcat9/tomcatsolr/solrhome/new_core/conf/managed-schema
#添加以下代码 <!-- ChineseAnalyzer ik分词器 --> <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> -
自定义搜索业务域
vim /usr/local/hy/tomcat9/tomcatsolr/solrhome/new_core/conf/managed-schema
<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"/>
启动Tomcat
/usr/local/hy/tomcat9/tomcatsolr/bin/./startup.sh