solr 5.3.1安装配置

1、下载Solr5.3.1

http://mirror.bit.edu.cn/apache/lucene/solr/5.3.1/

wget http://mirror.bit.edu.cn/apache/lucene/solr/5.3.0/solr-5.3.0.tgz

2、解压压缩包

tar zxf solr-5.3.1.tgz
或
unzip solr-5.3.1.zip

3、配置solr

1、复制solr项目文件

mkdir -p /data/web/solr/solr_app/
cp -r /data/solr-5.3.1/server/solr-webapp/webapp/* /data/web/solr/solr_app/

2、复制dll文件

cp /data/solr-5.3.1/server/lib/ext/* /data/web/solr/solr_app/WEB-INF/lib/

3、复制日志文件

mkdir /data/web/solr/solr_app/WEB-INF/classes
cp /data/solr-5.3.1/server/resources/log4j.properties /data/web/solr/solr_app/WEB-INF/classes/

4、修改solr.log文件的存储位置:默认在/root/logs/solr.log

vim /data/web/solr/solr_app/WEB-INF/classes/log4j.properties

solr 5.3.1安装配置_第1张图片

改成自己的日志路径

solr 5.3.1安装配置_第2张图片

5、复制solr.xml文件到web.xml里面的的路径下

mkdir -p /data/web/solr/solr_app/WEB-INF/solr_home
cp /data/solr-5.3.1/example/example-DIH/solr/solr.xml /data/web/solr/solr_app/WEB-INF/solr_home/

6、配置solr_home

vim /data/web/solr/solr_app/WEB-INF/web.xml   --修改env-entry-value的值:/data/web/solr/solr_app/WEB-INF/solr_home

solr 5.3.1安装配置_第3张图片

tomcat配置->Server.xml->Connector->connectionTimeout="20000"不知道为什么,这个值大了启动tomcat,solr页面显示就是失败的。

启动tomcat,此时没有集合,如下图:

solr 5.3.1安装配置_第4张图片

 4、配置solr集合

1、进入solr_home,开始配置solr的索引库、分词器、数据源和定时任务:

cd /data/web/solr/solr_app/WEB-INF/solr_home/

2、为某一个语言创建solr配置,首先需要该语言的目录,比如:英文

mkdir pc_EN
cd pc_EN
touch core.properties
mkdir conf
mkdir data

 solr 5.3.1安装配置_第5张图片

 3、编辑core.properties文件,设置索引名称和索引存放的位置:

vim core.properties
--指定索引文件的存放位置(solr_index目录可以创建了mkdir -p /data/web/solr/solr_app/WEB-INF/solr_index
--文件内容
name
=pc_EN
dataDir
=/data/web/solr/solr_app/WEB-INF/solr_index/master/pc_EN/data

 solr 5.3.1安装配置_第6张图片

 4、进入conf目录设置索引的数据格式、数据源

cd conf
find /data -name solrconfig.xml

solr 5.3.1安装配置_第7张图片

把rss文件夹下面的solrconfig.xml复制到pc_EN/conf目录里面

cp /data/solr-5.3.0/example/example-DIH/solr/rss/conf/solrconfig.xml solrconfig.xml

solr 5.3.1安装配置_第8张图片

设置solrconfig.xml关联website-data-config.xml文件

vim solrconfig.xml --搜索name="/dataimport"

solr 5.3.1安装配置_第9张图片

设置solrconfig.xml的solr搜索结果返回的数据格式为:xml

solr 5.3.1安装配置_第10张图片

设置solrconfig.xml关联schema.xml文件,增加如下代码:

"/replication" class="solr.ReplicationHandler" >
    "master">
        "replicateAfter">commit
        "replicateAfter">startup
        "confFiles">schema.xml
    

solr 5.3.1安装配置_第11张图片

完整的solrconfig.xml文件

  1 "1.0" encoding="UTF-8" ?>
  2 
 18 
 19 
 23 
 24   5.3.1
 25   
 28   "DirectoryFactory" class="${solr.directoryFactory:solr.NRTCachingDirectoryFactory}"/>
 29 
 30   ${solr.data.dir:}
 31 
 32   
 52   class="solr.SchemaCodecFactory"/>
 53   class="ClassicIndexSchemaFactory"/>
 54 
 55   class="solr.DirectUpdateHandler2">
 56     
 57       "dir">${solr.data.dir:}
 58       <int name="numVersionBuckets">${solr.ulog.numVersionBuckets:65536}int>
 59     
 60   
 61 
 62   
 63     
 76     1024
 77 
 78 
 79     
 90 
 91     
110     class="solr.FastLRUCache"
111                  size="512"
112                  initialSize="512"
113                  autowarmCount="0"/>
114 
115     
123     class="solr.LRUCache"
124                      size="512"
125                      initialSize="512"
126                      autowarmCount="0"/>
127    
128     
134     class="solr.LRUCache"
135                    size="512"
136                    initialSize="512"
137                    autowarmCount="0"/>
138     
139      
140     "perSegFilter"
141       class="solr.search.LRUCache"
142       size="30"
143       initialSize="0"
144       autowarmCount="30"
145       regenerator="solr.NoOpRegenerator" />
146 
147     
155     true
156 
157    
166    20
167 
168    
171    200
172 
173     
180     false
181 
182     
191     2
192 
193   
194 
195   "true" >
196     "true" multipartUploadLimitInKB="2048" formdataUploadLimitInKB="2048" />
197   
198 
199   "/select" class="solr.SearchHandler">
200     "defaults">
201       "echoParams">explicit
202       "wt">xml
203       "indent">true
204       <int name="rows">10int>
205     
206   
207   
208   "/analysis/field" startup="lazy" class="solr.FieldAnalysisRequestHandler" />
209      
210   "/admin/ping" class="solr.PingRequestHandler">
211     "invariants">
212       "q">*:*
213     
214     "defaults">
215       "echoParams">all
216     
217   
218   
219     "/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
220         "defaults">
221             "config">website-data-config.xml
222         
223     
224   
225     "/replication" class="solr.ReplicationHandler" >
226         "master">
227             "replicateAfter">commit
228             "replicateAfter">startup
229             "confFiles">schema.xml
230         
231     
232   
233    
234   
235     *:*
236   
237 
238 
solrconfig.xml

schema.xml用来设置solr需要索引的字段

solr 5.3.1安装配置_第12张图片

完整的schema.xml

 1 xml version="1.0" ?>
 2 
 3 <schema name="website" version="1.5">
 4     <types>
 5         <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true" />
 6         <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true" omitNorms="true" />    
 7         <fieldType name="booleans" class="solr.BoolField" sortMissingLast="true" multiValued="true"/>    
 8         <fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0" />
 9         <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" omitNorms="true" positionIncrementGap="0" />
10         <fieldType name="long" class="solr.TrieLongField" precisionStep="0" omitNorms="true" positionIncrementGap="0" />
11         <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" omitNorms="true" positionIncrementGap="0" />
12         <fieldType name="date" class="solr.TrieDateField" omitNorms="true" precisionStep="0" positionIncrementGap="0" /> 
13         <fieldType name="tint" class="solr.TrieIntField" precisionStep="8" omitNorms="true" positionIncrementGap="0" />
14         <fieldType name="sfloat" class="solr.TrieFloatField" precisionStep="8" omitNorms="true" positionIncrementGap="0" />
15         <fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" omitNorms="true" positionIncrementGap="0" />
16         <fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" omitNorms="true" positionIncrementGap="0" />
17         <fieldType name="tdate" class="solr.TrieDateField" omitNorms="true" precisionStep="6" positionIncrementGap="0" />
18         <fieldType name="tdates" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0" multiValued="true"/>
19         <fieldType name="tints" class="solr.TrieIntField" precisionStep="8" positionIncrementGap="0" multiValued="true"/>
20         <fieldType name="tfloats" class="solr.TrieFloatField" precisionStep="8" positionIncrementGap="0" multiValued="true"/>
21         <fieldType name="tlongs" class="solr.TrieLongField" precisionStep="8" positionIncrementGap="0" multiValued="true"/>
22         <fieldType name="tdoubles" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0" multiValued="true"/>
23         <fieldType name="text" class="solr.TextField">
24         <analyzer type="index"  class="org.apache.lucene.analysis.en.EnglishAnalyzer"/>
25         <analyzer type="query"  class="org.apache.lucene.analysis.en.EnglishAnalyzer"/>
26     fieldType>
27     types>
28   
29     <fields>
30         <field name="_version_"                type="long" indexed="true" stored="true"/>
31         <field name="CultureID"                type="int" indexed="false" stored="true" />    
32         <field name="DescriptionFull"         type="text" indexed="true" stored="false" />
33         <field name="DescriptionShort"         type="text" indexed="true" stored="false" />
34         <field name="ImageJSON"                type="text" indexed="false" stored="true"  />
35         <field name="IsHot"                    type="int" indexed="false" stored="true"  />
36         <field name="IsMutilColor"            type="int" indexed="false" stored="true" default="" />
37         <field name="LeiMuNameJSON"         type="text" indexed="true" stored="true"  />
38         <field name="PID"                    type="string" indexed="true" stored="true"  />
39         <field name="PropertyText"            type="text" indexed="true" stored="true"  />
40         <field name="RequiredText"            type="text" indexed="true" stored="true"  />
41         <field name="SPUID"                    type="long" indexed="true" stored="true" />
42         <field name="Sort"                    type="int" indexed="true" stored="true"  />
43         <field name="Status"                type="int" indexed="true" stored="true"  />
44         <field name="Title"                    type="text" indexed="true" stored="true"  />
45         <field name="UpTime"                type="date" indexed="true" stored="true"  />
46         <field name="Price"                    type="double" indexed="true" stored="true"  />
47         <field name="SaleCount"                type="long" indexed="true" stored="true"  />
48         <field name="CustomerRatingCount"    type="long" indexed="false" stored="true"  />
49         <field name="DisCount"                type="double" indexed="true" stored="true"  />
50         <field name="Basic_search"             type="text" indexed="true" stored="false" multiValued="true"/>
51     fields>
52  
53     
54     <uniqueKey>SPUIDuniqueKey>
55     
56     <defaultSearchField>Basic_searchdefaultSearchField>
57     
58     <solrQueryParser defaultOperator="OR"/>
59     <copyField source="PID"                     dest="Basic_search" />
60     <copyField source="DescriptionFull"         dest="Basic_search" />
61     <copyField source="DescriptionShort"        dest="Basic_search" />
62     <copyField source="LeiMuNameJSON"           dest="Basic_search" />
63     <copyField source="PropertyText"            dest="Basic_search" />
64     <copyField source="RequiredText"            dest="Basic_search" />
65     <copyField source="Title"                    dest="Basic_search" />
66 schema>
schema.xml

website-data-config.xml设置数据源和数据源格式与schema.xml的字段匹配

solr 5.3.1安装配置_第13张图片

完整的website-data-config.xml

 1 xml version="1.0" encoding="UTF-8" ?>
 2 <dataConfig>
 3     <dataSource type="URLDataSource" encoding="UTF-8" />
 4     <document>
 5         <entity name="website"
 6                 processor="XPathEntityProcessor"
 7                 forEach="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel |/LuceneSpuXmlModel"
 8                 url="http://url/product?cultureId=1&pageSize=100&pageIndex=1&siteId=6&platform=1"
 9                 transformer="RegexTransformer,DateFormatTransformer"
10                 connectionTimeout="120000"
11                 readTimeout="300000"
12                 stream="true">
13             <field column="SPUID"                 xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/SPUID"  />
14             <field column="PID"                 xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/PID" />
15             <field column="Title"               xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/Title" />
16             <field column="Status"               xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/Status" />
17             <field column="CultureID"           xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/CultureID"          commonField="true" />
18             <field column="LeiMuNameJSON"          xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/LeiMuNameJSON" />
19             <field column="DescriptionShort"    xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/DescriptionShort"     commonField="true" />
20             <field column="DescriptionFull"        xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/DescriptionFull"    commonField="true" />
21             <field column="Sort"                xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/Sort" />
22             <field column="ImageJSON"            xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/ImageJSON" />
23             <field column="PropertyText"        xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/PropertyText" />
24             <field column="RequiredText"           xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/RequiredText" />
25             <field column="IsHot"                 xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/IsHot" />
26             <field column="IsMutilColor"          xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/IsMutilColor" />
27             <field column="UpTime"               xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/UpTime"             dateTimeFormat="yyyy-MM-dd'T'hh:mm:ss"/>
28             <field column="Price"               xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/Price" />
29             <field column="SaleCount"           xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/SaleCount" />
30             <field column="CustomerRatingCount" xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/CustomerRatingCount" />
31             <field column="DisCount"               xpath="/LuceneSpuXmlModel/LuceneSpuModelList/LuceneSpuModel/DisCount" />
32                         
33             <field column="$hasMore"             xpath="/LuceneSpuXmlModel/HasMore" />
34             <field column="$nextUrl"             xpath="/LuceneSpuXmlModel/NextPageUrl" />
35         entity>
36     document>
37 dataConfig>
website-data-config.xml

启动Tomcat运行solr出错:

复制数据倒入的包:

cp /data/solr-5.3.1/dist/solr-dataimporthandler-* /data/web/solr/solr_app/WEB-INF/lib/

启动tomcat_solr成功界面如下:

solr 5.3.1安装配置_第14张图片

5、设置solr定时任务

1、复制定时任务包(如果没有复制过)

cp /data/solr-5.3.1/dist/solr-dataimporthandler-* /data/web/solr/solr_app/WEB-INF/lib/

2、还需要一个jar也复制到/data/web/solr/solr_app/WEB-INF/lib/下面:

apache-solr-dataimportscheduler-1.0.jar

3、修改Web.xml,添加配置节点:


    
         org.apache.solr.handler.dataimport.scheduler.ApplicationListener
    

4、回到solr_home目录创建conf目录,创建dataimport.properties定时任务文件:

solr 5.3.1安装配置_第15张图片

5、编辑dataimport.properties定时任务文件:

a、设置syncCores,server,port

solr 5.3.1安装配置_第16张图片

b、设置时间间隔、开始时间:

solr 5.3.1安装配置_第17张图片

 

http://my.oschina.net/lsf930709/blog/620738(参考文章)

转载于:https://www.cnblogs.com/qiyebao/p/5432201.html

你可能感兴趣的:(solr 5.3.1安装配置)