因为工作需要,我准备在win7 x64系统上基于springboot +elasticsearch+redis搭建全文索引服务器。

1. elasticsearch安装比较方便,直接去官网下载了elasticsearch 6.2.4 的msi安装包,安装过程中配置集群信息,并将路径添加到环境变量,同时将elasticsearch添加到系统服务中。这个都是在安装过程中配置的。顺便还有data目录,conf目录,logs目录等。我把elasticsearch安装到C盘,而将data目录等3个目录放到了H盘。

为了保证能识别127.0.0.1是localhost,要保证hosts文件中有一行为:

127.0.0.1 localhost

下面直接贴配置信息:

# elasticsearch.yml
bootstrap.memory_lock: false
cluster.name: oldkingESCluster
http.port: 9200
network.host: 127.0.0.1
node.data: true
node.ingest: true
node.master: true
node.max_local_storage_nodes: 1
node.name: okT400
path.data: H:\ElasticSearch\data
path.logs: H:\ElasticSearch\logs
transport.tcp.port: 9300
#jvm.options
-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly
-XX:+AlwaysPreTouch
-Xss1m
-Djava.awt.headless=true
-Dfile.encoding=UTF-8
-Djna.nosys=true
-XX:-OmitStackTraceInFastThrow
-Dio.netty.noUnsafe=true
-Dio.netty.noKeySetOptimization=true
-Dio.netty.recycler.maxCapacityPerThread=0
-Dlog4j.shutdownHookEnabled=false
-Dlog4j2.disable.jmx=true
-Djava.io.tmpdir=${ES_TMPDIR}
-XX:+HeapDumpOnOutOfMemoryError
-Xmx1024m
-Xms1024m

直接去安装路径启动elasticsearch即可。

至于elasticsearch-head插件,可以去elasticsearch-head的GitHub上看它的readme。可以直接从chrome的商店里面找到head插件,直接安装就可以啦。

启动elasticsearch后,点chrome上的head插件,发现elasticsearch启动了:

elasticsearch-head插件的作用基本就是elasticsearch的管理,平时也基本用不上。

注意:elasticsearch安装过程中会推荐一堆插件,看着挺有用的,但是你无法选中,选中就会出现无法联网的情况,所以我最后都没有安装它推荐的那些插件,包括x-package和其他的。

2. 安装redis

直接去GitHub上下载redis的msi版安装。

安装比较简单,一路就下去了,其余的就是配置。

(1)配置redis.window.conf

maxmemory 1024000000
requirepass redis
#一定要顶头写

(2)添加到系统服务中:redis-server.exe redis.windows.conf

(3)出错解决方法

Redis第一次启动报错:

[2368] 21 Apr 02:57:05.611 # Creating Server TCP listening socket 127.0.0.1:6379: bind: No error

解决方法:在命令行中运行

redis-cli.exe

127.0.0.1:6379>shutdown

not connected>exit

然后重新运行redis-server.exe redis.windows.conf,启动成功!

添加系统服务错误:

[12820] 06 Sep 11:00:26.431 # HandleServiceCommands: system error caught. error code=1073, message = CreateService failed: unknown error

原因:系统服务中已经存在
解决办法:
1)先卸载服务:
redis-server --service-uninstall
2)然后再安装:
redis-server--service-install redis.windows.conf
启停:
启动服务:redis-server --service-start
停止服务:redis-server --service-stop

3. 查看redis中的数据

下载青格软件的TreeNMS来管理redis,这里我给出csdn的下载链接。

登录后,点击右上角“参数配置”按钮,新增或修改连接参数,我们这里要添加密码(因为我们设置了redis的密码)测试连接成功后,保存参数并刷新页面即可。

4. 编译爬取IT之家的热评的代码

这个源码,我会给出csdn上的下载链接。

这个工程还依赖mysql,所以需要安装mysql并设置密码,这里设置的用户名密码是root和mysql。如果设置成其他的,可以在工程中修改。

除此之外,我们贴出配置文件,这里主要是elasticsearch和redis的配置:

