Solr7.1--- 單機Linux環境搭建


應網友的要求,寫個關於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

 

 

 這樣,增量導入沒問題了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM