学习淘淘商城第三十五课(Solr的安装)

来源:互联网 发布:excel多表格数据合计 编辑:程序博客网 时间:2024/06/05 09:31

        Solr是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口。用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文件,生成索引;也可以通过Http Get操作提出查找请求,并得到XML格式的返回结果。

       Solr是一个高性能,采用Java5开发,基于Lucene的全文搜索服务器。同时对其进行了扩展,提供了比Lucene更为丰富的查询语言,同时实现了可配置、可扩展并对查询性能进行了优化,并且提供了一个完善的功能管理界面,是一款非常优秀的全文搜索引擎。

       对于淘淘商城来讲,由于网上商城的搜索频率特别高,我们很有必要把搜索单独做成一个服务,这样做的好处是可以针对该服务做扩展,做成服务集群等。其它模块都可以调用solr服务。

      下面我们来搭建一下单机版的Solr服务器。

第一步:新建一台虚拟机

       大家可以参考http://blog.csdn.net/u012453843/article/details/68947589这篇博客进行学习

第二步:配置静态IP以及要能上网

       大家可以参考http://blog.csdn.net/u012453843/article/details/52839105这篇博客进行学习

第三步:使用XShell工具来操作我们的虚拟机

       大家可以参考http://blog.csdn.net/u012453843/article/details/54293774和http://blog.csdn.net/u012453843/article/details/68951776这两篇博客学习如何使用XShell来进行上传下载操作。

第四步:安装vim命令

       使用命令yum install vim-enhanced进行安装

第五步:安装JDK

       由于Solr是由Java开发的,因此安装Solr需要安装JDK,大家可以参考http://blog.csdn.net/u012453843/article/details/52422736这篇博客进行安装(该篇博客使用的操作工具是SecureCRT,与XShell工具有异曲同工之用)。

第六步:安装Solr

       首先到http://download.csdn.net/detail/u012453843/9822733这个地址下载solr-4.10.3.tgz.tgz。

       下面,我们在虚拟机的/usr/local/目录下新建software目录,如下所示。

[root@solr-server ~]# mkdir /usr/local/software

        我们把solr-4.10.3.tgz.tgz上传到/usr/local/software目录下,如下所示。

[root@solr-server software]# ll总用量 325416-rw-r--r--. 1 root root 183212596 4月   2 10:51 jdk-8u112-linux-x64.gz-rw-r--r--. 1 root root 150010621 3月  15 01:20 solr-4.10.3.tgz.tgz[root@solr-server software]# 

        下面解压solr安装包

[root@solr-server software]# tar -zxvf solr-4.10.3.tgz.tgz -C /usr/local/

         解压后到/usr/local目录下,可以看到解压后的solr-4.10.3目录。

[root@solr-server software]# cd /usr/local/[root@solr-server local]# ll总用量 48drwxr-xr-x. 2 root root 4096 9月  23 2011 bindrwxr-xr-x. 2 root root 4096 9月  23 2011 etcdrwxr-xr-x. 2 root root 4096 9月  23 2011 gamesdrwxr-xr-x. 2 root root 4096 9月  23 2011 includedrwxr-xr-x. 2 root root 4096 9月  23 2011 libdrwxr-xr-x. 2 root root 4096 9月  23 2011 lib64drwxr-xr-x. 2 root root 4096 9月  23 2011 libexecdrwxr-xr-x. 2 root root 4096 9月  23 2011 sbindrwxr-xr-x. 5 root root 4096 4月  23 16:36 sharedrwxr-xr-x. 2 root root 4096 4月  23 18:48 softwaredrwxr-xr-x. 8 root root 4096 4月  23 18:59 solr-4.10.3drwxr-xr-x. 2 root root 4096 9月  23 2011 src[root@solr-server local]# 

        我们进入到solr-4.10.3目录下,可以看到solr的所有文件目录,如下所示。其中bin目录使用jetty容器可以启动solr服务,但是我们一般不用这个。contrib目录下存放的是扩展包,我们一般也不用。