#application.yml
#端口号
server:port: 8081spring:data:##elasticsearch配置elasticsearch:cluster-name: oldkingESClustercluster-nodes: localhost:9300##redis配置redis:database: 0host: localhostport: 6379password: redispool:max-active: 15max-wait: 1max-idle: 0timeout: 0##freemarker配置freemarker:##是否允许属性覆盖allow-request-override: falseallow-session-override: falsecache: truecheck-template-location: truecontent-type: text/html##暴露request属性expose-request-attributes: falseexpose-session-attributes: falseexpose-spring-macro-helpers: falsesuffix: .ftltemplate-loader-path: classpath:/templates/request-context-attribute: requestsettings:classic_compatible: truelocale: zh_CNdate_format: yyyy-MM-ddtime_format: HH:mm:ssdatetime_format: yyyy-MM-dd HH:mm:ss

编译之后会报错:

(1)Spring连接Elasticsearch报错:org.elasticsearch.transport.NodeDisconnectedException: [][127.0.0.1:9300][cluster:monitor/nodes/liveness] disconnected

这个错误是由于elasticsearch版本过高造成的,查看你的Elasticsearch安装目录的logs下的日志.

java.lang.IllegalStateException: Received message from unsupported version: [2.0.0] minimal compatible version is: [5.6.0]

从不支持的版本接收消息:[2.0.0]最小兼容版本是:[5.6.0]

低版本jar包的不支持高版本的Elasticsearch

这里是什么版本建议使用什么版本的Elasticsearch。

装上elasticsearch-2.1.0 解决。

我们曾尝试按照文章《spring boot集成elasticsearch6.1版本》和《spring boot elasticsearch 5.x/6.x版本整合详解》升级org.springframework.boot的版本到2.0.1,但是编译出了更多的错误,这是因为里面调用的接口发生变化造成的。所以我们还是老老实实的安装低版本的Elasticsearch算了。

另外,https://blog.csdn.net/weixin_36380516/article/details/78482167也说明了Spring boot和spring-data-elasticsearch以及elasticsearch之间有严格的版本对应关系。

有的地方写着:Spring Boot Version (x) Spring Data Elasticsearch Version (y) Elasticsearch Version (z)
x <= 1.3.5 y <= 1.3.4 z <= 1.7.2* x >= 1.4.x 2.0.0 <=y < 5.0.0** 2.0.0 <= z < 5.0.0**
* - 只需要你修改下对应的 pom 文件版本号

我们这里是spring-boot-1.5.6.RELEASE和spring-data-elasticsearch-2.1.6.RELEASE,我们卸载安装的elasticsearch 6.2.4版本,试试安装2.4.6版本。这个是没有msi的哦。

5. 重新安装elasticsearch 2.4.6

配置2.4.6可以参考:https://www.cnblogs.com/ljhdo/p/4887557.html

下载2.4.6太费劲了。下载完解压缩,然后安装head插件,然后将elasticsearch添加到系统服务中。

安装完head插件后,可以通过网页管理ElasticSearch

启动elasticsearch服务,然后在本地浏览器中输入http://localhost:9200/_plugin/head/,如果看到以下截图,说明head插件安装成功。

6. 编译工程ithomecrawler

由于是下载别人的程序,原来IThome的评论页面都是json格式,而目前完全没了格式,所以没法使用jsoup。我们要保存的数据内容如下:

    private Long id;//热评编号private String commentId;private String user;//用户private String comment;//内容private int up;//支持数private int down;//反对数private String posandtime;//位置和时间private String mobile;//设备private String articleUrl;//源文章地址

如果采用json返回类型,那么解析出上面的数据结构相当简单,然而,下面给出一个评论页面的内容(只有两条评论):

