在tomcat下安装solr3.6

原创文章,转载请注明来源并保留原文链接

1)首先确认已经安装Tomcat,我的安装目录在/usr/local/tomcat

2)下载最新的solr,目前版本是3.6

cd /tmp
wget http://labs.renren.com/apache-mirror/lucene/solr/3.6.0/apache-solr-3.6.0.tgz
tar -xzfv apache-solr-3.6.0.tgz

3)下面我们创建一个实例,命名为solr

cd /usr/share
cp -a /tmp/apache-solr-3.6.0/example/solr ./solr
cp /tmp/apache-solr-3.6.0/dist/apache-solr-3.6.0.war ./solr/solr.war

4)创建data,lib文件夹,data用来放数据,lib用来放一些额外的库文件,拷贝contrib文件夹

cd /usr/share/solr
mkdir data lib
cp /tmp/apache-solr-3.6.0/dist/*.jar ./lib
cp -a /tmp/apache-solr-3.6.0/contrib ./lib

5)修改solrconfig.xml文件

cd /usr/share/solr/conf
cp solrconfig.xml solrconfig.xml.bak
vi solrconfig.xml

找到<lib dir="./lib" />修改如下:

<lib dir="./lib" />
<!-- A 'dir' option by itself adds any files found in the directory
    to the classpath, this is useful for including all jars in a
    directory.
-->
<!--
    <lib dir="../add-everything-found-in-this-dir-to-the-classpath" />
-->

<!-- When a 'regex' is specified in addition to a 'dir', only the
    files in that directory which completely match the regex
    (anchored on both ends) will be included.
-->
<lib dir="./lib" regex="apache-solr-cell-\d.*\.jar" />
<lib dir="./contrib/extraction/lib" regex=".*\.jar" />

<lib dir="./lib" regex="apache-solr-clustering-\d.*\.jar" />
<lib dir="./contrib/clustering/lib/" regex=".*\.jar" />

<lib dir="./lib" regex="apache-solr-dataimporthandler-\d.*\.jar" />
<lib dir="./contrib/dataimporthandler/lib/" regex=".*\.jar" />
 
<lib dir="./lib" regex="apache-solr-langid-\d.*\.jar" />
<lib dir="./contrib/langid/lib/" regex=".*\.jar" />

<lib dir="./lib" regex="apache-solr-velocity-\d.*\.jar" />
<lib dir="./contrib/velocity/lib" regex=".*\.jar" />

5)创建tomcat的solr配置文件

cd /usr/local/tomcat/conf/Catalina/localhost
touch solr.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="/usr/share/solr/solr.war" debug="0" crossContext="true" path="/solr">
  <Environment name="solr/home" type="java.lang.String" value="/usr/share/solr" override="true" />
</Context>

6)最后重启tomcat

/etc/init.d/tomcat6 restart

访问 http://127.0.0.1:8080/solr/

Leave a Reply

Your email address will not be published. Required fields are marked *