[root@solr-server local]# cd solr-4.10.3/[root@solr-server solr-4.10.3]# ll总用量 996drwxr-xr-x.  2 root root   4096 4月  23 18:59 bin-rw-r--r--.  1 root root 406208 12月 10 2014 CHANGES.txtdrwxr-xr-x. 13 root root   4096 12月 10 2014 contribdrwxr-xr-x.  4 root root   4096 4月  23 18:59 distdrwxr-xr-x. 17 root root   4096 4月  23 19:00 docsdrwxr-xr-x. 15 root root   4096 4月  23 18:59 exampledrwxr-xr-x.  2 root root  28672 4月  23 18:59 licenses-rw-r--r--.  1 root root  12646 12月  1 2014 LICENSE.txt-rw-r--r--.  1 root root 501873 12月  8 2014 LUCENE_CHANGES.txt-rw-r--r--.  1 root root  24655 12月  1 2014 NOTICE.txt-rw-r--r--.  1 root root   5344 12月  1 2014 README.txt-rw-r--r--.  1 root root    850 12月  1 2014 SYSTEM_REQUIREMENTS.txt[root@solr-server solr-4.10.3]# 

         我们看看dist目录下的内容,如下所示,可以看到solr-4.10.3.war,这个war包结合tomcat进行使用。solr-solrj-4.10.3.jar是我们的solr客户端。

-rw-r--r--. 1 root root 29741796 12月 10 2014 solr-4.10.3.war-rw-r--r--. 1 root root    17631 12月 10 2014 solr-analysis-extras-4.10.3.jar-rw-r--r--. 1 root root    30179 12月 10 2014 solr-cell-4.10.3.jar-rw-r--r--. 1 root root    51646 12月 10 2014 solr-clustering-4.10.3.jar-rw-r--r--. 1 root root  2852283 12月 10 2014 solr-core-4.10.3.jar-rw-r--r--. 1 root root   219326 12月 10 2014 solr-dataimporthandler-4.10.3.jar-rw-r--r--. 1 root root    37442 12月 10 2014 solr-dataimporthandler-extras-4.10.3.jardrwxr-xr-x. 2 root root     4096 4月  23 18:59 solrj-lib-rw-r--r--. 1 root root   767091 12月 10 2014 solr-langid-4.10.3.jar-rw-r--r--. 1 root root   129327 12月 10 2014 solr-map-reduce-4.10.3.jar-rw-r--r--. 1 root root    24630 12月 10 2014 solr-morphlines-cell-4.10.3.jar-rw-r--r--. 1 root root    42228 12月 10 2014 solr-morphlines-core-4.10.3.jar-rw-r--r--. 1 root root   451184 12月 10 2014 solr-solrj-4.10.3.jar-rw-r--r--. 1 root root   199743 12月 10 2014 solr-test-framework-4.10.3.jar-rw-r--r--. 1 root root    39744 12月 10 2014 solr-uima-4.10.3.jar-rw-r--r--. 1 root root    20302 12月 10 2014 solr-velocity-4.10.3.jardrwxr-xr-x. 4 root root     4096 4月  23 18:59 test-framework[root@solr-server dist]# 

         我们再看下example目录,这个目录下有一个很重要的目录,那就是solr目录,这个目录下存放都是Solr很重要的文件。

[root@solr-server solr-4.10.3]# cd example/[root@solr-server example]# ll总用量 104drwxr-xr-x. 2 root root  4096 4月  23 18:59 contextsdrwxr-xr-x. 2 root root  4096 4月  23 18:59 etcdrwxr-xr-x. 4 root root  4096 4月  23 18:59 example-DIHdrwxr-xr-x. 2 root root  4096 4月  23 18:59 exampledocsdrwxr-xr-x. 3 root root  4096 12月 10 2014 example-schemalessdrwxr-xr-x. 3 root root  4096 4月  23 18:59 libdrwxr-xr-x. 2 root root  4096 12月  1 2014 logsdrwxr-xr-x. 5 root root  4096 4月  23 18:59 multicore-rw-r--r--. 1 root root  2992 12月  1 2014 README.txtdrwxr-xr-x. 2 root root  4096 4月  23 18:59 resourcesdrwxr-xr-x. 4 root root  4096 12月 10 2014 scriptsdrwxr-xr-x. 4 root root  4096 4月  23 18:59 solrdrwxr-xr-x. 2 root root  4096 12月 10 2014 solr-webapp-rw-r--r--. 1 root root 46294 3月  12 2013 start.jardrwxr-xr-x. 2 root root  4096 4月  23 18:59 webapps[root@solr-server example]# 

第七步:安装tomcat

       大家可以到http://download.csdn.net/detail/u012453843/9794438这个地址下载apache-tomcat-7.0.47.tar.gz。

       下载完后,上传到虚拟机的/usr/local/software目录下,如下所示。

