solr两种安装、ik分词器设置、DIH导入mysql数据
文章目录
- solr 安装(内置方式)
- solr 安装(tomcat方式)
- IK中文分词器设置
- solr数据操作
- 使用dataimport导入数据库数据
solr 安装(内置方式)
安装包
官网下载安装包,官网地址:https://lucene.apache.org/solr/downloads.html
使用命令获取:
[root@10 ss]# wget https://mirror.bit.edu.cn/apache/lucene/solr/7.7.3/solr-7.7.3.tgz
解压
[root@10 solr]# tar xvf solr-7.7.3.tgz
启动
[root@10 bin]# pwd /root/solr/solr-7.7.3/bin [root@10 bin]# ./solr start -force *** [WARN] *** Your open file limit is currently 1024. It should be set to 65000 to avoid operational disruption. If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh *** [WARN] *** Your Max Processes Limit is currently 7283. It should be set to 65000 to avoid operational disruption. If you no longer wish to see this warning, set SOLR_ULIMIT_CHECKS to false in your profile or solr.in.sh Waiting up to 180 seconds to see Solr running on port 8983 [\] [root@10 bin]#
浏览器访问
http://192.168.0.101:8983
配置solr_core
在/server/solr目录下建立一个文件夹,此处叫laosan_core
复制文件到该目录下
[root@10 solr]# pwd /root/solr/solr-7.7.3/server/solr [root@10 solr]# cp /root/solr/solr-7.7.3/server/solr/configsets/_default/conf -rf laosan_core
修改managed-schema为schema.xml
[root@10 conf]# pwd /root/solr/solr-7.7.3/server/solr/laosan_core/conf [root@10 conf]# ll 总用量 132 drwxr-xr-x. 2 root root 4096 9月 11 22:19 lang -rw-r--r--. 1 root root 54513 9月 11 22:19 managed-schema -rw-r--r--. 1 root root 308 9月 11 22:19 params.json -rw-r--r--. 1 root root 873 9月 11 22:19 protwords.txt -rw-r--r--. 1 root root 53346 9月 11 22:19 solrconfig.xml -rw-r--r--. 1 root root 781 9月 11 22:19 stopwords.txt -rw-r--r--. 1 root root 1124 9月 11 22:19 synonyms.txt [root@10 conf]# mv managed-schema schema.xml [root@10 conf]# ll 总用量 132 drwxr-xr-x. 2 root root 4096 9月 11 22:19 lang -rw-r--r--. 1 root root 308 9月 11 22:19 params.json -rw-r--r--. 1 root root 873 9月 11 22:19 protwords.txt -rw-r--r--. 1 root root 54513 9月 11 22:19 schema.xml -rw-r--r--. 1 root root 53346 9月 11 22:19 solrconfig.xml -rw-r--r--. 1 root root 781 9月 11 22:19 stopwords.txt -rw-r--r--. 1 root root 1124 9月 11 22:19 synonyms.txt
页面Add Core
添加成功后显示
solr 安装(tomcat方式)
解压tomcat
[root@10 solr]# unzip apache-tomcat-8.0.52-windows-x64.zip Archive: apache-tomcat-8.0.52-windows-x64.zipcreating: apache-tomcat-8.0.52/
移动solr中webapp到tomcat中webapp下
[root@10 solr-webapp]# pwd /root/solr/solr-7.7.3/server/solr-webapp [root@10 solr-webapp]# cp -r webapp/ /root/solr/apache-tomcat-8.0.52/webapps
将应用名改为solr
[root@10 webapps]# pwd /root/solr/apache-tomcat-8.0.52/webapps [root@10 webapps]# mv webapp/ solr [root@10 webapps]# ll 总用量 12 drwxr-xr-x. 14 root root 4096 4月 28 2018 docs drwxr-xr-x. 6 root root 78 4月 28 2018 examples drwxr-xr-x. 5 root root 82 4月 28 2018 host-manager drwxr-xr-x. 5 root root 97 4月 28 2018 manager drwxr-xr-x. 3 root root 4096 4月 28 2018 ROOT drwxr-xr-x. 8 root root 4096 9月 11 22:44 solr
复制所需依赖jar包
- 复制ext目录下jar包
[root@10 lib]# pwd /root/solr/solr-7.7.3/server/lib [root@10 lib]# cp ext/* /root/solr/apache-tomcat-8.0.52/webapps/solr/WEB-INF/lib/ cp:是否覆盖"/root/solr/apache-tomcat-8.0.52/webapps/solr/WEB-INF/lib/disruptor-3.4.0.jar"? y [root@10 lib]#
- 复制有metrics-开头的jar包
[root@10 lib]# cp metrics-* /root/solr/apache-tomcat-8.0.52/webapps/solr/WEB-INF/lib/
配置solrhome
用于存储Solr Core的数据及配置文件
创建solrhome存储Solr索引文件,创建哪里都可以
[root@10 lib]# mkdir -p /usr/local/solr/solrhome
复制server/solr目录下所有内容到solrhome
[root@10 solr]# pwd /root/solr/solr-7.7.3/server/solr [root@10 solr]# cp -r * /usr/local/solr/solrhome/
配置tomcat
修改web.xml,修改solr_home路径指向我们刚刚创建的 solrhome
[root@10 WEB-INF]# pwd /root/solr/apache-tomcat-8.0.52/webapps/solr/WEB-INF [root@10 WEB-INF]# vim web.xml
<!-- 修改solrhome路径 --> <env-entry><env-entry-name>solr/home</env-entry-name><env-entry-value>/usr/local/solr/solrhome</env-entry-value><env-entry-type>java.lang.String</env-entry-type> </env-entry>
去掉安全认证
<!-- Get rid of error message <security-constraint><web-resource-collection><web-resource-name>Disable TRACE</web-resource-name><url-pattern>/</url-pattern><http-method>TRACE</http-method></web-resource-collection><auth-constraint/></security-constraint><security-constraint><web-resource-collection><web-resource-name>Enable everything but TRACE</web-resource-name><url-pattern>/</url-pattern><http-method-omission>TRACE</http-method-omission></web-resource-collection></security-constraint> -->
修改tomcat中bin目录权限
[root@10 apache-tomcat-8.0.52]# pwd /root/solr/apache-tomcat-8.0.52 [root@10 apache-tomcat-8.0.52]# chmod 777 -R bin/
配置solr_core
在/server/solr目录下建立一个文件夹,此处叫laosan_core
复制文件到该solrhome目录下
[root@10 solr]# pwd /usr/local/solr/solrhome [root@10 solr]# cp /root/solr/solr-7.7.3/server/solr/configsets/_default/conf -rf laosan_core
修改managed-schema为schema.xml
[root@10 conf]# pwd /usr/local/solr/solrhome/laosan_core/conf [root@10 conf]# ll 总用量 132 drwxr-xr-x. 2 root root 4096 9月 11 22:19 lang -rw-r--r--. 1 root root 54513 9月 11 22:19 managed-schema -rw-r--r--. 1 root root 308 9月 11 22:19 params.json -rw-r--r--. 1 root root 873 9月 11 22:19 protwords.txt -rw-r--r--. 1 root root 53346 9月 11 22:19 solrconfig.xml -rw-r--r--. 1 root root 781 9月 11 22:19 stopwords.txt -rw-r--r--. 1 root root 1124 9月 11 22:19 synonyms.txt [root@10 conf]# mv managed-schema schema.xml [root@10 conf]# ll 总用量 132 drwxr-xr-x. 2 root root 4096 9月 11 22:19 lang -rw-r--r--. 1 root root 308 9月 11 22:19 params.json -rw-r--r--. 1 root root 873 9月 11 22:19 protwords.txt -rw-r--r--. 1 root root 54513 9月 11 22:19 schema.xml -rw-r--r--. 1 root root 53346 9月 11 22:19 solrconfig.xml -rw-r--r--. 1 root root 781 9月 11 22:19 stopwords.txt -rw-r--r--. 1 root root 1124 9月 11 22:19 synonyms.txt
启动tomcat后add core
http://192.168.0.101:8080/solr/index.html#/
IK中文分词器设置
下载solr7版本的ik分词器
- 下载地址:http://search.maven.org/#search%7Cga%7C1%7Ccom.github.magese
- GitHub源码地址:https://github.com/magese/ik-analyzer-solr7
将jar包拷贝到tomcat中lib目录下:
[root@10 lib]# pwd /root/solr/apache-tomcat-8.0.52/webapps/solr/WEB-INF/lib [root@10 lib]# rz -E rz waiting to receive.
修改managed-schema文件,增加ik分词器
<!-- ik分词器 --> <fieldType name="text_ik" class="solr.TextField"> <analyzer type="index"> <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="false" conf="ik.conf"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> <analyzer type="query"> <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="true" conf="ik.conf"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> </fieldType>
重启tomcat
页面测试
solr数据操作
使用Solr的DIH将mysql中的数据导入到Solr中
使用dataimport导入数据库数据
复制3个jar包到tomcat/webapp/solr/WEB-INF/lib/下
- solr-dataimporthandler-extras-7.7.3.jar
- solr-dataimporthandler-7.7.3.jar
- mysql-connector-java-5.1.47.jar
上传sql脚本到服务器并在机器执行
上传sql脚本到此目录
当前目录进入mysql,执行脚本
[root@10 mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.28 MySQL Community Server (GPL) Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> source create_table.sql Query OK, 0 rows affected (0.00 sec)
solrhome/laosan_core/conf/下创建文件data-config.xml
[root@10 conf]# pwd /usr/local/solr/solrhome/laosan_core/conf
<dataConfig> <!-- 这是mysql的配置 --> <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://192.168.0.112:3306/laosan" user="root" password="root"/> <document> <!-- query是一条sql,代表在数据库查找出来的数据 --> <entity name="position" query="select * from position"> <!-- 每一个field映射着数据库中列与文档中的域,column是数据库列,name是 solr的域(必须是在managed-schema文件中配置过的域才行) --> <field column="companyName" name="companyName"/> <field column="id" name="id"/> <field column="type" name="type"/> <field column="prolong_offline_time"/> </entity> </document> </dataConfig>
修改solrconfig.xml配置文件增加以下内容(678行)
[root@10 conf]# pwd /usr/local/solr/solrhome/laosan_core/conf [root@10 laosan_core]# vim solrconfig.xml
<requestHandler name="/dataimport" class="solr.DataImportHandler"> <lst name="defaults"> <str name="config">data-config.xml</str> </lst> </requestHandler>
在managed-schema 配置对应的域(453行)
[root@10 conf]# pwd /usr/local/solr/solrhome/laosan_core/conf
<field name="companyName" type="text_ik" indexed="true" stored="true"/> <field name="positionName" type="text_ik" indexed="true" stored="true"/> <field name="positionAdvantage" type="text_ik" indexed="true" stored="true"/> <field name="salary" type="text_ik" indexed="true" stored="true"/> <field name="workYear" type="text_ik" indexed="true" stored="true"/>
页面导入数据
查询数据
solr两种安装、ik分词器设置、DIH导入mysql数据相关推荐
- 2021年大数据ELK(八):Elasticsearch安装IK分词器插件
全网最详细的大数据ELK文章系列,强烈建议收藏加关注! 新文章都已经列出历史文章目录,帮助大家回顾前面的知识重点. 目录 系列历史文章 安装IK分词器 一.下载Elasticsearch IK分词器 ...
- 【javaWeb微服务架构项目——乐优商城day07】——Elasticsearch介绍和安装及使用(安装kibana,安装ik分词器,Spring Data Elasticsearch,高级查询)
文章目录 0.学习目标 1.Elasticsearch介绍和安装 1.1.简介 1.1.1.Elastic 1.1.2.Elasticsearch 1.1.3.版本 1.2.安装和配置 1.2.1.新 ...
- Elasticsearch安装IK分词器,kibana安装是基本使用,DSL语句入门
文章目录 1. 安装IK分词器 2. Kibana安装和使用 2.1 ELK概述 2.2 Kibana下载 2.3 DSL语句 1. 安装IK分词器 ElasticSearch 默认采用的分词器, 是 ...
- Elasticsearch下安装ik分词器
安装ik分词器(必须安装maven) 上传相应jar包 解压到相应目录 unzip elasticsearch-analysis-ik-master.zip(zip包) cp -r elasticse ...
- Elasticsearch中安装IK分词器
Elasticsearch中默认的分词器对中文的支持不好,会分隔成一个一个的汉字.而IK分词器对中文的支持比较好一些,主要有两种模式"ik_smart"和"ik_max_ ...
- Elasticsearch入门之从零开始安装ik分词器
起因 需要在ES中使用聚合进行统计分析,但是聚合字段值为中文,ES的默认分词器对于中文支持非常不友好:会把完整的中文词语拆分为一系列独立的汉字进行聚合,显然这并不是我的初衷.我们来看个实例: POST ...
- 分布式系列教程(34) -Linux下安装ik分词器
1.引言 因为Elasticsearch中默认的标准分词器分词器对中文分词不是很友好,会将中文词语拆分成一个一个中文的汉字,因此引入中文分词器-es-ik插件. 例如使用传统的分词器,可以看到把中文分 ...
- elasticsearch安装ik分词器
elasticsearch安装ik分词器 1. 修改docker-compose.yml文件,对es目录下的plugins文件夹进行文件映射 version: "2.2" volu ...
- Linux下安装ik分词器
Linux下安装ik分词器 首先下载ik分词器 下载地址: https://github.com/medcl/elasticsearch-analysis-ik/releases 一定要点进来 下载z ...
最新文章
- centos6.4安装java,CentOS6.4下YUM安装MySQL和JDK和Tomcat
- 研究能力培养的阶梯: 盐趣一对一科研项目
- VS2017 Pro未能找到路径“……\bin\roslyn\csc.exe”的解决方案
- 数字化时代的创新意欲何为?
- /usr/local/php-5.2.14/sbin/php-fpm start Starting php_fpm –fpm-config
- 【OpenKruise v0.9.0】新增 Pod 重启、删除防护等重磅功能
- Linux 修改IP及虚拟网卡配置详解
- 第一次冲刺-站立会议03
- 通过json动态创建控制器
- 手机浏览器怎么查看html,手机浏览器网页收藏在哪里查看
- 高中数学怎么学好我的数学学习方法
- html模板怎样做seo,SEO如何做分享模板做外链
- 《团》里男人是否可嫁的汉?
- 必会算法总结5—弗洛伊德算法
- 【Simulink+Prescan笔记】控件介绍
- pomelo客户端开发
- Windows系统ping不通同网段主机解决方法
- 猿如意中的【格式工厂】工具的安装与使用教程,格式转换这个工具就够了
- steam下载地址,千万别搞错!
- win10系统谷歌浏览器实现鼠标滚轮切换标签
热门文章
- 编译PX4时,报错error ‘i‘ does not name a type __ULong i[2];解决方法
- 动态规划-最少硬币组合问题(Java)
- 海外区块链投融资持续火热 | 产业区块链发展周报
- java map 参数传递_Java参数传递分析
- 【TransMEF】
- ctf【ciscn_2019_s_3】
- SPU ITEM SKU
- iOS release版本
- 在线JSON转XML工具
- 使用Python将OV7725的RGB565图像数据转换为jpg图像