solr 官网:http://lucene.apache.org/solr
下载地址:http://archive.apache.org/dist/lucene/solr/4.10.4/solr-4.10.4.tgz
安装JDK
yum install java-1.8.0-openjdk -y
查看JDK版本
[root@localhost ~]# java -version openjdk version "1.8.0_171" OpenJDK Runtime Environment (build 1.8.0_171-b10) OpenJDK 64-Bit Server VM (build 25.171-b10, mixed mode)
安装tomcat7
yum install -y tomcat
查看tomcat版本
[root@localhost ~]# tomcat version Server version: Apache Tomcat/7.0.76 Server built: Apr 11 2018 03:37:53 UTC Server number: 7.0.76.0 OS Name: Linux OS Version: 3.10.0-514.16.1.el7.x86_64 Architecture: amd64 JVM Version: 1.8.0_171-b10 JVM Vendor: Oracle Corporation
配置solr
1.下载并解压solr,我是下载到了root目录
wget http://archive.apache.org/dist/lucene/solr/4.10.4/solr-4.10.4.tgz tar -xzf solr-4.10.4.tgz
2.将解压目录/root/solr-4.10.4/example/webapps下的solr.war复制到tomcat/webapps/目录下,通过启动tomcat解压solr.war后,关闭tomcat,删除solr.war
cp /root/solr-4.10.4/example/webapps/solr.war /var/lib/tomcat/webapps/ service tomcat start service tomcat stop rm -f /var/lib/tomcat/webapps/solr.war
3.将解压目录/root/solr-4.10.4/example/lib/ext/下的所有jar包复制到tomcat/webapps/solr/WEB-INF/lib/目录下
cp /root/solr-4.10.4/example/lib/ext/* /var/lib/tomcat/webapps/solr/WEB-INF/lib/
4.将解压目录/root/solr-4.10.4/example/solr复制到/home/目录下
cp /root/solr-4.10.4/example/solr /home/ -R chown tomcat:tomcat /home/solr -R
5.修改tomcat/webapps/solr/WEB-INF/下的web.xml文件
vim /var/lib/tomcat/webapps/solr/WEB-INF/web.xml
去掉下面配置的注释,将<env-entry-value>中的内容改成上一步solr的路径
<env-entry> <env-entry-name>solr/home</env-entry-name> <env-entry-value>/home/solr</env-entry-value> <env-entry-type>java.lang.String</env-entry-type> </env-entry>
6.启动tomcat,在浏览器输入http://IP:8080/solr即可出现Solr的管理界面
service tomcat start
导入数据库数据
1.配置/home/solr/collection1/conf/solrconfig.xml
<!-- 添加数据库导入功能 --> <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">data-config.xml</str> </lst> </requestHandler>
2.将解压目录/root/solr-4.10.4/dist下的solr-dataimporthandler-*复制到tomcat/webapps/solr/WEB-INF/lib/目录下
cp /root/solr-4.10.4/dist/solr-dataimporthandler-* /var/lib/tomcat/webapps/solr/WEB-INF/lib/
3.下载mysql数据库驱动包mysql-connector-java-5.1.37.jar到/var/lib/tomcat/webapps/solr/WEB-INF/lib/
cd /var/lib/tomcat/webapps/solr/WEB-INF/lib/ wget http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.37/mysql-connector-java-5.1.37.jar
4.配置/home/solr/collection1/conf/data-config.xml
<dataConfig> <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/db_name" user="username" password="password"/> <document> <entity name="product" query="SELECT s_id, s_product_id, s_product_category_id, s_product_image, s_product_status, s_product_warehouse, s_product_create_time, s_product_attr, s_product_price, s_product_rating, s_product_title, s_product_keyword, s_product_special_price, s_product_category, s_product_review_count, s_product_discount, s_product_lang, s_modify_time FROM solr_product_data WHERE 1"> <field name="id" column="s_id" /> <field name="s_product_id" column="s_product_id" /> <field name="idx_product_category_id" column="s_product_category_id" /> <field name="s_product_image" column="s_product_image"/> <field name="s_product_satus" column="s_product_satus"/> <field name="idx_product_create_time" column="s_product_create_time"/> <field name="s_product_attr" column="s_product_attr"/> <field name="idx_product_price" column="s_product_price"/> <field name="idx_product_rating" column="s_product_rating"/> <field name="idx_product_title" column="s_product_title"/> <field name="idx_product_keyword" column="s_product_keyword"/> <field name="s_product_special_price" column="s_product_special_price"/> <field name="s_product_category" column="s_product_category"/> <field name="s_product_review_count" column="s_product_review_count"/> <field name="s_product_discount" column="s_product_discount"/> <field name="idx_product_lang" column="s_product_lang"/> <field name="s_product_warehouse" column="s_product_warehouse"/> </entity> </document> </dataConfig>
5.修改schema.xml,添加与数据库字段对应索引,这是Solr对数据库里的数据进行索引的模式
<field name="s_product_id" type="int" indexed="true" stored="true" multiValued="false"/> <field name="idx_product_category_id" type="int" indexed="true" stored="true" multiValued="false"/> <field name="s_product_image" type="string" indexed="false" stored="true" multiValued="false"/> <field name="s_product_attr" type="string" indexed="false" stored="true" multiValued="false"/> <field name="s_product_status" type="string" indexed="true" stored="true" multiValued="false"/> <field name="idx_product_create_time" type="string" indexed="true" stored="true" multiValued="false"/> <field name="idx_product_price" type="tfloat" indexed="true" stored="true" multiValued="false"/> <field name="idx_product_rating" type="int" indexed="true" stored="true" multiValued="false"/> <field name="idx_product_title" type="text_general" indexed="true" stored="true" multiValued="false"/> <field name="idx_product_keyword" type="string" indexed="true" stored="true" multiValued="false"/> <field name="s_product_special_price" type="string" indexed="true" stored="true" multiValued="false"/> <field name="s_product_category" type="string" indexed="false" stored="true" multiValued="false"/> <field name="s_product_review_count" type="string" indexed="true" stored="true" multiValued="false"/> <field name="s_product_discount" type="string" indexed="true" stored="true" multiValued="false"/> <field name="idx_product_lang" type="int" indexed="true" stored="true"/> <field name="s_product_warehouse" type="string" indexed="true" stored="true" multiValued="false" default="null"/>
6.重启tomcat,点击Execute执行导入
点击Refresh Status查看结果
导入完成
本文链接:https://jeff.xin/post/103.html
--EOF--
发表于 2018-07-16 ,并被添加「 Solr 」标签 。
Comments
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。