码迷,mamicode.com
首页 > 系统相关 > 详细

Solr7.1--- 单机Linux环境搭建

时间:2017-11-28 01:41:12      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:打开   lang   manual   demo   mysq   jdbc   zone   tty   mysql   

应网友的要求,写个关于Linux单机的

首先,把MySQL驱动包和solr7.1安装包上传到服务器,我上传到了自定义的目录/mysoft

 

执行服务安装脚本

 1. 先切换到root用户

 2. 解压出脚本

 3. 执行安装命令,注意要把其中的‘taozi’换成你的普通用户名

[taozi@localhost 桌面]$ su root
密码:
[root@localhost mysoft]# tar zxf solr-7.1.0.tgz solr-7.1.0/bin/install_solr_service.sh --strip-components=2
[root@localhost mysoft]# ./install_solr_service.sh solr-7.1.0.tgz -i /opt -d /var/solr -u taozi -s solr -p 8983 -n

Extracting solr-7.1.0.tgz to /opt


Installing symlink /opt/solr -> /opt/solr-7.1.0 ...


Installing /etc/init.d/solr script ...


Installing /etc/default/solr.in.sh ...

Service solr installed.
Customize Solr startup configuration in /etc/default/solr.in.sh
Not starting Solr service (option -n given). Start manually with service solr start

 

 

 开启防火墙端口

 

[root@localhost mysoft]# firewall-cmd --zone=public --add-port=8983/tcp --permanent
success
[root@localhost mysoft]# systemctl restart firewalld

 

 

 启动服务(其实我喜欢先配置完毕再启动,这里只是让大家看一下有没有安装成功)

 

[root@localhost mysoft]# service solr start
Waiting up to 180 seconds to see Solr running on port 8983 [/]  
Started Solr server on port 8983 (pid=6375). Happy searching!

 

 打开前台:

技术分享图片

 

 建立核心

 注意要切换到普通用户

[root@localhost mysoft]# cd /opt/solr-7.1.0/
[root@localhost solr-7.1.0]# su taozi
[taozi@localhost solr-7.1.0]$ ./bin/solr create -c mycore
WARNING: Using _default configset. Data driven schema functionality is enabled by default, which is
         NOT RECOMMENDED for production use.

         To turn it off:
            curl http://localhost:8983/solr/mycore/config -d ‘{"set-user-property": {"update.autoCreateFields":"false"}}‘

Created new core mycore

 

 查看界面

技术分享图片

人家说没有dataimport-handler,那就配置一个呗。

 

关闭服务

[taozi@localhost solr-7.1.0]$ su root
密码:
[root@localhost solr-7.1.0]# service solr stop
Sending stop command to Solr running on port 8983 ... waiting up to 180 seconds to allow Jetty process 6375 to stop gracefully.

 

进入solr主目录 

[root@localhost solr-7.1.0]# cd /var/solr/data/
[root@localhost data]# ll
总用量 8
drwxrwxr-x. 4 taozi taozi   50 11月 27 22:21 mycore
-rw-r-----. 1 taozi taozi 2117 11月 27 22:14 solr.xml
-rw-r-----. 1 taozi taozi  975 11月 27 22:14 zoo.cfg

 

 进入core的conf目录

[root@localhost data]# cd mycore/conf/
[root@localhost conf]# ll
总用量 128
drwxrwxr-x. 2 taozi taozi  4096 11月 27 22:14 lang
-rw-rw-r--. 1 taozi taozi 50739 10月 13 22:59 managed-schema
-rw-rw-r--. 1 taozi taozi   308 10月 13 22:59 params.json
-rw-rw-r--. 1 taozi taozi   873 10月 13 22:59 protwords.txt
-rw-rw-r--. 1 taozi taozi 53959 10月 13 23:07 solrconfig.xml
-rw-rw-r--. 1 taozi taozi   781 10月 13 22:59 stopwords.txt
-rw-rw-r--. 1 taozi taozi  1124 10月 13 22:59 synonyms.txt
[root@localhost conf]# su taozi
[taozi@localhost conf]$ vim data-config.xml

 

新建data-config.xml文件,注意切换普通用户。

添加内容如下:【注意:这个是配置数据库的对应关系的,还有,MySQL数据库仅仅本地访问支持root用户,网络访问需要授权新用户,这里我的数据库用户是非root用户】

<dataConfig>
    <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://192.168.1.112:3306/demo" user="admin" password="admin" />
    <document>
        <entity name="bless" pk="bless_id"
                                query="select * from bless"
                deltaQuery="select bless_id from bless where bless_time > ‘${dataimporter.last_index_time}‘"
                                deltaImportQuery="SELECT * FROM bless where bless_id=‘${dataimporter.delta.bless_id}‘">
            <field column="BLESS_ID" name="blessId" />
            <field column="BLESS_CONTENT" name="blessContent" />
                        <field column="BLESS_TIME" name="blessTime" />
        </entity>
    </document>
