阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 6.6上安装与配置Solr 6.5

225次阅读
没有评论

共计 19877 个字符,预计需要花费 50 分钟才能阅读完成。

这篇文章主要是介绍在 CentOS 6.6 上 Solr 6.5 的安装与配置。

一、安装准备及各软件使用版本说明:

1、JDK8, 版本 jdk1.8.0_121 下载地址:jdk-8u121-linux-x64.tar.gz

2、Apache Tomcat,版本 8.5.13 下载地址:apache-tomcat-8.5.13.tar.gz

3、Solr, 版本 solr-6.5.0, 下载地址:solr-6.5.0.tgz

此文使用的是 CentOS 6.6 的系统。在系统根目录下建立 down 目录。然后依次下载上面的三个软件。下载完成后如下:

/down
├── apache-tomcat-8.5.12.tar.gz
├── jdk-8u121-linux-x64.tar.gz
└── solr-6.5.0.tgz

二、jdk 安装与配置:

1、安装

cd /down 
tar -zxvf jdk-8u121-linux-x64.tar.gz // 解压缩 jdk 包 
解压后 jdk 的路径应该为 
/down/jdk1.8.0_121/ 

2、配置:

修改系统环境变量文件:

vi /etc/profile 

向文件里面追加以下内容:

Java_HOME=/down/jdk1.8.0_121 
JRE_HOME=/down/jdk1.8.0_121/jre 
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib 
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin 
export JAVA_HOME JRE_HOME CLASS_PATH PATH 

是修改生效:

[root@admin local]# source /etc/profile  // 使修改立即生效 
[root@admin local]# echo $PATH  // 查看 PATH 值 

查看系统环境状态:

[root@localhost down]# echo $PATH 
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/down/jdk1.8.0_121/bin:/down/jdk1.8.0_121/jre/bin:/root/bin 
[root@localhost down]# 

查看 JAVA 版本:

[root@localhost down]# java -version 
java version “1.8.0_121” 
Java(TM) SE Runtime Environment (build 1.8.0_121-b13) 
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode) 
[root@localhost down]# 

至此 jdk 安装完毕。

三、Solr 安装与配置:

 1、解压 apache-tomcat-8.5.12.tar.gz 和 solr-6.5.0.tgz

[root@localhost down]# tar -zxvf apache-tomcat-8.5.12.tar.gz 
[root@localhost down]# tar -zxvf solr-6.5.0.tgz 
 
解压后的目录结构: 
[root@localhost down]# ls 
apache-tomcat-8.5.12        jdk1.8.0_121                solr-6.5.0 
apache-tomcat-8.5.12.tar.gz  jdk-8u121-linux-x64.tar.gz  solr-6.5.0.tgz 

2、复制 Solr 文件夹中的一些文件到 apache-tomcat 下:

1)将 solr 压缩包中 solr\server\solr-webapp\ 文件夹下有个 webapp 文件夹,将之复制到 tomcat\webapps\ 目录下,文件夹名改成 solr(任意);

2)将 solr 压缩包中 solr\server\lib\ext 中的 jar 全部复制到 Tomcat\ webapps\solr\WEB-INF\lib 目录中;

3)将 solr 压缩包中 solr/server/lib/metrics* 开头的 jar 全部复制到 Tomcat\ webapps\solr\WEB-INF\lib 目录中;

4)将 solr 压缩包中 solr/server/lib/solr-dataimporthandler-* 开头的 jar 全部复制到 Tomcat\ webapps\solr\WEB-INF\lib 目录中;

5)在 Tomcat\ webapps\solr\WEB-INF\ 下建立 classes 目录,并将 solr/server/resources/log4j.properties 文件复制其中;

6)在 tomcat 目录下建立 solrhome 目录(也可以放在其它目录中)

