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
改成自己的日志路径
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
tomcat配置->Server.xml->Connector->connectionTimeout="20000"不知道为什么,这个值大了启动tomcat,solr页面显示就是失败的。
启动tomcat,此时没有集合,如下图:
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
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
4、进入conf目录设置索引的数据格式、数据源
cd conf
find /data -name solrconfig.xml
把rss文件夹下面的solrconfig.xml复制到pc_EN/conf目录里面
cp /data/solr-5.3.0/example/example-DIH/solr/rss/conf/solrconfig.xml solrconfig.xml
设置solrconfig.xml关联website-data-config.xml文件
vim solrconfig.xml --搜索name="/dataimport"
设置solrconfig.xml的solr搜索结果返回的数据格式为:xml
设置solrconfig.xml关联schema.xml文件,增加如下代码:
"/replication" class="solr.ReplicationHandler" > "master"> "replicateAfter">commit "replicateAfter">startup "confFiles">schema.xml
完整的solrconfig.xml文件
1 "1.0" encoding="UTF-8" ?> 2 18 19 2324 5.3.1 25 28"DirectoryFactory" class="${solr.directoryFactory:solr.NRTCachingDirectoryFactory}"/> 29 30 ${solr.data.dir:} 31 32 52class="solr.SchemaCodecFactory"/> 53 class="ClassicIndexSchemaFactory"/> 54 55 class="solr.DirectUpdateHandler2"> 56 61 6257 60"dir">${solr.data.dir:} 58 <int name="numVersionBuckets">${solr.ulog.numVersionBuckets:65536}int> 5963 76 194 1951024 77 78 79 90 91 110class="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 16620 167 168 171200 172 173 180false 181 182 1912 192 193"true" > 196 198 199"true" multipartUploadLimitInKB="2048" formdataUploadLimitInKB="2048" /> 197 "/select" class="solr.SearchHandler"> 200 207 208"defaults"> 201 206"echoParams">explicit 202"wt">xml 203"indent">true 204 <int name="rows">10int> 205"/analysis/field" startup="lazy" class="solr.FieldAnalysisRequestHandler" /> 209 210 "/admin/ping" class="solr.PingRequestHandler"> 211 218 219"invariants"> 212 214"q">*:* 213"defaults"> 215 217"echoParams">all 216"/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> 220 224 225"defaults"> 221 223"config">website-data-config.xml 222"/replication" class="solr.ReplicationHandler" > 226 232 233 234"master"> 227 231"replicateAfter">commit 228"replicateAfter">startup 229"confFiles">schema.xml 230235 237 238*:* 236
schema.xml用来设置solr需要索引的字段
完整的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>
website-data-config.xml设置数据源和数据源格式与schema.xml的字段匹配
完整的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>
启动Tomcat运行solr出错:
复制数据倒入的包:
cp /data/solr-5.3.1/dist/solr-dataimporthandler-* /data/web/solr/solr_app/WEB-INF/lib/
启动tomcat_solr成功界面如下:
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定时任务文件:
5、编辑dataimport.properties定时任务文件:
a、设置syncCores,server,port
b、设置时间间隔、开始时间:
http://my.oschina.net/lsf930709/blog/620738(参考文章)