solr的master-slave和Multiple Cores

Solr multicore配置

Solr继续学习中,感觉Solr的multicore主要用途有两个:

1、充分利用服务器资源。在一台服务器上部署不用的搜索应用。

2、提高一个应用服务能力,在服务器上同时部署同一个应用的多个core,这些core共用一份索引数据(对Solr的运行机制不了解,不知道Solr并发能力怎么样)。

基于Solr的列车时刻表查询服务基础上,我又搭建了一个身份证区域查询服务。这两个服务分别放在两个core中。Solr中配置多core是非常简单的,只要将example/multicore拷贝到某个目录,然后设置”-Dsolr.solr.home=/path/to/multicore”。每个core有自己的schema.xml和solrconfig.xml文件。通过下面这个url可以看到所有的core列表。

这个身份证区域查询服务可以通过身份证号码中的区位码查询其对应的地区,也可以根据地区名查询其区位码。这里就需要对中文进行分词,可以使用Solr内置的CJK分词器来简单地做分词(2-gram)。另外我要将用户搜索记录保存到日志中,对于互联网应用来说,搜索日志是宝贵的资源,感觉Solr对这块支持还比较薄弱。

1、CJK分词。

?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<? xml version = "1.0" encoding = "UTF-8" ?>
 
< schema name = "example" version = "1.2" >
 
   < types >
     < fieldType name = "sint" class = "solr.SortableIntField" sortMissingLast = "true" omitNorms = "true" />
 
     < fieldtype name = "cjktext" class = "solr.TextField" >
                 < analyzer >
                         < tokenizer class = "solr.CJKTokenizerFactory" />
                 </ analyzer >
     </ fieldtype >
 
   </ types >
 
  < fields >
 
    < field name = "region_id" type = "sint" indexed = "true" stored = "true" />
    < field name = "region_name" type = "cjktext" indexed = "true" stored = "true" />
  </ fields >
 
  <!-- field for the QueryParser to use when an explicit fieldname is absent -->
  < defaultSearchField >region_id</ defaultSearchField >
 
  <!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
  < solrQueryParser defaultOperator = "OR" />
 
</ schema >

2、保存日志。参考Solr 使用 Log4j。发现最后产生的日志信息太多了,要想想怎么将查询日志和操作日志分离开。

 

 

 

 

需求:

1. 实现SOLR主,辅服务器更新同步,每次客户端COMMIT请求都会及时应用在辅服务器上。

2. 实现MULTICORE,实际生产环境中往往会有多个搜索应用实例。

 

步骤:

一、准备条件

1. 服务器准备

准备两台服务器:

一台用作主服务器(192.168.0.36),负责分发索引

另一台负责辅服务器(192.168.0.46),负责承载搜索服务。

2.软件环境

Linux版本不限,32,64位不限

应用容器:TOMCAT 6.0

JAVA版本:JDK1.6以上版本

Solr应用环境目录: /solr/video/ (可使用ln –s 创建软连接) 和 /solr/album/ (本例设定为两个应用:实际情况可自由增减 )

Solr索引目录:/solr/data /album 和 /solr/data/video

3. 划分应用

本例中划分两个应用 专辑 album 和 视频 video

 

4. 基础目录创建(主,辅均需配置)

a)在 /solr/ 应用环境目录下创建两个目录:album 和 video

b)分别将SOLR安装目录下Solr/example/solr/conf文件夹至这两个目录

c)分别复制安装目录solr/src/scripts文件夹至 album 和 video目录,并将script改名为bin(后续要用到)

d)按照特定需求分别修改索引字段结构文件: schema.xml(有关此文件的配置不再撰述) e)复制 Solr/example/multicore 下的solr.xml文件至 应用环境根目录:/solr/ f)创建索引目录 /solr/data/album 和 /solr/data/video

 

二、 配置MULTICORE(主,辅均需配置)

划分业务类型,如做一个视频搜索引擎需要专辑和视频两大应用,则:

1)配置SOLR业务类型:在 /solr/下 编辑solr.xml文件

 

<core name="core0" instanceDir="core0" />

<core name="core1" instanceDir="core1" />

修改为

<core name="album" instanceDir="album" />

<core name="video" instanceDir="video" />

 

2)指定索引目录,进入/solr/album/conf目录,打开编辑器修改solrconfig.xml,找到

<dataDir> 节点,将真正的目录“/solr/data/album”替换掉原有数据。(视频应用步骤与此相同。)

 

三、 配置分布式应用(以下均在主服务器上配置)

 

1) 分别修改分布式分发脚本: scripts.conf

 

(/solr/album/bin 和 /solr/video/bin)

 

#触发外部命令所使用的用户

user=haiting

#本地机器名

solr_hostname=localhost

#本地SOLR开放的端口(及TOMCAT 服务端口)

solr_port=9001

#分发脚本使用的RSYNC服务端口,业务端口要区分开,在本例中,album为19001,video为19002,客户端与服务端端口设置需一致,否则会导致SNAPPULLER过程失败。 rsyncd_port=19001

#索引文件路径

data_dir=/solr/data/album

#TOMCAT容器中SOLR服务名(默认不变)

webapp_name=solr

#主服务器IP(主与辅同配置)

master_host=192.168.0.46

#主服务器索引文件路径

master_data_dir=/solr/data/album

