前端之家收集整理的这篇文章主要介绍了
CentOS下安装Solr5.3,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_
404_0@
https://lucene.apache.org/solr/
@H_
404_0@
前言
@H_
404_0@Solr现在是一个独立的服务器。
从Solr5.0开始,Solr不再发布为在任何Servlet容器中部署的“war”Web应用程序包(Web Application Archive)。Solr现在部署为一个独立的java服务器应用程序,包含在Unix和Windows平台上可以使用的启动和停止脚本,以及将Solr作为服务安装到类Unix平台的/etc/init.d下的安装脚本。
本质上,Solr仍然以Servlet APIs实现,并在Jetty上运行,但只是作为一个实现。部署为“webapp”到其他的Servlet容器(或其他Jetty实例)上不被
支持,可能在未来的Solr 5.x版本不会工作。而可能会带来Solr的其他改变,事实上是利用
自定义网络协议栈
功能。
@H_
404_0@
安装JRE
- @H_404_0@需要Java Runtime Environment(JRE) 1.7或更高版本,先验证。 @H_404_0@# java -version
- @H_404_0@安装可参考《在CentOS下安装JDK8》,包含JRE。
@H_
404_0@
安装Solr5.3
- @H_404_0@去http://www.apache.org/dyn/closer.lua/lucene/solr/5.3.0下载Solr安装文件solr-5.3.0.tgz。
- @H_404_0@将solr-5.3.0.tgz文件放到/tmp目录下,执行如下脚本:
|
@H_404_0@#cd/tmp @H_404_0@#tar-zxvfsolr-5.3.0.tgz//解压压缩包 |
- @H_404_0@创建应用程序和数据目录
|
@H_404_0@#mkdir-p/data/solr/usr/local/solr |
- @H_404_0@创建运行solr的用户并赋权
@H_404_0@#groupaddsolr @H_404_0@#useradd-gsolrsolr @H_404_0@#chown-Rsolr.solr/data/solr/usr/local/solr |
- @H_404_0@安装solr服务
|
@H_404_0@#solr-5.3.0/bin/install_solr_service.shsolr-5.3.0.tgz-d/data/solr-i/usr/local/solr |
- @H_404_0@检查服务状态
|
@H_404_0@#servicesolrstatus |
@H_404_0@将会看到如下输出:
@H_404_0@Solrprocess29692runningonport8983 @H_404_0@{ @H_404_0@"solr_home":"/data/solr/data/", @H_404_0@"version":"5.3.01696229-noble-2015-08-1717:10:43", @H_404_0@"startTime":"2015-09-16T01:32:03.919Z", @H_404_0@"uptime":"0days,0hours,3minutes,6seconds", @H_404_0@"memory":"89.8MB(%18.3)of490.7MB"} |
@H_
404_0@
solr命令用法
- @H_404_0@定位到solr应用程序目录
|
@H_404_0@#cd/usr/local/solr/solr |
- @H_404_0@查看solr命令选项
@H_404_0@Usage:solrCOMMANDOPTIONSwhereCOMMANDisoneof:start,stop,restart,status,healthcheck,create,create_core,create_collection,delete @H_404_0@Standaloneserverexample(startSolrrunninginthebackgroundonport8984): @H_404_0@./solrstart-p8984 @H_404_0@SolrCloudexample(startSolrrunninginSolrCloudmodeusinglocalhost:2181toconnecttoZooKeeper,with1gmaxheapsizeandremoteJavadebugoptionsenabled): @H_404_0@./solrstart-c-m1g-zlocalhost:2181-a"-Xdebug-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044" @H_404_0@Pass-helpafteranyCOMMANDtoseecommand-specificusageinformation,suchas:./solrstart-helpor./solrstop-help |
|
@H_404_0@#./bin/solrstart-help |
@H_404_0@Usage:solrstart[-f][-c][-hhostname][-pport][-ddirectory][-zzkHost][-mmemory][-eexample][-ssolr.solr.home][-a"additional-options"][-V] @H_404_0@-fStartSolrinforeground;defaultstartsSolrinthebackgroundandsendsstdout/stderrtosolr-PORT-console.log @H_404_0@-cor-cloudStartSolrinSolrCloudmode;if-znotsupplied,anembeddedZooKeeperinstanceisstartedonSolrport+1000,suchas9983ifSolrisboundto8983 @H_404_0@-h<host>SpecifythehostnameforthisSolrinstance @H_404_0@-p<port>SpecifytheporttostarttheSolrHTTPlisteneron;defaultis8983Thespecifiedport(SOLR_PORT)willalsobeusedtodeterminethestopportSTOP_PORT=($SOLR_PORT-1000)andJMXRMIlistenportRMI_PORT=(1$SOLR_PORT).Forinstance,ifyouset-p8985,thentheSTOP_PORT=7985andRMI_PORT=18985 @H_404_0@-d<dir>SpecifytheSolrserverdirectory;defaultstoserver @H_404_0@-z<zkHost>ZooKeeperconnectionstring;onlyusedwhenrunninginSolrCloudmodeusing-cTolaunchanembeddedZooKeeperinstance,don'tpassthisparameter. @H_404_0@-m<memory>Setsthemin(-Xms)andmax(-Xmx)heapsizefortheJVM,suchas:-m4gresultsin:-Xms4g-Xmx4g;bydefault,thisscriptsetstheheapsizeto512m @H_404_0@-s<dir>Setsthesolr.solr.homesystemproperty;Solrwillcreatecoredirectoriesunderthisdirectory.ThisallowsyoutorunmultipleSolrinstancesonthesamehostwhilereusingthesameserverdirectorysetusingthe-dparameter.Ifset,thespecifieddirectoryshouldcontainasolr.xmlfile,unlesssolr.xmlexistsinZooKeeper.Thisparameterisignoredwhenrunningexamples(-e),asthesolr.solr.homedependsonwhichexampleisrun.Thedefaultvalueisserver/solr. @H_404_0@-e<example>Nameoftheexampletorun;availableexamples:cloud:SolrCloudexampletechproducts:ComprehensiveexampleillustratingmanyofSolr'scorecapabilitiesdih:DataImportHandlerschemaless:Schema-lessexample @H_404_0@-aAdditionalparameterstopasstotheJVMwhenstartingSolr,suchastosetupJavadebugoptions.Forexample,toenableaJavadebuggertoattachtotheSolrJVMyoucouldpass:-a"-agentlib:jdwp=transport=dt_socket,address=18983"Inmostcases,youshouldwraptheadditionalparametersindoublequotes. @H_404_0@-nopromptDon'tpromptforinput;acceptalldefaultswhenrunningexamplesthatacceptuserinput @H_404_0@-VVerbosemessagesfromthisscript |
|
@H_404_0@#./bin/solrcreate-help |
@H_404_0@Usage:solrcreate[-cname][-dconfdir][-nconfigName][-shards#][-replicationFactor#][-pport] @H_404_0@CreateacoreorcollectiondependingonwhetherSolrisrunninginstandalone(core)orSolrCloudmode(collection).Inotherwords,thisactiondetectswhichmodeSolrisrunningin,andthentakestheappropriateaction(eithercreate_coreorcreate_collection).Fordetailedusageinstructions,do: @H_404_0@bin/solrcreate_core-help @H_404_0@or @H_404_0@bin/solrcreate_collection–help |
@H_
404_0@
安装solr服务脚本用法
- @H_404_0@运行安装脚本
|
@H_404_0@#/tmp/solr-5.3.0/bin/install_solr_service.sh |
@H_404_0@ERROR:MustspecifythepathtotheSolrinstallationarchive,suchassolr-5.0.0.tgz @H_404_0@Usage:install_solr_service.shpath_to_solr_distribution_archiveOPTIONS @H_404_0@ThefirstargumenttothescriptmustbeapathtoaSolrdistributionarchive,suchassolr-5.0.0.tgz(only.tgzor.ziparesupportedformatsforthearchive) @H_404_0@SupportedOPTIONSinclude: @H_404_0@-dDirectoryforlive/writableSolrfiles,suchaslogs,pidfiles,andindexdata;defaultsto/var/solr @H_404_0@-iDirectorytoextracttheSolrinstallationarchive;defaultsto/opt/Thespecifiedpathmustexistpriortousingthisscript. @H_404_0@-pPortSolrshouldbindto;defaultis8983 @H_404_0@-sServicename;defaultstosolr @H_404_0@-uUsertoowntheSolrfilesandruntheSolrprocessas;defaultstosolrThisscriptwillcreatethespecifieduseraccountifitdoesnotexist. @H_404_0@NOTE:Mustberunastherootuser |
@H_
404_0@
创建集合
@H_
404_0@在这个部分,我们创建一个简单的Solr集合。
@H_
404_0@Solr可以有多个集合,但在这个示例,我们只使用一个。使用如下命令,创建一个新的集合。我们以solr
用户运行以避免任何权限
错误。
|
@H_404_0@#su-solr-c"/usr/local/solr/solr/bin/solrcreate-cgettingstarted-ndata_driven_schema_configs" |
@H_
404_0@在这个命令中,gettingstarted是集合的名字,-n指定配置集合。Solr默认提供了3个配置集合。这里我们使用的是schemaless,意思是可以提供任意名字的任意列,类型将会被猜测。
|
@H_404_0@Setupnewcoreinstancedirectory:/data/solr/data/gettingstarted @H_404_0@Creatingnewcore'gettingstarted'usingcommand:http://localhost:8983/solr/admin/cores?action=CREATE&name=gettingstarted&instanceDir=gettingstarted @H_404_0@{"responseHeader":{"status":0,"QTime":3247},"core":"gettingstarted"} |
@H_
404_0@
你现在已经创建了集合,并可以开始
添加数据。默认的架构只需要提供一列:id。没有其他默认列,只有动态列。
@H_
404_0@
添加和查询文档
@H_
404_0@在这个部分,我们将浏览Solr Web界面,
添加一些文档到集合中。
@H_
404_0@问你使用Web浏览器访问http://your_server_ip:8983/solr,Solr Web界面将会
显示为:
@H_
404_0@这个Web界面包含大量的有用信息,可以被用于调试在使用中产生的任何问题。
@H_
404_0@集合被划分为核,这就是为什么在Web界面中有大量的对核的参照。现在,gettingstarted只包含一个核,名为gettingstarted。在左手边,可以看到“Core Selector”下拉
菜单,我们可以选择gettingstarted看到更多信息。
@H_
404_0@在选择gettingstarted核之后,选择“Documents”。文档存储可被Solr
搜索的真实数据。因为我们使用了一个无模式的配置,我们可以使用任何列。我使用如下的JSON示例
添加了一个单一文档,通过拷贝以下到“Documents(s)”列:
|
@H_404_0@{ @H_404_0@"number":1, @H_404_0@"president":"GeorgeWashington", @H_404_0@"birth_year":1732, @H_404_0@"death_year":1799, @H_404_0@"took_office":"1789-04-30", @H_404_0@"left_office":"1797-03-04", @H_404_0@"party":"NoParty" @H_404_0@} |
@H_
404_0@点击“Submit document”
添加文档到索引。过一会,你会看到如下信息:
@H_
404_0@
添加文档后的
输出:
@H_404_0@Status:success @H_404_0@Response: @H_404_0@{ @H_404_0@"responseHeader":{ @H_404_0@"status":0, @H_404_0@"QTime":290 @H_404_0@} @H_404_0@} |
@H_
404_0@你可以使用一个类似的或完全不同的结构
添加更多文档,但你也可以只使用一个文档继续。
@H_
404_0@现在,选择左边的“Query”去
查询我们刚刚
添加的文档。保持屏幕中的默认值,在点击“Execute Query”之后,你最多看到10个文档,依赖于你
添加了多少:
@H_
404_0@
查询输出
@H_404_0@{ @H_404_0@"responseHeader":{ @H_404_0@"status":0, @H_404_0@"QTime":39, @H_404_0@"params":{ @H_404_0@"q":"*:*", @H_404_0@"indent":"true", @H_404_0@"wt":"json", @H_404_0@"_":"1442371884598" @H_404_0@} @H_404_0@}, @H_404_0@"response":{ @H_404_0@"numFound":1, @H_404_0@"start":0, @H_404_0@"docs":[ @H_404_0@{ @H_404_0@"number":[ @H_404_0@1 @H_404_0@], @H_404_0@"president":[ @H_404_0@"GeorgeWashington" @H_404_0@], @H_404_0@"birth_year":[ @H_404_0@1732 @H_404_0@], @H_404_0@"death_year":[ @H_404_0@1799 @H_404_0@], @H_404_0@"took_office":[ @H_404_0@"1789-04-30T00:00:00Z" @H_404_0@], @H_404_0@"left_office":[ @H_404_0@"1797-03-04T00:00:00Z" @H_404_0@], @H_404_0@"party":[ @H_404_0@"NoParty" @H_404_0@], @H_404_0@"id":"b9b294c1-4b68-4d96-adc2-f6fb77f60932", @H_404_0@"_version_":1512437472611532800 @H_404_0@} @H_404_0@] @H_404_0@} @H_404_0@} |
@H_
404_0@ 参考:http://lucene.apache.org/solr/quickstart.html