centos安装solr并配置IKanalyzer中文分词

Submitted by admin on Sun, 10/19/2014 - 12:47

安装Java环境

yum install java-1.7.0-openjdk

安装Tomcat

  useradd -Mb /usr/local tomcat

  到http://tomcat.apache.org/download-70.cgi下载最新tomcat安装到/usr/local/src

tar -C /usr/local -zxf /usr/local/src/apache-tomcat-7.*.tar.gz
mv /usr/local/apache-tomcat-7.* /usr/local/tomcat

  [可选]修改端口:

sudo sed -i s/8080/8983/g /usr/local/tomcat/conf/server.xml
chown -R tomcat:tomcat /usr/local/tomcat
sudo -u tomcat /usr/local/tomcat/bin/startup.sh

安装solr

  到http://lucene.apache.org/solr/查找并下载最新版solr (目前是4.10.0)

  解压 

tar -zxf solr-4.10.0.tgz
cp solr-4.10.0/dist/solrj-lib/* /usr/local/tomcat/lib/
cp solr-4.10.0/example/resources/log4j.properties /usr/local/tomcat/conf/
cp solr-4.10.0/dist/solr-4.10.0.war /usr/local/tomcat/webapps/solr.war
cp /usr/local/src/solr-4.10.0/example/lib/ext/* /usr/local/tomcat/webapps/solr/WEB-INF/lib/

  编辑or创建/usr/local/tomcat/conf/Catalina/localhost/solr.xml

<Context docBase="/usr/local/tomcat/webapps/solr.war" debug="0" crossContext="true">
  <Environment name="solr/home" type="java.lang.String" value="/usr/local/tomcat/solr" override="true" />
</Context>

配置solr索引

mkdir -p /usr/local/tomcat/solr
cp -r solr-4.10.0/example/solr/collection1/conf /usr/local/tomcat/solr/

  到https://drupal.org/project/apachesolr下载并使用Drupal提供的solr配置

tar -zxf apachesolr-*.tar.gz
rsync -av apachesolr/solr-conf/solr-4.x/ /usr/local/tomcat/solr/conf/

  创建新的索引

    /usr/local/tomcat/solr/solr.xml如入如下值:

<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="false">
<cores adminPath="/admin/cores">
  <core name="drupal" instanceDir="drupal" />
</cores>
</solr>
  mkdir /usr/local/tomcat/solr/drupal
  cp -r /usr/local/tomcat/solr/conf /usr/local/tomcat/solr/drupal/

  保险措施:

/usr/local/tomcat/bin/shutdown.sh
chown -R tomcat:tomcat /usr/local/tomcat
sudo -u tomcat /usr/local/tomcat/bin/startup.sh

配置中文分词:

  到https://code.google.com/p/ik-analyzer/downloads/list下载并解压IKAnalyzer,版本号选择2012FF_hf1。

  有用的文件:

cp IKAnalyzer2012FF_u1.jar /usr/local/tomcat/webapps/solr/WEB-INF/lib
cp IKAnalyzer.cfg.xml /usr/local/tomcat/webapps/solr/WEB-INF/classes
cp stopword.dic /usr/local/tomcat/webapps/solr/WEB-INF/classes

  到下载新的scheme文件http://pan.baidu.com/s/1qWsJJ1E

cp schema.xml /usr/local/tomcat/solr/conf/schema.xml

  重启solr

/usr/local/tomcat/bin/shutdown.sh
chown -R tomcat:tomcat /usr/local/tomcat
sudo -u tomcat /usr/local/tomcat/bin/startup.sh

参考文章:

  https://www.lullabot.com/blog/article/installing-solr-use-drupal

  http://www.dplor.com/archives/579