這篇文章主要是介紹在Centos6上Solr6.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
此文使用的是centos6.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的安裝完畢。
下一篇將介紹創建core並加上中文分詞的配置。