本人上周五刚刚配置了一遍centos下配置solr5.3版本,综合借鉴并改进了一些教程,贴出如下
单位使用内网,本教程暂无截图,抱歉
另,本人是使用.net编程调用solr的使用的是solrnet,在此推荐一下
首先将软件包上传到/tmp目录下
需要文件如下
jdk-8u60-linux-x64.gz
apache-tomcat-7.0.64.tar.gz
solr-5.3.0.tgz
ik分词器、拼音分词器:
IKAnalyzer-5.0.jar
solr-analyzer-ik-5.1.0.jar
pinyin4j-2.5.0.jar
analyzer-pinyin-lucene-5.1.0.jar
analyzer-pinyin-solr-5.1.0.jar
ik分词器需要ext.dic(字典) stopword.dic(排除词) IKAnalyzer.cfg.xml(配置)
一、  jdk安装
[root@svn-server /]# cd /tmp/              
[root@svn-server /]#tar zxvf  jdk-8u60-linux-x64.gz
[root@svn-server /]#mv  jdk1.8.0_60 /usr/
[root@svn-server /]#vi  /etc/profile
在最后一行复制以下代码添加如下内容:
JAVA_HOME=/usr/jdk1.8.0_60/
CLASSPATH=.:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
保存退出(:wq!)后,执行下面命令生效:
source /etc/profile
二、  tomcat安装
1、将tomcat包减压到tmp目录下:
[root@svn-server tmp]tar zxvf apache-tomcat-7.0.64.tar.gz 
将tomcat包移动到/usr/local/tomcat 下:
[root@svn-server tmp]mv apache-tomcat-7.0.64  /usr/local/tomcat
2、修改tomcat的server配置,加上utf-8
[root@svn-server tmp]vim  /usr/local/tomcat/conf/server.xml
新增URIEncoding="UTF-8"
<Connector port="80" protocol="HTTP/1.1"   
               connectionTimeout="20000"   
               redirectPort="8443" URIEncoding="UTF-8"/>  
3、tomcat 加账号
vi /usr/local/tomcat/conf/tomcat-users.xml
倒数第二行回车添加如下:
<user username="admin" password="admin" roles="manage-gui" />
4、启动tomcat,并测试访问
[root@svn-server tmp]/usr/local/tomcat/bin/startup.sh
访问 localhost:8080/manager/html 输入账号admin密码admin成功进入
5、需要注意,若防火墙端口未开启需要开启相应端口
[root@svn-server tmp]vi /ect/sysconfig/iptables 
在iptables中加一行端口数据,并重启iptables
[root@svn-server tmp]service iptables stop
[root@svn-server tmp]service iptables start
三、安装solr
1、解压solr 
[root@svn-server tmp]tar -zxvf solr-5.3.0.tgz  
2、将solr包移动到opt目录下:
[root@svn-server tmp]mv /tmp/solr-5.3.0  /opt/solr  
3、把server/solr-webapp中的webapp复制到tomcat的webapps下,并重命名为solr
[root@svn-server tmp]cp -r /opt/solr/server/webapps/webapp  /usr/local/tomcat/webapps/solr
 
4、修改solr home配置(注意:要把这段内容的注释去掉,否则不生效):
            <env-entry>  
              <env-entry-name>solr/home</env-entry-name>  
              <env-entry-value>/opt/solr/server/solr</env-entry-value>  
              <env-entry-type>java.lang.String</env-entry-type>  
            </env-entry> 
            