#主服务器状态过程日志存放目录

master_status_dir=/solr/status/album

 

2)修改脚本所在默认路径

(通过修改scripts-util公用脚本实现)

找到该文件所在路径:/solr/album/bin和/solr/video/bin

第27行

confFile=${solr_root}/conf/scripts.conf

修改为:

confFile=/solr/bin/album/conf/scripts.conf

confFile=/solr/bin/video/conf/scripts.conf

注明:不进行此步骤会造成SOLR外部调用监听器执行会失败(/solr/)

 

3)修改主配置文件solrconfig.xml

 

找到以下目录:/solr/album/conf和 /solr/video/conf

分别修改两个应用的 COMMIT监听器,使得SOLR接收到COMMIT请求时,自动调用外

部命令snappuller

 

找到 postCommit 节点,配置后的节点如下所示:

<listener event="postCommit" class="solr.RunExecutableListener">

<str name="exe">/solr/video/bin/snapshooter</str>

<str name="dir">.</str>

<bool name="wait">true</bool>

<arr name="args"> <str>-d</str> <str>/solr/data/video</str> </arr>

<arr name="env"> <str>MYVAR=val1</str> </arr>

</listener>

注明:每一个应用对应的配置文件都需要配置,包括外部命令的目录.

 

四、配置、执行分发脚本

 

1.主服务器

1)启动SOLR

2)启用RSYNC

手工执行脚本:

/solr/video/bin/rsyncd-enable –v

说明:-v终端打印执行详细日志

3)开启RSYNC

/solr/video/bin/rsyncd-start –v

2.客户端

推荐使用SolrJ(目录位于/solr/src/solrj)

a)将SOLR接收URL改为:http://192.168.0.36:9001/solr/video

(或http://192.168.0.36:9001/solr/album )

b)执行发送命令,将数据推送至主服务器

3.辅服务器

a)配置清理脚本

su haiting

crontab –e

0 0 * * * /solr/album/bin/snapcleaner -D 7

0 0 * * * /solr/video/bin/snapcleaner -D 7

说明:系统每7天调用一次清理脚本,清理不用的快照

 

b)启用快照

手动执行

/solr/video/bin/snappuller-enable -v

c)获取并安装快照

配置cron

su haiting

crontab –e

*/5 * * * * /solr/video/bin/snappuller;/solr/video/bin/snapinstaller

*/5 * * * * /solr/album/bin/snappuller;/solr/album/bin/snapinstaller

说明:系统每五分钟调用一次smappuller和 snapinstaller,及每五分钟生效一次。

本文补充: 因SOLR的复制分发模式所需要的脚本没有考虑到 MULTICORE模块存在,所以在两种并行的情况下会造成快照安装失败,报 logMessage snapshot installed but Solr server has not open a new Searcher 错误。

具体修改方法: 在/solr/album/bin 和 /solr/video/bin 下修改commit文件,

将第三页中的 curl_url=http://${solr_hostname}:${solr_port}/${webapp_name}/update

修改成 curl_url=http://${solr_hostname}:${solr_port}/${webapp_name}/album/update 保存即可。

 

三亿文库3y.uu456.com包含各类专业文献、高等教育、幼儿教育、小学教育、中学教育、应用写作文书、各类资格考试、行业资料、专业论文、生活休闲娱乐、solr 分布式部署59等内容。


<iframe id="cproIframe21383726403019" src="http://cpro.baidu.com/cpro/ui/uijs.php?rs=0&amp;tu=u1138180&amp;tn=baiduTlinkInlay&amp;n=00009009_cpr&amp;adn=24&amp;rsi1=92&amp;rsi0=708&amp;rad=&amp;rss0=%23FFFFFF&amp;rss1=%23FFFFFF&amp;conOP=1&amp;rss2=%23ff0000&amp;rss3=&amp;rss4=&amp;rss5=&amp;rss6=%23e10900&amp;rsi5=4&amp;ts=1&amp;at=103&amp;ch=0&amp;cad=1&amp;aurl=&amp;rss7=&amp;cpa=1&amp;fv=11&amp;cn=0&amp;if=16&amp;word=http%3A%2F%2F3y.uu456.com%2Fbp-2debfb010740be1e6s0e9aeb-1.html&amp;refer=https%3A%2F%2Fwww.google.com.hk%2F&amp;ready=1&amp;jk=d341638eaace2cbe&amp;jn=3&amp;lmt=1383697603&amp;csp=1366,768&amp;csn=1366,728&amp;ccd=32&amp;chi=1&amp;cja=true&amp;cpl=23&amp;cmi=74&amp;cce=true&amp;csl=zh-CN&amp;did=2&amp;rt=4&amp;dt=1383726403&amp;pn=7:3%7CbaiduTlinkInlay:text_default_336_280%7C103:103&amp;ev=402653184&amp;c01=0&amp;prt=1383726402616&amp;i3=f&amp;anatp=0&amp;stid=0&amp;lunum=6&amp;scale=&amp;skin=&amp;titFS=14&amp;titFF=%25E5%25AE%258B%25E4%25BD%2593&amp;titTA=left&amp;conBW=0&amp;hn=4&amp;wn=6" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" align="center,center" width="708" height="92"></iframe>

 

猜你喜欢

转载自kavy.iteye.com/blog/1972176