</dataConfig>

 

 修改solrconfig.xml

[taozi@localhost conf]$ vim solrconfig.xml

技术分享图片

 <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
      <lst name="defaults">
        <str name="config">data-config.xml</str>
      </lst>
  </requestHandler>

 

复制依赖jar包到solr-webapp/webapp/WEB-INF/lib目录下

[taozi@localhost conf]$ su root
密码:
[root@localhost conf]# cd /opt/solr-7.1.0/dist/
[root@localhost dist]# ll
总用量 8776
-rw-r--r--. 1 root root   18196 10月 14 00:15 solr-analysis-extras-7.1.0.jar
-rw-r--r--. 1 root root  684523 10月 14 00:15 solr-analytics-7.1.0.jar
-rw-r--r--. 1 root root   47384 10月 14 00:15 solr-cell-7.1.0.jar
-rw-r--r--. 1 root root   55085 10月 14 00:15 solr-clustering-7.1.0.jar
-rw-r--r--. 1 root root 5078912 10月 14 00:16 solr-core-7.1.0.jar
-rw-r--r--. 1 root root  227977 10月 14 00:15 solr-dataimporthandler-7.1.0.jar
-rw-r--r--. 1 root root   39192 10月 14 00:15 solr-dataimporthandler-extras-7.1.0.jar
drwxr-xr-x. 2 root root    4096 11月 27 22:14 solrj-lib
-rw-r--r--. 1 root root  769343 10月 14 00:15 solr-langid-7.1.0.jar
-rw-r--r--. 1 root root  117731 10月 14 00:15 solr-ltr-7.1.0.jar
-rw-r--r--. 1 root root 1551422 10月 14 00:16 solr-solrj-7.1.0.jar
-rw-r--r--. 1 root root  297712 10月 14 00:15 solr-test-framework-7.1.0.jar
-rw-r--r--. 1 root root   41049 10月 14 00:15 solr-uima-7.1.0.jar
-rw-r--r--. 1 root root   31907 10月 14 00:15 solr-velocity-7.1.0.jar
drwxr-xr-x. 4 root root      51 11月 27 22:14 test-framework
[root@localhost dist]# cp solr-dataimporthandler-7.1.0.jar solr-dataimporthandler-extras-7.1.0.jar /opt/solr-7.1.0/server/solr-webapp/webapp/WEB-INF/lib/
[root@localhost dist]# cp /mysoft/mysql-connector-java-5.1.37-bin.jar /opt/solr-7.1.0/server/solr-webapp/webapp/WEB-INF/lib/

 

启动服务

[root@localhost dist]# service solr start

 

如果还是没显示data-import的配置信息,那么就重启

[root@localhost bin]# service solr restart
Sending stop command to Solr running on port 8983 ... waiting up to 180 seconds to allow Jetty process 8665 to stop gracefully.
Waiting up to 180 seconds to see Solr running on port 8983 [-]  
Started Solr server on port 8983 (pid=9521). Happy searching!

 

这下有了。

技术分享图片

 

建立Schema

技术分享图片

 

 分别建立你需要的字段

技术分享图片

技术分享图片

技术分享图片

 

执行导入

技术分享图片

 

查看

技术分享图片

 

看似没问题了,但是你如果增量导入,就会出现问题,会有重复数据,因为时区相差八小时。

[root@localhost conf]# cat dataimport.properties 
#Mon Nov 27 15:08:04 UTC 2017
bless.last_index_time=2017-11-27 15\:08\:03
last_index_time=2017-11-27 15\:08\:03

 

解决:【注意:这种方法适用于Linux】

vim /etc/default/solr.in.sh

技术分享图片

重启服务,查看时区

[root@localhost conf]# service solr restart
Sending stop command to Solr running on port 8983 ... waiting up to 180 seconds to allow Jetty process 9521 to stop gracefully.
Waiting up to 180 seconds to see Solr running on port 8983 [-]  
Started Solr server on port 8983 (pid=11615). Happy searching!

[root@localhost conf]# cat dataimport.properties 
#Tue Nov 28 00:08:44 GMT+08:00 2017
bless.last_index_time=2017-11-28 00\:08\:43
last_index_time=2017-11-28 00\:08\:43

 

 

 这样,增量导入没问题了。

 

Solr7.1--- 单机Linux环境搭建

标签:打开   lang   manual   demo   mysq   jdbc   zone   tty   mysql   

原文地址:http://www.cnblogs.com/LUA123/p/7906774.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!