[root@solr-server software]# ll总用量 333460-rw-r--r--. 1 root root   8234674 3月  15 01:22 apache-tomcat-7.0.47.tar.gz-rw-r--r--. 1 root root 183212596 4月   2 10:51 jdk-8u112-linux-x64.gz-rw-r--r--. 1 root root 150010621 3月  15 01:20 solr-4.10.3.tgz.tgz[root@solr-server software]# 

        先解压apache到当前目录,解压的命令:tar -zxvf apache-tomcat-7.0.47.tar.gz,如下所示。

[root@solr-server software]# ll总用量 333464drwxr-xr-x. 9 root root      4096 4月  23 19:50 apache-tomcat-7.0.47-rw-r--r--. 1 root root   8234674 3月  15 01:22 apache-tomcat-7.0.47.tar.gz-rw-r--r--. 1 root root 183212596 4月   2 10:51 jdk-8u112-linux-x64.gz-rw-r--r--. 1 root root 150010621 3月  15 01:20 solr-4.10.3.tgz.tgz[root@solr-server software]# 

        我们在/usr/local目录下新建一个solr目录

[root@solr-server software]# mkdir /usr/local/solr

        然后我们将解压好的的apache-tomcat-7.0.47复制一份到/usr/local/solr/目录下并重命名为tomccat,如下所示。

[root@solr-server software]# cp -r apache-tomcat-7.0.47 /usr/local/solr/tomcat[root@solr-server software]# cd /usr/local/solr[root@solr-server solr]# ll总用量 4drwxr-xr-x. 9 root root 4096 4月  23 19:55 tomcat[root@solr-server solr]#

第八步:solr与tomcat结合

       我们将solr的war包放到tomcat的webapps目录下并命名为solr.war,如下所示。

[root@solr-server local]# cp /usr/local/solr-4.10.3/dist/solr-4.10.3.war /usr/local/solr/tomcat/webapps/solr.war[root@solr-server local]# cd /usr/local/solr/tomcat/webapps/[root@solr-server webapps]# ll总用量 29068drwxr-xr-x. 13 root root     4096 4月  23 19:55 docsdrwxr-xr-x.  7 root root     4096 4月  23 19:55 examplesdrwxr-xr-x.  5 root root     4096 4月  23 19:55 host-managerdrwxr-xr-x.  5 root root     4096 4月  23 19:55 managerdrwxr-xr-x.  3 root root     4096 4月  23 19:55 ROOT-rw-r--r--.  1 root root 29741796 4月  23 19:59 solr.war[root@solr-server webapps]# 

        下面对solr.war进行解压,解压的方式是启动tomcat,如下所示。可以是使用tailf logs/catalina.out命令查看启动日志。

[root@solr-server tomcat]# bin/startup.sh Using CATALINA_BASE:   /usr/local/solr/tomcatUsing CATALINA_HOME:   /usr/local/solr/tomcatUsing CATALINA_TMPDIR: /usr/local/solr/tomcat/tempUsing JRE_HOME:        /usr/java/jdk1.8.0_112Using CLASSPATH:       /usr/local/solr/tomcat/bin/bootstrap.jar:/usr/local/solr/tomcat/bin/tomcat-juli.jar
 
          启动tomcat之后,我们到webapps目录下查看,可以看到多了一个solr的目录,说明solr.war已经解压好了。

[root@solr-server tomcat]# cd /usr/local/solr/tomcat/webapps/[root@solr-server webapps]# ll总用量 29072drwxr-xr-x. 13 root root     4096 4月  23 19:55 docsdrwxr-xr-x.  7 root root     4096 4月  23 19:55 examplesdrwxr-xr-x.  5 root root     4096 4月  23 19:55 host-managerdrwxr-xr-x.  5 root root     4096 4月  23 19:55 managerdrwxr-xr-x.  3 root root     4096 4月  23 19:55 ROOTdrwxr-xr-x.  8 root root     4096 4月  23 20:01 solr-rw-r--r--.  1 root root 29741796 4月  23 19:59 solr.war[root@solr-server webapps]# 

       下面我们删掉solr.war,但是前提是先关闭掉tomcat,然后再删除(如果不关闭tomcat就删除solr.war的话,solr文件夹也会被删除),如下所示。