{"html":"\u003cli class=\"entry\" cid=\"32767350\" nid=\"356518\"\u003e\u003cdiv class=\"adiv\"\u003e\u003cdiv\u003e\u003ca title=\"软媒通行证数字ID:1114977\" target=\"_blank\" href=\"http://quan.ithome.com/user/1114977\"\u003e\u003cimg class=\"headerimage\" οnerrοr=\"this.src=\u0027//img.ithome.com/images/v2.1/noavatar.png\u0027\" src=\"//avatar.ithome.com/avatars/001/11/49/77_60.jpg\"/\u003e\u003c/a\u003e\u003c/div\u003e\u003cdiv class=\"level\"\u003e\u003cspan\u003eLv.24\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv\u003e\u003cdiv class=\"info rmp\"\u003e\u003cstrong class=\"p_floor\"\u003e72楼2#\u003c/strong\u003e\u003cdiv class=\"nmp\"\u003e\u003cspan class=\"nick\"\u003e\u003ca title=\"软媒通行证数字ID:1114977\" target=\"_blank\" href=\"http://quan.ithome.com/user/1114977\"\u003e在拾荒时捡到的\u003c/a\u003e\u003c/span\u003e\u003cspan class=\"mobile iphone\"\u003e\u003ca target=\"_blank\" title=\"App版本:v6.03\" href=\"//m.ithome.com/ithome/download/\"\u003eiPhone 6s 银\u003c/a\u003e\u003c/span\u003e\u003cspan class=\"posandtime\"\u003eIT之家甘肃兰州网友\u0026nbsp;2018-4-22 20:57:21\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cp\u003eov:告辞告辞,没想到是魅族技高一筹,甘拜下风,下一代机型见\u003c/p\u003e\u003cdiv class=\"zhiChi\"\u003e\u003cdiv class=\"l\"\u003e\u003cspan class=\"comm_reply\"\u003e\u003ca class=\"comment_co\"\u003e展开(21)\u003cimg src=\"//img.ithome.com/images/v2.3/arrow.png\"\u003e\u003c/a\u003e\u003c/span\u003e\u003c/div\u003e \u003cdiv class=\"r\"\u003e\u003cspan class=\"comm_reply\"\u003e\u003ca class=\"s\" id=\"hotagree32767852\" href=\"javascript:hotCommentVote(32767852,1)\"\u003e支持(72)\u003c/a\u003e\u003ca class=\"a\" id=\"hotagainst32767852\" href=\"javascript:hotCommentVote(32767852,2)\"\u003e反对(0)\u003c/a\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/li\u003e\u003cli class=\"entry\" cid=\"32767546\" nid=\"356518\"\u003e\u003cdiv class=\"adiv\"\u003e\u003cdiv\u003e\u003ca title=\"软媒通行证数字ID:1565223\" target=\"_blank\" href=\"http://quan.ithome.com/user/1565223\"\u003e\u003cimg class=\"headerimage\" οnerrοr=\"this.src=\u0027//img.ithome.com/images/v2.1/noavatar.png\u0027\" src=\"//avatar.ithome.com/avatars/001/56/52/23_60.jpg\"/\u003e\u003c/a\u003e\u003c/div\u003e\u003cdiv class=\"level\"\u003e\u003cspan\u003eLv.18\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv\u003e\u003cdiv class=\"info rmp\"\u003e\u003cstrong class=\"p_floor\"\u003e99楼6#\u003c/strong\u003e\u003cdiv class=\"nmp\"\u003e\u003cspan class=\"nick\"\u003e\u003ca title=\"软媒通行证数字ID:1565223\" target=\"_blank\" href=\"http://quan.ithome.com/user/1565223\"\u003e死星\u003c/a\u003e\u003c/span\u003e\u003cspan class=\"mobile android\"\u003e\u003ca target=\"_blank\" title=\"App版本:v6.02\" href=\"//m.ithome.com/ithome/download/\"\u003e华为 Mate RS 保时捷设计\u003c/a\u003e\u003c/span\u003e\u003cspan class=\"posandtime\"\u003eIT之家四川成都网友\u0026nbsp;2018-4-22 20:57:14\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cp\u003e白色15我肯定要入一部的\u003cbr\u003e颜值高(仅限白色)\u003cbr\u003e线性马达\u003cbr\u003e手感好\u003cbr\u003e24w快充保障\u003cbr\u003e够用性能+够用拍照\u003cbr\u003e\u003cbr\u003e\u003c/p\u003e\u003cdiv class=\"zhiChi\"\u003e\u003cdiv class=\"l\"\u003e\u003cspan class=\"comm_reply\"\u003e\u003ca class=\"comment_co\"\u003e展开(130)\u003cimg src=\"//img.ithome.com/images/v2.3/arrow.png\"\u003e\u003c/a\u003e\u003c/span\u003e\u003c/div\u003e \u003cdiv class=\"r\"\u003e\u003cspan class=\"comm_reply\"\u003e\u003ca class=\"s\" id=\"hotagree32767844\" href=\"javascript:hotCommentVote(32767844,1)\"\u003e支持(54)\u003c/a\u003e\u003ca class=\"a\" id=\"hotagainst32767844\" href=\"javascript:hotCommentVote(32767844,2)\"\u003e反对(1)\u003c/a\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/li\u003e\u003cli class=\"entry\" cid=\"32767350\" nid=\"356518\"\u003e\u003cdiv class=\"adiv\"\u003e\u003cdiv\u003e\u003ca title=\"软媒通行证数字ID:1197300\" target=\"_blank\" href=\"http://quan.ithome.com/user/1197300\"\u003e\u003cimg class=\"headerimage\" οnerrοr=\"this.src=\u0027//img.ithome.com/images/v2.1/noavatar.png\u0027\" src=\"//avatar.ithome.com/avatars/001/19/73/00_60.jpg\"/\u003e\u003c/a\u003e\u003c/div\u003e\u003cdiv class=\"level\"\u003e\u003cspan\u003eLv.28\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv\u003e\u003cdiv class=\"info rmp\"\u003e\u003cstrong class=\"p_floor\"\u003e72楼7#\u003c/strong\u003e\u003cdiv class=\"nmp\"\u003e\u003cspan class=\"nick\"\u003e\u003ca title=\"软媒通行证数字ID:1197300\" target=\"_blank\" href=\"http://quan.ithome.com/user/1197300\"\u003e雷檬猴啊\u003c/a\u003e\u003c/span\u003e\u003cspan class=\"mobile iphone\"\u003e\u003ca target=\"_blank\" title=\"App版本:v6.02\" href=\"//m.ithome.com/ithome/download/\"\u003eiPhone 7 Plus 亮黑\u003c/a\u003e\u003c/span\u003e\u003cspan class=\"posandtime\"\u003eIT之家湖北网友\u0026nbsp;2018-4-22 21:10:02\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cp\u003e鸡王:扫视一圈友商把苹果能抄的都抄了个遍,就差带震动回馈的home键还没人抄了,这波我来捡个漏

win7 x64 基于spring boot+elasticsearch+Redis+mysql+mybatis进行搜索引擎web开发--爬取IThome热评(一)相关推荐

  1. 一个不错的基于Spring boot+Security+Redis+MySql实现权限登录和反爬虫的脚手架

    介绍 一个基于Spring boot 2.4.2.JDK 1.8.Security.防恶意请求技术实现的前后端分离的脚手架,可以为开发人员省去前期框架调研和搭建的成本. 软件架构 Spring boo ...

  2. Spring Boot2.x-10 基于Spring Boot 2.1.2 + Mybatis 2.0.0实现多数据源,支持事务

    文章目录 概述 思路 步骤 Step1 多数据源配置文件applicaiton.yml Step2 初始化多个数据源 Step3 配置多个数据源 验证测试 支持事务 Step1 配置类中通过@Bean ...

  3. Spring Boot2.x-09 基于Spring Boot 2.1.2 + Mybatis使用自定义注解实现数据库切换

    文章目录 概述 场景说明:读写分离 操作步骤 工程结构 Step1 自定义注解 Step2 数据源定义 Step3 配置文件配置数据源 Step4 数据源实例化DatasourceConfig Ste ...

  4. 猿创征文 | 微服务 Spring Boot 整合Redis 实战开发解决高并发数据缓存

    文章目录 一.什么是 缓存? ⛅为什么用缓存? ⚡如何使用缓存 二.实现一个商家缓存 ⌛环境搭建 ♨️核心源码 ✅测试接口 三.采用 微服务 Spring Boot 注解开启缓存 ✂️@CacheEn ...

  5. 【java毕业设计】基于Spring Boot+mysql的线上教学平台系统设计与实现(程序源码)-线上教学平台

    基于Spring Boot+mysql的线上教学平台系统设计与实现(程序源码+毕业论文) 大家好,今天给大家介绍基于Spring Boot+mysql的线上教学平台系统设计与实现,本论文只截取部分文章 ...

  6. TDengine 入门教程⑪——基于Spring Boot+Alibaba Druid框架的智能电表项目的后端时序数据库开发实战

    文章目录 一.前文 二.工程依赖 三.配置数据源 四.数据库连接池 五.电表数据实体类 六.数据库建表 七.业务Service层 八.总结 一.前文 TDengine 入门教程--导读 本开发实战配置 ...

  7. python爬取微博热搜并存入表格_python爬虫进阶之爬取微博热搜存入Mysql

    在编程中,我们如果想要把数据转入数据库中,首先会选择 MySQL数据库.因为MySQL数据库体积小.速度快.总体拥有成本低.开放源代码,其有着广泛的应用,例如我们使用python爬虫微博热搜,就可以使 ...

  8. spring boot shiro redis整合基于角色和权限的安全管理-Java编程

    一.概述 本博客主要讲解spring boot整合Apache的shiro框架,实现基于角色的安全访问控制或者基于权限的访问安全控制,其中还使用到分布式缓存redis进行用户认证信息的缓存,减少数据库 ...

  9. JPA的单向一对多关联(oneToMany)实现示例(基于Spring Boot + JPA +MySQL,表自动维护)

    本篇的环境 本篇基于Spring Boot + JPA+ MySQL. 表自动维护: 配置 ddl-auto: update,使用 Hibernate 根据类自动维护表. 本篇的示例 这里有两个类: ...

最新文章

  1. Linux下addr2line命令用法
  2. JAVA web项目转客户端(nativefier)
  3. vmware virtualization software
  4. set和enum类型的用法和区别
  5. [译] 我多希望在我学习 React.js 之前就已经知晓这些小窍门
  6. char、int、long、float、double等在64位下占多少字节
  7. PPT小技巧:拆解汉字!
  8. 4G+5G多卡聚合(弱网通信)路由器视频传输最佳选择
  9. iOS大神牛人的博客集合
  10. 棋盘分割(区间DP)
  11. 如何制作小游戏(c++教程)(新手版)(1)
  12. c++动态存储空间分配
  13. WPS以及它的两种方式PIN与PBC的理解
  14. np.rot90()的用法
  15. R语言使用factor函数处理名义变量(nominal、无序/标称分类变量)、使用ordered函数处理序数变量(ordinal、有序分类/标称变量)
  16. 人工智能下一个热点探讨,为什么要提出互联网大脑模型
  17. c语言蓝桥杯b组试题及答案,2014第五届蓝桥杯C-C++本科B组试题及答案要点-20210413045934.docx-原创力文档...
  18. Python3爬虫-04-模拟登录爬取企信宝200页数据
  19. 文件管理工具,文件批量改名,文件从1到100命名
  20. 【网络安全】LemonDuck木马进化,危害性增强

热门文章

  1. 游戏服务端开发-邮件系统
  2. PowerDesigner(数据库建模工具) 使用教程+如何生成主键和自增列
  3. Axure知识点:如何制作弹出效果的搜索框(以泉州师范学院官网为例)
  4. mysql 登录失败18456_SQL 2008 windows登录失败,错误18456, 更正
  5. 【C语言】预处理超级详细解析
  6. 美团外卖兼职值得干嘛,赚的多吗
  7. 据说真的有神,叫做人工智能(下):深度学习篇
  8. MQTT发布订阅和取消订阅
  9. 一阶电路暂态响应的结果分析。_清华考研辅导班-2020清华大学827电路原理考研真题经验参考书...
  10. 免费馅饼(简单dp)