您现在的位置是:首页 > 文章详情

solr7.4定时/实时更新/重建索引配置,及报错404问题解决方案

日期:2018-08-30点击:362

 

本文分两部分:

一、Solr定时/实时更新/重建索引配置。

二、Solr7+版本,服务器启动报错,页面404解决方案。(重点)


 

一、solr定时/实时更新/重建索引配置

准备工作要做好:

    1、下载jar包:solr-dataimportscheduler-1.1.jar (网上也有1.0版本,但是具体对应solr版本请自行查找)

下载地址:http://pan.baidu.com/s/1hsySs2S

     注意注意注意(重要的事情说三遍):当solr7+以上版本时,该jar包会有问题,配置后服务器启动会报错,页面404,具体详情后面会有解决方案。

     2、新建文件:dataimport.properties,文件复制下面的就好,具体配置含义已给出注释:

 ################################################# # # # dataimport scheduler properties # # # ################################################# # to sync or not to sync # 1 - active; anything else - inactive # 这里的配置不用修改 syncEnabled=1 # which cores to schedule # in a multi-core environment you can decide which cores you want syncronized # leave empty or comment it out if using single-core deployment # 修改成你所使用的core,我这里是我自定义的core:simple syncCores=product_auto # solr server name or IP address # [defaults to localhost if empty] 这个一般都是localhost不会变 server=localhost # solr server port # [defaults to 80 if empty] # 安装solr的tomcat端口,如果你使用的是默认的端口,就不用改了,否则改成自己的端口就好了 port=8080 # application name/context # [defaults to current ServletContextListener's context (app) name] # 这里默认不改 webapp=solr # URL params [mandatory] # remainder of URL # 这里改成下面的形式,solr同步数据时请求的链接 params=/dataimport?command=delta-import&clean=false&commit=true # schedule interval # number of minutes between two runs # [defaults to 30 if empty] #这里是设置定时任务的,单位是分钟,也就是多长时间你检测一次数据同步,根据项目需求修改 # 开始测试的时候为了方便看到效果,时间可以设置短一点 interval=1 # 重做索引的时间间隔,单位分钟,默认7200,即5天; # 为空,为0,或者注释掉:表示永不重做索引 reBuildIndexInterval=7200 # 重做索引的参数 reBuildIndexParams=/select?qt=/dataimport&command=full-import&clean=true&commit=true # 重做索引时间间隔的计时开始时间,第一次真正执行的时间=reBuildIndexBeginTime+reBuildIndexInterval*60*1000; # 两种格式:2012-04-11 03:10:00 或者 03:10:00,后一种会自动补全日期部分为服务启动时的日期 reBuildIndexBeginTime=03:10:00 

准备好这一个jar包和dataimport.properties文件,开始下面的步骤……

步骤一:将solr-dataimportscheduler-1.1.jar包复制到apache-tomcat-7.0.72\webapps\solr\WEB-INF\lib中。

步骤二:在apache-tomcat-7.0.72\webapps\solr\WEB-INF目录下的web.xml文件中添加监听配置(<servlet>标签前面):

 <listener> <listener-class>org.apache.solr.handler.dataimport.scheduler.ApplicationListener</listener-class> </listener>

注意(又一个注意的地方):org.apache.solr.handler.dataimport.scheduler.ApplicationListener 后面不能有空格,否则可能会报错,且很难发现问题原因。

步骤三:在\solrhome目录下新建一个conf文件夹(与simple文件夹同目录),将dataimport.properties文件放在conf文件夹中。

步骤四:重启tomcat,访问Solr。

大部分人应该到这里就搞定了。


但是,但是,但是 这个坑被我踩到了!!!

二、Solr7+版本,服务器启动报错,页面404解决方案。

但是本人使用Solr版本为7.4 在按照上述教程配置后,Tomcat无法启动,页面报错404。

查看日志,内容如下:

31-Aug-2018 09:47:43.139 信息 [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log ContextListener: contextInitialized() 31-Aug-2018 09:47:43.140 信息 [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log SessionListener: contextInitialized() 31-Aug-2018 09:47:43.141 信息 [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log ContextListener: attributeAdded('StockTicker', 'async.Stockticker@4f752dd7') 31-Aug-2018 09:47:47.637 严重 [localhost-startStop-1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [org.apache.solr.handler.dataimport.scheduler.ApplicationListener] java.lang.NoSuchMethodError: org.apache.solr.core.SolrResourceLoader.<init>(Ljava/lang/String;)V at org.apache.solr.handler.dataimport.scheduler.SolrDataImportProperties.loadProperties(SolrDataImportProperties.java:36) at org.apache.solr.handler.dataimport.scheduler.BaseTimerTask.reloadParams(BaseTimerTask.java:57) at org.apache.solr.handler.dataimport.scheduler.BaseTimerTask.<init>(BaseTimerTask.java:39) at org.apache.solr.handler.dataimport.scheduler.DeltaImportHTTPPostScheduler.<init>(DeltaImportHTTPPostScheduler.java:20) at org.apache.solr.handler.dataimport.scheduler.ApplicationListener.contextInitialized(ApplicationListener.java:47) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4792) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5256) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1140) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

经过重重困难,终于找到了解决方案,问题原因是 引入的apache-solr-dataimportscheduler-1.0.jar或者1.1 这个jar包针对高版本solr 有并未及时维护。也就是版本没有跟上所以产生bug。

有大神已经解决了该问题,且针对该jar反编译且重新打包了。

solr-dataimport-scheduler.jar

下载地址:https://download.csdn.net/download/vikasdhanve/10637569

更换这个jar包后,然后该问题迎刃而解。

在处理该问题的时候,在网上的确是碰到了很多人跟我一样的问题,但是始终就没有人给出一个解决方案。

我这儿就借着大神们的砖搬给大家,也算是个人记录一下该问题的处理方法吧。

大家有什么问题可以留言,一起讨论。

原文链接:https://yq.aliyun.com/articles/660563
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章