操做系統:LINUX CENTOS 6.7java
solr安裝目錄:/usr/local/solr-6.1.0mysql
一、準備工做:
1.一、建立數據表:sql
CREATE TABLE `mytable` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(25) NOT NULL, `desc` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; insert into `mytable`(`id`,`name`,`desc`) values (1,'NAME11','DESC11,DESC11'); insert into `mytable`(`id`,`name`,`desc`) values (2,'NAME22','DESC22,DESC22'); insert into `mytable`(`id`,`name`,`desc`) values (3,'NAME33','DESC33,DESC33'); insert into `mytable`(`id`,`name`,`desc`) values (4,'NAME44','DESC44,DESC44');
1.二、下載須要的jar包:
mysql-connector-java-5.1.7-bin.jar 複製到 /usr/local/solr-6.1.0/dist/目錄下。apache
二、啓動solr&建立新核new_corevim
[root@localhost solr-6.1.0]# ./bin/solr start [root@localhost solr-6.1.0]# ./bin/solr create_core new_core
三、配置solrconfig.xml文件,增長以下內容:ui
[root@localhost conf]# vim solrconfig.xml
3.一、加載須要的jar包,大概在75行左右:url
<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-dataimporthandler-\d.*\.jar" /> <lib dir="${solr.install.dir:../../../..}/dist/" regex="mysql-connector-java-5.1.7-bin.jar" />/*本身下載*/ 3.二、加載導入數據監聽代碼,大概在745行左右: <requestHandler name="/dataimport" class="solr.DataImportHandler"> <lst name="defaults"> <str name="config">new_core-data-config.xml</str> </lst> </requestHandler>
四、生成/配置new_core-data-config.xml文件操作系統
[root@localhost conf]# cp /usr/local/solr-6.1.0/example/example-DIH/solr/db/conf/db-data-config.xml ./new_core-data-config.xml [root@localhost conf]# vim new_core-data-config.xml
增長以下內容,保存退出:調試
<dataConfig> <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/test" user="root" password=""/> <document> <entity name="mytable" query="select id,`name`,`desc` from mytable"> <field column="id" name="id"/> <field column="name" name="name"/> <field column="desc" name="desc"/> </entity> </document> </dataConfig>
注:瞭解更多data-config.xml配置信息地址:https://wiki.apache.org/solr/DIHQuickStart
五、重啓solr服務,不然配置不生效。rest
[root@localhost conf]# /usr/local/solr-6.1.0/bin/solr restart
六、訪問solr自帶的UI地址運行導入操做
http://localhost:8983/solr/#/new_core/dataimport//dataimport
七、若是UI頂部顯示錯誤提示(紅框),能夠訪問solr日誌作針對性調試。
http://localhost:8983/solr/#/~logging