将实例的core拷一个到solrhome,并命名为自己的名字(我的叫qdfs)
cp -r /opt/solr/example/example-DIH/solr/solr /opt/solr/server/solr/qdfs
5、复制solr/server/lib/ext下的jar包到tomcat的solr web的WEB-INF/lib/下:
[root@svn-server tmp]cp /opt/solr/example/lib/ext/*.jar  /usr/local/tomcat/webapps/solr/WEB-INF/lib/  
将dist\solrj-lib的jar 拷到 tomcat\lib
cp /opt/solr/dist/solrj-lib/*.jar /usr/local/tomcat/lib/
6、在tomcat solr下创建classes,并把example/resources/log4j.properties复制到classes中:
[root@svn-server tmp]mkdir -p /usr/local/tomcat/webapps/solr/WEB-INF/classes  
[root@svnserver tmp]cp /opt/solr/server/resources/log4j.properties /usr/local/tomcat/webapps/solr/WEB-INF/classes/  
四、配置实例core(我的叫qdfs)
1、创建索引文件夹data
[root@svn-server tmp]mkdir /opt/solr/server/solr/data
2、修改solrconfig
[root@svn-server tmp]vi /opt/solr/server/solr/qdfs/conf/solrconfig.xml
把<lib dir="{solr.instal.dir.....注释掉。因为不是使用solr自带的启动
设置solrdata地址
<dataDir>${solr.data.dir:/opt/solr/server/solr/data}</dataDir>
3、配置实例需要的jar包,也可通过配置上一步solrconfig中lib节点实现同样作用,但效果不太稳定
[root@svn-server tmp]cp /opt/solr/contrib/analysis-extras/lib/*.jar /usr/local/tomcat/webapps/solr/WEB-INF/lib/
4、修改schema,配置字段分词器
[root@svn-server tmp]vi /opt/solr/server/solr/qdfs/conf/schema.xml
文档最后面加上ik分词器配置
<!--IK分词器-->
    <fieldType name="text_ik" class="solr.TextField">
	  <analyzer type="index">
        <tokenizer class="org.apache.lucene.analysis.ik.IKTokenizerFactory" useSmart="false"/>
        <filter class="org.apache.lucene.analysis.pinyin.solr5.PinyinTokenFilterFactory" firstChar="false" minTermLength="2" />
        <filter class="org.apache.lucene.analysis.pinyin.solr5.PinyinNGramTokenFilterFactory" nGramChinese="false" nGramNumber="false" />
      </analyzer>
      <analyzer type="query">
        <tokenizer class="org.apache.lucene.analysis.ik.IKTokenizerFactory" useSmart="false"/>
        <filter class="org.apache.lucene.analysis.pinyin.solr5.PinyinTokenFilterFactory" firstChar="false" minTermLength="2" />
        <filter class="org.apache.lucene.analysis.pinyin.solr5.PinyinNGramTokenFilterFactory" nGramChinese="true" nGramNumber="true" />
      </analyzer>
    </fieldType>
在field节点中配置
<field name="text_ik" type="text_ik" indexed="true" stored="true"/>
五、ik分词器配置
1、将ik分词器的jar拷入lib,solr5.x版本正常的ik分词器、拼音分词器不好用,使用的是益达大神博客下载的。大概需要如下jar
IKAnalyzer-5.0.jar
solr-analyzer-ik-5.1.0.jar
pinyin4j-2.5.0.jar
analyzer-pinyin-lucene-5.1.0.jar
analyzer-pinyin-solr-5.1.0.jar
[root@svn-server tmp]cp /tmp/solr_jars/*.jar /usr/local/tomcat/webapps/solr/WEB-INF/lib/
2、ik分词器需要ext.dic(字典) stopword.dic(排除词) IKAnalyzer.cfg.xml(配置)的几个文件拷入solrweb下
[root@svn-server tmp]mkdir /usr/local/tomcat/webapps/solr/WEB-INF/classes
将ext.dic stopword.dic IKAnalyzer.cfg.xml拷入
编辑IKAnalyzer.cfg.xml中ext.dic的注释放开
六、测试
注意solr网站使用angularjs,需要支持html5的浏览器才可正常访问。
访问localhost:8080/solr,能够成功访问。
点击Core Admin,点击AddCore,输入name:qdfs, InstanceDir:qdfs,提交数据。
访问ocalhost:8080/solr#/qdfs/analysis, fieldType选择刚才添加的text_ik 测试分词效果
参考链接:
Linux(CentOS)下完美部署Solr 搜索引擎 http://www.linuxidc.com/Linux/2014-03/98024.htm
跟益达学Solr5之使用IK分词器 http://iamyida.iteye.com/blog/2220474
跟益达学Solr5之拼音分词[改进版] http://iamyida.iteye.com/blog/2240657
原文:http://www.cnblogs.com/zhangyuan0532/p/4826740.html