solr 7.3.1 mysql同步_Apache Solr学习 第七篇 实现solr定时数据同步

一、准备环境

已安装配置好solr和mysql数据。

jar包:solr-dataimportscheduler-1.1.1.jar。

原理:看了下jar的大概逻辑,就是在solr启动的时候,启动一个定时任务,以http方式访问solr 的dataimport接口。

二、配置

1.data-config.xml配置

A.bid,

A.bname,

A.author,

A.currPrice,

A.discount,

A.press,

A.publishtime,

A.edition,

A.pageNum,

A.wordNum,

A.printtime,

A.booksize,

A.paper,

A.cid,

A.image_w as imageW,

A.image_b as imageB,

A.orderBy,

price

FROM books A"deltaImportQuery="SELECT

A.bid,

A.bname,

A.author,

A.currPrice,

A.discount,

A.press,

A.publishtime,

A.edition,

A.pageNum,

A.wordNum,

A.printtime,

A.booksize,

A.paper,

A.cid,

A.image_w as imageW,

A.image_b as imageB,

A.orderBy,

price

FROM books A WHERE A.bid = '${dih.delta.bid}'"deltaQuery="select bid from books" >

配置参数说明:

driver:数据库驱动

url:数据库访问地址

query:全量更新SQL

deltaQuery: 增量更新SQL

${dih.delta.bid}表的主键

2.dataimport.properties配置

有的solr-dataimportscheduler-1.1.1.jar自带该文件,有的没有,如果是Tomcat启动solr,在/solrhome下新建文件夹conf,并在conf下新建dataimport.properties,

如果是用solr自带的jetty启动,则在solr-6.6.6\server\solr目录下新建conf,注意,在每一个core对应的conf文件夹也有dataimport.properties,但是和我们新建不是一个

文件,dataimport.properties内容如下:

#################################################

# #

# dataimport scheduler properties #

# #

#################################################

# server BASIC authorization by userName and password

# format:userName:password

# if no server BASIC authorization,please set:

# authorizationMsg=

#authorizationMsg=userName:password

# to sync or not to sync

# 同步执行更新

syncEnabled=1

#

# solr中对应得core名,可写多个,多个时用逗号“,”分隔

#

syncCores=books

# solr server name or IP address

# [defaults to localhost if empty]

server=localhost

# solr服务的端口号

# [defaults to 80 if empty]

port=8983

# application name/context

# [defaults to current ServletContextListener's context (app) name]

webapp=solr

# URL params [mandatory]

# remainder of URL

#增量更新对应的访问参数,注意/dataimport?地址不同版本sorl了能地址名不同,具体可登录solr管理后台##查看dataimport的具体访问ULR

params=/dataimport?command=delta-import&clean=false&commit=true&optimize=false&wt=json&indent=true&verbose=false&debug=false

# schedule interval

# number of minutes between two runs

# 定时任务执行增量更新的间隔,不能为0.5这样的数,默认设置为1分钟

interval=1

# 重做索引的时间间隔,单位分钟,默认7200,即5天;

# 为空,为0,或者注释掉:表示永不重做索引,即全量更新的时间间隔

reBuildIndexInterval=7200

# 重做索引的参数,即全量更新

reBuildIndexParams=/dataimport?command=full-import&clean=true&commit=true&optimize=true&wt=json&indent=true&verbose=false&debug=false

# 重做索引时间间隔的计时开始时间,第一次真正执行的时间=reBuildIndexBeginTime+reBuildIndexInterval*60*1000;

# 两种格式:2012-04-11 03:10:00 或者 03:10:00,后一种会自动补全日期部分为服务启动时的日期

reBuildIndexBeginTime=03:10:00

3.全量更新和增量更新

全量更新:即删除原来core下的所有索引数据,并从数据库中重新导入

增量更新:根据/core/conf/dataimport.properties记录的时间,将查到的数据做对比,只更新有改变的索引会更新

4.将solr-dataimportscheduler-1.1.1.jar放入到WEB-INF下的lib目录中

5.在WEB-INF/web.xml中配置监听器

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

配置完成启动项目,一分钟以后就可以去查看数据更新了

三、遇到的问题

涉及问题,启动时候报了

ERROR: Solr at http://localhost:8983/solr did not come online within 30 seconds!

查看solr启动日志,发现

java.lang.NoSuchMethodError: org.apache.solr.core.SolrResourceLoader.getInstanceDir()Ljava/lang/String;

at org.apache.solr.handler.dataimport.scheduler.SolrDataImportProperties.loadProperties(SolrDataImportProperties.java:37)

at org.apache.solr.handler.dataimport.scheduler.BaseTimerTask.reloadParams(BaseTimerTask.java:57)

at org.apache.solr.handler.dataimport.scheduler.BaseTimerTask.(BaseTimerTask.java:39)

像这种报错一般都是jar包不兼容引起的,打开了jar看了看,发现有solr-core的有个类的构造方法发生了改变,所以反编译修改了solr-dataimportscheduler-1.1.1.jar,

修改后已测试好使, 修改后的jar地址。

提取码:vf3u

solr涉及资源已全部分享网盘,喜欢的给文章点个赞,谢谢大家了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值