[root@solr-server tomcat]# bin/shutdown.sh Using CATALINA_BASE:   /usr/local/solr/tomcatUsing CATALINA_HOME:   /usr/local/solr/tomcatUsing CATALINA_TMPDIR: /usr/local/solr/tomcat/tempUsing JRE_HOME:        /usr/java/jdk1.8.0_112Using CLASSPATH:       /usr/local/solr/tomcat/bin/bootstrap.jar:/usr/local/solr/tomcat/bin/tomcat-juli.jar[root@solr-server tomcat]# cd webapps/[root@solr-server webapps]# lsdocs  examples  host-manager  manager  ROOT  solr  solr.war[root@solr-server webapps]# rm -rf solr.war [root@solr-server webapps]# lsdocs  examples  host-manager  manager  ROOT  solr[root@solr-server webapps]#

        下面我们将example/lib/ext目录下的所有jar包拷贝到/usr/local/solr/tomcat/webapps/solr/WEB-INF/lib/目录下。如下所示

cp /usr/local/solr-4.10.3/example/lib/ext/* /usr/local/solr/tomcat/webapps/solr/WEB-INF/lib/

        将example目录下的solr文件夹复制到/usr/local/solr/目录下并且重命名为solrhome,如下所示。

[root@solr-server solr-4.10.3]# cp -r example/solr /usr/local/solr/solrhome

        下面我们需要修改/usr/local/solr/tomcat/webapps/solr/WEB-INF/目录下的web.xml文件

[root@solr-server solrhome]# cd /usr/local/solr/tomcat/webapps/solr/WEB-INF/[root@solr-server WEB-INF]# ll总用量 16drwxr-xr-x. 2 root root 4096 4月  23 20:09 lib-rw-r--r--. 1 root root 1210 12月  1 2014 weblogic.xml-rw-r--r--. 1 root root 7052 12月  1 2014 web.xml[root@solr-server WEB-INF]#

         我们把web.xml文件当中的下面这段配置的注释去掉,并修改<env-entry-value>的值为我们solrhome的目录,如下所示。

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

第九步:检测

       经过上面的配置,单机版的solr我们便配置完了,下面我们启动tomcat并使用tailf logs/catalina.out查看启动日志,如下所示。

[root@solr-server tomcat]# bin/startup.sh Using CATALINA_BASE:   /usr/local/solr/tomcatUsing CATALINA_HOME:   /usr/local/solr/tomcatUsing CATALINA_TMPDIR: /usr/local/solr/tomcat/tempUsing JRE_HOME:        /usr/java/jdk1.8.0_112Using CLASSPATH:       /usr/local/solr/tomcat/bin/bootstrap.jar:/usr/local/solr/tomcat/bin/tomcat-juli.jar[root@solr-server tomcat]# tailf logs/catalina.out四月 23, 2017 8:28:51 下午 org.apache.catalina.core.StandardEngine startInternal信息: Starting Servlet Engine: Apache Tomcat/7.0.47四月 23, 2017 8:28:51 下午 org.apache.catalina.startup.HostConfig deployDirectory信息: Deploying web application directory /usr/local/solr/tomcat/webapps/examples四月 23, 2017 8:28:52 下午 org.apache.catalina.startup.HostConfig deployDirectory信息: Deploying web application directory /usr/local/solr/tomcat/webapps/docs四月 23, 2017 8:28:52 下午 org.apache.catalina.startup.HostConfig deployDirectory信息: Deploying web application directory /usr/local/solr/tomcat/webapps/ROOT四月 23, 2017 8:28:52 下午 org.apache.catalina.startup.HostConfig deployDirectory信息: Deploying web application directory /usr/local/solr/tomcat/webapps/solrlog4j:WARN No appenders could be found for logger (org.apache.solr.client.solrj.impl.HttpClientUtil).log4j:WARN Please initialize the log4j system properly.log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.四月 23, 2017 8:29:01 下午 org.apache.catalina.startup.HostConfig deployDirectory信息: Deploying web application directory /usr/local/solr/tomcat/webapps/manager四月 23, 2017 8:29:01 下午 org.apache.catalina.startup.HostConfig deployDirectory信息: Deploying web application directory /usr/local/solr/tomcat/webapps/host-manager四月 23, 2017 8:29:01 下午 org.apache.coyote.AbstractProtocol start信息: Starting ProtocolHandler ["http-bio-8080"]四月 23, 2017 8:29:01 下午 org.apache.coyote.AbstractProtocol start信息: Starting ProtocolHandler ["ajp-bio-8009"]四月 23, 2017 8:29:01 下午 org.apache.catalina.startup.Catalina start信息: Server startup in 10340 ms

        下面我们到地址栏输入http://192.168.156.22:8080/solr/即可访问到solr的管理页面了,如下图所示。


       

       

       

1 0
原创粉丝点击