7)复制solr/server/solr/* 所有文件到 tomcat/solrhome 目录,用到创建 solr 的 core 时使用。

操作 shell 如下:

[root@localhost down]# cd /down 
[root@localhost down]# cp -R /down/solr-6.5.0/server/solr-webapp/webapp /down/apache-tomcat-8.5.12/webapps/solr 
[root@localhost down]# cp -R /down/solr-6.5.0/server/lib/ext/*  /down/apache-tomcat-8.5.12/webapps/solr/WEB-INF/lib/ 
[root@localhost down]# cp -R /down/solr-6.5.0/server/lib/metrics*.*  /down/apache-tomcat-8.5.12/webapps/solr/WEB-INF/lib/ 
[root@localhost down]# cp /down/solr-6.5.0/dist/solr-dataimporthandler-*  /down/apache-tomcat-8.5.12/webapps/solr/WEB-INF/lib/ 
[root@localhost down]# mkdir /down/apache-tomcat-8.5.12/webapps/solr/WEB-INF/classes 
[root@localhost down]# cp /down/solr-6.5.0/server/resources/log4j.properties  /down/apache-tomcat-8.5.12/webapps/solr/WEB-INF/classes/ 
[root@localhost down]# mkdir /down/apache-tomcat-8.5.12/solrhome 
[root@localhost down]# cp -R /down/solr-6.5.0/server/solr/*  /down/apache-tomcat-8.5.12/solrhome/ 

3、配置 Solr:

编辑 web.xml 文件:

[root@localhost down]# vi /down/apache-tomcat-8.5.12/webapps/solr/WEB-INF/web.xml   

1)配置 solr 下 core 路径,找如下配置内容(初始状态下该内容是被注释掉的):

<env-entry> 
  <env-entry-name>solr/home</env-entry-name> 
  <env-entry-value>/down/apache-tomcat-8.5.12/solrhome</env-entry-value> // 将路径指向我们创建的 solrhome 目录。
  <env-entry-type>java.lang.String</env-entry-type> 
</env-entry> 

2)配置访问权限:找到如下内容,并注释掉:

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

整个 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” 

 
 
  <!– Uncomment if you are trying to use a Resin version before 3.0.19. 
    Their XML implementation isn’t entirely compatible with Xerces. 
    Below are the implementations to use with Sun’s JVM. 
  <system-property javax.xml.xpath.XPathFactory= 
            “com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl”/> 
  <system-property javax.xml.parsers.DocumentBuilderFactory= 
            “com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl”/> 
  <system-property javax.xml.parsers.SAXParserFactory= 
            “com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl”/> 
  –> 
 
  <!– People who want to hardcode their “Solr Home” directly into the 
      WAR File can set the JNDI property here… 
  –> 
    <env-entry> 
      <env-entry-name>solr/home</env-entry-name> 
      <env-entry-value>/down/apache-tomcat-8.5.12/solrhome</env-entry-value> 
      <env-entry-type>java.lang.String</env-entry-type> 
    </env-entry> 
   
  <!– 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>/libs/.+,/css/.+,/js/.+,/img/.+,/tpl/.+</param-value> 
    </init-param> 
  </filter> 
 
  <filter-mapping> 
    <!– 
      NOTE: When using multicore, /admin JSP URLs with a core specified 
      such as /solr/coreName/admin/stats.jsp get forwarded by a 
      RequestDispatcher to /solr/admin/stats.jsp with the specified core 
      put into request scope keyed as “org.apache.solr.SolrCore”. 
 
      It is unnecessary, and potentially problematic, to have the SolrDispatchFilter 
      configured to also filter on forwards.  Do not configure 
      this dispatcher as <dispatcher>FORWARD</dispatcher>. 
    –> 
    <filter-name>SolrRequestFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
  </filter-mapping> 
 
  <servlet> 
    <servlet-name>LoadAdminUI</servlet-name> 
    <servlet-class>org.apache.solr.servlet.LoadAdminUiServlet</servlet-class> 
  </servlet> 
   
  <!– Remove in Solr 5.0 –> 
  <!– This sends SC_MOVED_PERMANENTLY (301) for resources that changed in 4.0 –> 
  <servlet> 
    <servlet-name>RedirectOldAdminUI</servlet-name> 
    <servlet-class>org.apache.solr.servlet.RedirectServlet</servlet-class> 
    <init-param> 
      <param-name>destination</param-name> 
      <param-value>${context}/#/</param-value> 
    </init-param> 
  </servlet> 
   
  <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> 
    <servlet-name>RedirectLogging</servlet-name> 
    <servlet-class>org.apache.solr.servlet.RedirectServlet</servlet-class> 
    <init-param> 
      <param-name>destination</param-name> 
      <param-value>${context}/#/~logging</param-value> 
    </init-param> 
  </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>RedirectOldAdminUI</servlet-name> 
    <url-pattern>/admin/</url-pattern> 
  </servlet-mapping> 
  <servlet-mapping> 
    <servlet-name>RedirectOldAdminUI</servlet-name> 
    <url-pattern>/admin</url-pattern> 
  </servlet-mapping> 
  <servlet-mapping> 
    <servlet-name>RedirectOldZookeeper</servlet-name> 
    <url-pattern>/zookeeper.jsp</url-pattern> 
  </servlet-mapping> 
  <servlet-mapping> 
    <servlet-name>RedirectOldZookeeper</servlet-name> 
    <url-pattern>/zookeeper</url-pattern> 
  </servlet-mapping> 
  <servlet-mapping> 
    <servlet-name>RedirectLogging</servlet-name> 
    <url-pattern>/logging</url-pattern> 
  </servlet-mapping> 
 
  <servlet-mapping> 
    <servlet-name>LoadAdminUI</servlet-name> 
    <url-pattern>/old.html</url-pattern> 
  </servlet-mapping> 
 
  <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> 
  –> 
</web-app> 

至此 solr 的配置工作完成

四、运行 Solr:

 启动执行:/down/apache-tomcat-8.5.12/bin/startup.sh

[root@localhost down]# /down/apache-tomcat-8.5.12/bin/startup.sh 
Using CATALINA_BASE:  /down/apache-tomcat-8.5.12 
Using CATALINA_HOME:  /down/apache-tomcat-8.5.12 
Using CATALINA_TMPDIR: /down/apache-tomcat-8.5.12/temp 
Using JRE_HOME:        /down/jdk1.8.0_121/jre 
Using CLASSPATH:      /usr/local/tomcat/bin/bootstrap.jar:/down/apache-tomcat-8.5.12/bin/tomcat-juli.jar 
Tomcat started. 
[root@localhost down]# 

在浏览器输入 http://localhost:8080/solr/index.html 即可出现 Solr 的管理界面

关闭 solr 只需要关闭 tomcat 即可:

[root@localhost down]# /down/apache-tomcat-8.5.12/bin/shutdown.sh 

至此 solr 的安装完毕。

更多 Solr 相关教程见以下内容

Solr3.6.1 在 Tomcat6 下的环境搭建 http://www.linuxidc.com/Linux/2013-01/77664.htm

Apache Solr: 安装和运行 http://www.linuxidc.com/Linux/2016-12/138527.htm

在 Ubuntu 12.04 LTS 上通过 Tomcat 部署 Solr 4 http://www.linuxidc.com/Linux/2012-09/71158.htm

Solr 实现 Low Level 查询解析(QParser)http://www.linuxidc.com/Linux/2012-05/59755.htm

Solr6.0.0 + Tomcat8 配置问题 http://www.linuxidc.com/Linux/2016-05/131845.htm

基于 Solr 3.5 搭建搜索服务器 http://www.linuxidc.com/Linux/2012-05/59743.htm

Solr 3.5 开发应用教程 PDF 高清版 http://www.linuxidc.com/Linux/2013-10/91048.htm

CentOS 6.7 下单机部署 Solr 7.1.0  http://www.linuxidc.com/Linux/2017-12/149889.htm

Solr 4.0 部署实例教程 http://www.linuxidc.com/Linux/2013-10/91041.htm

Solr 的详细介绍:请点这里
Solr 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-12/149891.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计19877字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中