solr5.5(3)——结合mysql定时索引

1.首先请看我的第一篇solr文章搭建dataimpotrt功能,这篇还有些重复,就单做复习吧

2.在mysql里建立一张表(记得一定要有个s_updateTime字段,类型是timestamp,有个默认值是CURRENT_TIMESTAMP)


2.在我们上一章建立的目录D:\software\solrHome\core1\conf目录下找到一个managed-schema.xml(我的第一篇文章也讲过)


3.找到solr-5.5.3\example\example-DIH\solr\db\conf\db-data-config.xml,将它拷贝到D:\software\solrHome\core1\conf目录下,并改名为data-config.xml

4.将data-config.xml打开,进行编辑,核心思想就是${dih.delta.s_id}和${dih.last_index_time}记录本次索引的id和最后索引的时间,时间在D:\software\solrHome\core1\conf目录下的dataimport.properties记录着


5.现在可以将D:\software\solrHome\core1\conf\solrconfig.xml进行编辑


6.在网上下载一个apache-solr-dataimportscheduler-1.0.jar包,解压后拿到里面的dataimport.properties文件,将里面的文件修改成一下内容,并将此文件放在D:\software\solrHome\conf目录下(如果没有conf目录就自己建立一个,记得不是在core1目录下的conf)


#################################################  
#                                               #  
#       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  
syncCores=core
  
#  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=8070
  
#  application name/context  
#  [defaults to current ServletContextListener's context (app) name]  
#  这里默认不改    
webapp=solr
  
#  URL params [mandatory]  
#  remainder of URL  
#  这里要改成下面的形式    
params=/dataimport?command=delta-import&clean=false&commit=true
  
#  schedule interval   
#  [defaults to 30 if empty]  
#  这里是设置定时任务的,单位是秒,也就是多长时间你检测一次数据同步,根据项目需求修改    
#  开始测试的时候为了方便看到效果,时间可以设置短一点,我这是60秒
interval=60
  
#  重做索引的时间间隔,单位分钟,默认7200,即1天;   
#  为空,为0,或者注释掉:表示永不重做索引  
reBuildIndexInterval=7200
  
#  重做索引的参数  
reBuildIndexParams=/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

#  Authorization认证:用户名
username=aaaa

# Authorization认证:密码
password=bbbb
*******一定要注意,这些参数的后面一定不能有空格,还有下面的web.xml配置

7.然后将定时任务jar包(我是在其他网上下载的1.1.1jar包,后来发现客户端需要加密就改了下)和D:\solr\solr-5.5.3\dist目录下的solr-dataimporthandler-5.5.3.jar和solr-dataimporthandler-extras-5.5.3.jar拷贝到apache-tomcat-8.0.39\webapps\solr\WEB-INF\lib目录下

7.1:这个我需要说明下,因为我的jar被我修改过,所以,有些配置文件进行过修改和添加。Authorization认证是我在apache-tomcat-8.5.11\conf下面有个tomcat-users.xml文件,我在下面添加这么一行,

	<role rolename="solr"/>
	
	<user username="aaaa" password="bbbb" roles="solr"/>

6.2:然后在apache-tomcat-8.5.11\webapps\solr\WEB-INF下面打开web.xml文件,在<web-app></web-app>中间添加

 <security-constraint>
    <web-resource-collection>
        <web-resource-name>Restrict access to Solr admin</web-resource-name>
        <url-pattern>/</url-pattern>
    </web-resource-collection>
	
    <auth-constraint>
        <role-name>solr</role-name>
    </auth-constraint>
</security-constraint>
<login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>default</realm-name>
</login-config>
6.3在登录的时候会让你输入用户名和密码


8.在apache-tomcat-8.0.39\webapps\solr\WEB-INF\web.xml文件下增加

<listener>        
<listener-class>        
org.apache.solr.handler.dataimport.scheduler.ApplicationListener
</listener-class>        
</listener>
9.启动tomcat

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值