應網友的要求,寫個關於Linux單機的java
首先,把MySQL驅動包和solr7.1安裝包上傳到服務器,我上傳到了自定義的目錄/mysoftmysql
1. 先切換到root用戶web
2. 解壓出腳本sql
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!
打開前臺:apache
注意要切換到普通用戶json
[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'
查看界面vim
人家說沒有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.
[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
[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>
[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
這樣,增量導入沒問題了。