solr的Replication详解.docx
- 文档编号:18044671
- 上传时间:2023-08-07
- 格式:DOCX
- 页数:16
- 大小:242.57KB
solr的Replication详解.docx
《solr的Replication详解.docx》由会员分享,可在线阅读,更多相关《solr的Replication详解.docx(16页珍藏版)》请在冰点文库上搜索。
solr的Replication详解
solr的Replication详解
本文档介绍了index索引复制的工作在HTTP的Java实现,包括solr1.4版本。
自solr1.1开始在SSH / rsync信息为基础的复制请查阅CollectionDistribution。
请注意,在solr4.0 solrcloud,复制将以push的方式,该方式复制index将不再是必要的了。
特征
1、无需外部脚本复制
2、只在solrconfig.xml中配置
3、Replicates配置文件
4、跨平台的工作具有相同的结构
5、在硬链接不依赖操作系统相关
6、使用Solr紧密集成;管理页面提供了细粒度的各个方面的复制控制
配置
Java复制的特征是基于一个requesthandler。
配置复制是类似于任何正常的requesthandler。
Master
--Replicateon'startup'and'commit'.'optimize'isalsoavalidvalueforreplicateAfter.-->
--Createabackupafter'optimize'.Othervaluescanbe'commit','startup'.Itispossibletohavemultipleentriesofthisconfigstring.Notethatthisisjustforbackup,replicationdoesnotrequirethis.-->
--
--Ifconfigurationfilesneedtobereplicatedgivethenameshere,separatedbycomma-->
--Thedefaultvalueofreservationis10secs.Seethedocumentationbelow.Normally,youshouldnotneedtospecifythis-->
00:
10
--keeponly1backup.Usingthisparameterprecludesusingthe"numberToKeep"requestparameter.(Solr3.6/Solr4.0)-->
--(Forthistoworkinconjunctionwith"backupAfter"withSolr3.6.0,seebugfixhttps:
//issues.apache.org/jira/browse/SOLR-3361)-->
说明:
1、如果你有commit非常频繁,网络是特别慢,你可以调整的额外属性,
00:
10,从masters到slave下载大约是5MB的数据。
默认值是10秒。
2、如果你使用的是replicateafter的startup选项,必须commit/options也配置,如果你想在未来有触发复制/优化。
如果只是给了startup选项,在启动完成后commit/options将不再触发replication。
Replicatingsolrconfig.xml
在master 中的 solrconfig.xml配置,在replication 的requesthandler中,添加下面的一行
solrconfig.xml,x.xml,y.xml
这使得在slave上本地配置solrconfig_slave.XML”将被保存为“solrconfig.XML。
其他所有的文件将被按照现在的名字保存。
在master 服务中,slave配置文件的文件名可以是任何东西,只要是在“conffiles”字符串正确识别;然后将它保存为冒号后出现任何文件名:
即使用冒号分割”。
Slave
--fullyqualifiedurltothemastercore.Itispossibletopassonthisasarequestparamforthefetchindexcommand-->
//master_host:
port/solr/corename
--Intervalinwhichtheslaveshouldpollmaster.FormatisHH:
mm:
ss.Ifthisisabsentslavedoesnotpollautomatically.
ButafetchindexcanbetriggeredfromtheadminorthehttpAPI-->
00:
20
--THEFOLLOWINGPARAMETERSAREUSUALLYNOTREQUIRED-->
--tousecompressionwhiletransferringtheindexfiles.Thepossiblevaluesareinternal|external
ifthevalueis'external'makesurethatyourmasterSolrhasthesettingstohonourtheaccept-encodingheader.
seeherefordetailshttp:
//wiki.apache.org/solr/SolrHttpCompression
Ifitis'internal'everythingwillbetakencareofautomatically.
USETHISONLYIFYOURBANDWIDTHISLOW.THISCANACTUALLYSLOWDOWNREPLICATIONINALAN-->
--Thefollowingvaluesareusedwhentheslaveconnectstothemastertodownloadtheindexfiles.
Defaultvaluesimplicitlysetas5000msand10000msrespectively.TheuserDOESNOTneedtospecify
theseunlessthebandwidthisextremelyloworifthereisanextremelyhighlatency-->
--IfHTTPBasicauthenticationisenabledonthemaster,thentheslavecanbeconfiguredwiththefollowing-->
注:
如果你不使用的core,那你干脆省略上面的“corename”参数中masterurl。
确保该URL是否正确,只是一个浏览器到URL。
你必须得到一个状态好的响应。
建立一个中继器
master可以提供这么多的slave而不影响性能。
一些组织在多个数据中心已经部署了从属服务器。
如果每一个slave下载索引从远程数据中心,由此产生的下载可能会消耗太多的网络带宽。
为了避免这样的情况下的性能退化,您可以配置一个或多个slave作为中继器。
在master和slave之间,中继器是一个简单的节点。
1、配置一个服务器作为中继器,无论是master还是slave配置清单都需要出现在replicationhandler requesthandler在solrconfig.xml文件。
一个repeater的配置例子
8080/solr
00:
60
enable/disablemaster/slaveinanode
如果一个服务器需要从slave变成master或如果您希望为master和slave使用相同的solrconfig.xml,做如下,
false}
false}
//master_host:
8983/solr
00:
60
注意:
一定要加上一个“flase”为默认enable.master和enable.slave,否则部署将失败,日志将显示Solr用.替换一个正确的目录。
在solr管理主页,你不会看到core名称链接(点击进入唯一的链接,你会得到“失踪”的核心路径错误)。
注意:
如果部署是好的但是你仍然会看到与核心的名字没有联系,这可能是权限问题。
这通常发生在当你集实例目录服务器的默认应用程序文件夹下的AP。
解决方法是创建一个文件夹具有良好的权限,并把solr.xml进入那个文件夹的根。
编辑上下文指向文件solr/home文件夹。
现在取消部署和重新部署了以前的程序。
当master开始工作,添加 -Denable.master=true,且在slave中加入 -Denable.slave=true,或者,将那些值存储在solrcore.properties中,向下面这样:
#solrcore.propertiesinmaster
enable.master=true
enable.slave=false
在slave中
#solrcore.propertiesinslave
enable.master=false
enable.slave=true
注:
每个core拥有自己的solrcore.properties位于conf目录下的每个core的实例目录。
ReplicationwithMultiCore
为每个core添加replication复制请求handler。
Master 的配置仍然是相同的
Slave仅仅需要添加core.name属性
//${MASTER_CORE_URL}/${solr.core.name}
ReplicationDashboard
这显示以下信息
1、当前复制状态
2、percentage/sizedownloaded/tobedownloaded
3、Currentfilebeingdownloaded
4、Timetaken/Timeremaining
Thefollowingactionscanbeperformedfromthedashboard
∙Enable/Disablepolling
∙Forcestartreplication
∙Abortanongoingreplication
如何工作?
此功能依赖于Lucene的IndexDeletionPolicy特征。
通过这个API,Lucene暴露indexcommits为回调每个提交/优化。
一个IndexCommit暴露相关文件每次提交。
这使我们能够确定需要复制的文件。
当提交或优化的时候会发生什么?
当提交/优化了master,replicationhandler读取为每个提交点关联的文件名列表。
这依赖于配置的replicateafter参数来决定这些文件的名字时,从Lucene被提取并存储。
Slave如何复制?
slave是完全不知道master。
slave不断轮询master(取决于“pollinterval参数)来检查当前索引版的master。
如果slave发现master有一个新版本的启动复制过程的指标。
步骤如下,
∙Slave分配的文件列表框”命令来获取文件的列表。
此命令返回的文件的名称以及一些元数据(大小,lastmodified,别名等(如果有))
∙Slave通过他们检查与自己的index,如果有任何的文件在本地索引。
然后继续下载丢失的文件(命令名是“filecontent’)。
使用自定义格式(类似于HTTP块编码)或下载的每个文件的一部分的全部内容。
如果连接失败,下载从失败点开始。
在任何时候,它试图5次复制如果换链接不上,完全放弃之前。
∙文件下载到一个临时目录。
如果slave或master崩溃之间不出现任何错误。
它只是中止当前复制。
∙Afterthedownloadcompletes,allthenewfilesare'mov'edtotheslave'sliveindexdirectoryandthefiles'timestampswillmatchthetimestampsinthemaster.
∙A'commit'commandisissuedontheslavebytheSlave'sReplicationHandlerandthenewindexisloaded.
配置文件如何复制?
∙文件被复制,必须显式地使用“conffiles参数。
∙只有在“conf目录的Solr实例的文件复制。
.
∙Thefilesarereplicatedonlyalongwithafreshindex.Thatmeansevenifafileischangedinthemasterthefileisreplicatedonlyafterthereisanewcommit/optimizeonthemaster.
∙Unliketheindexfiles,wherethetimestampisgoodenoughtofigureoutiftheyareidentical,conffilesarecomparedagainsttheirchecksum.Theschema.xmlfiles(onmasterandslave)aresameiftheirchecksumsmatch.
∙Conffilesarealsodownloadedtoatempdirbeforetheyare'mov'edtotheoriginalfiles.Theoldfilesarerenamedandkeptinthesamedirectory.ReplicationHandlerdoesnotautomaticallycleanuptheseoldfiles.
∙Ifareplicationinvolveddownloadingofatleastoneconffileacorereloadisissuedinsteadofa'commit'command.
WhatifIadddocumentstotheslaveorifslaveindexgetscorrupted?
Ifdocsareaddedtotheslave,thentheslaveisnotinsyncwiththemasteranymore.But,itdoesnotdoanythingtokeepitinsyncwithmasteruntilthemasterhasanewerindex.Whenacommithappensonthemaster,theindexversionofthemasterwillbecomedifferentfromthatoftheslave.Theslavefetchesthelistoffilesandfindsthatsomeofthefiles(samename)arethereinthelocalindexwithadifferentsize/timestamp.Thismeansthatthemasterandslavehaveincompatibleindexes.Slavethencopiesallthefilesfrommaster(theremaybescopetooptimizethis,butthisisararecaseandmaynotbeworthit)toanewindexdirandandasksthecoretoloadthefreshindexfromthenewdirectory.
HTTPAPI
solr的ReplicationHandler提供了一系列http命令(参数command),支持的可选值如下:
∙slave从master获取最新的索引点信息r:
http:
//master_host:
port/solr/replication?
command=indexversion
∙Abortcopyingindexfrommastertoslavecommand:
http:
//slave_host:
port/solr/replication?
command=abortfetch
∙Createabackuponmasteriftherearecommittedindexdataintheserver,otherwisedonothing.Thisisusefultotakeperiodicbackups.Command:
http:
//master_host:
port/solr/replication?
command=backup.
∙Canalsoprovidealocationparameter(i.e.&location=/foo/bar),whichisthedirectorytowritethebackuptoondisk.
∙Specifyparameter"numberToKeep"toindicatehowmanybackupstoretain(includingthisone).Olderbackupswillbeautomaticall
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- solr Replication 详解