当前位置: 首页 > news >正文

日常记录:springboot 2.2.5 + es 6.8.12

前言

最近有用到搜索引擎的功能,这不得把之前的es过程实践一遍,但发现过程坎坷,因为版本太低了。

一、安装es 6.8.12

  安装过程跟之前写那章日常记录:elasticsearch 在linux安装_elasticsearch linux安装-CSDN博客一样,安装包下载Elasticsearch 6.8.12 | Elastic。

  下载完毕,上传到服务器之后直接用tar -zxvf 解压。然后进入config目录,编辑elasticsearch.yml文件。

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: es
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: master
#cluster.initial_master_nodes: ["master"]
discovery.type: single-node
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /home/elasticsearch-6.8.12/to/data
#
# Path to log files:
#
path.logs: /home/elasticsearch-6.8.12/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#http 请求端口
http.port: 9200

#通讯端口

transport.tcp.port: 9300
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
#discovery.type: zen
#discovery.zen.minimum_master_nodes: 1
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes:
#
# For more information, consult the zen discovery module documentation.
#
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true


#开启登录校验,不开启登录的话两个都关闭掉

xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

配置完毕之后,进入es 的bin 目录执行./elasticsearch -d 后台挂起启动。

然后需要初始化一次es密码,执行命令./elasticsearch-setup-passwords interactive 会提示每个账号的密码输入,这里简单输入123456。

好了,在浏览器访问9200,提示账号、密码登录,输入就可以了

这样就简单设置账号登录成功了

二、程序上连接

springboot maven引入spring-boot-starter-data-elasticsearch ,跟随springboot版本,这里springboot版本是2.2.5,自动引入elasticsearch 3.2.5

       ... 

       <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>

       ...

yml配置

spring:
  application:
    name: es
  data:
    elasticsearch:

      #这里填真实cluster-name名字
      cluster-name: es

      #这里填真实 cluster-nodes ip+端口
      cluster-nodes: xxxx:9300
      rest:
        uris: http://xxx:9200
        username: elastic
        password: 123456

这里很坑的是springboot不会自动读取es 账号密码,尝试过yml多动配置账号、密码,最终还是没生效(但是我看es 7.x的springboot是会读取的,知道的同学可以说下),然后自己写一个配置类读取账号、密码 。

package com.xxxxx.configuration;import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;/*** * 描述:elasticsearch配置* @author sakyoka* @date 2024年10月11日 下午3:47:19*/
@Configuration
public class ElasticsearchConfiguration extends AbstractElasticsearchConfiguration {@Value("${spring.data.elasticsearch.rest.username}")private String username;@Value("${spring.data.elasticsearch.rest.password}")private String password;@Value("${spring.data.elasticsearch.rest.uris}")private String uris;@Beanpublic ElasticsearchRestTemplate elasticsearchRestTemplate(RestHighLevelClient client) {return new ElasticsearchRestTemplate(elasticsearchClient());}@Overridepublic RestHighLevelClient elasticsearchClient(){//这句关闭很奏效,不然会有异常System.setProperty("es.set.netty.runtime.available.processors", "false");CredentialsProvider credentialsProvider = new BasicCredentialsProvider();credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));RestClientBuilder builder = RestClient.builder(HttpHost.create(uris)).setHttpClientConfigCallback(http -> {return http.setDefaultCredentialsProvider(credentialsProvider);});return new RestHighLevelClient(builder);}
}

这里es自定义类主要是继承了AbstractElasticsearchConfiguration,重写elasticsearchClient,对RestHighLevelClient设置账号、密码以及请求地址。本来以为重写这个就可以了的,但是提示引用

ElasticsearchTemplate有问题,没错es有两个ElasticsearchRestTemplate以及ElasticsearchTemplate,似乎重写了elasticsearchClient之后一定要用ElasticsearchRestTemplate,所以得重新定义elasticsearchRestTemplate。

好了到目前为止,配置完毕,使用ElasticsearchRestTemplate也正常请求es数据。但是还知道我开启了登录xpack.security.enabled: true同时开启了xpack.security.transport.ssl.enabled: true了吗,这里服务器日志一直打印异常

io.netty.handler.codec.DecoderException: io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record: 45530000002c00000000000012f208004d3603000016696e7465726e616c3a7463702f68616e647368616b650004bb91f302(已处理日常记录:es TransportClient添加证书处理-CSDN博客)

尝试设置transport的证书,发现还是继续报这个异常,都怀疑生成证书是不是无效的,到目前为止还没解决这个异常,很奇怪的是正常使用,或者这个异常是es节点之间通讯用的?

尝试关闭xpack.security.transport.ssl.enabled: false,但是启动失败至少需要配置证书

xpack.security.transport.ssl.key: ssl/http.key
xpack.security.transport.ssl.certificate: ssl/http.crt
xpack.security.transport.ssl.verification_mode: certificate

 关闭之后以及配置这个证书之后,服务器确实不报错了,但是程序报错也不影响使用,一直提示ElasticsearchSecurityException: missing authentication token for action,这个异常问题也没处理,想到这还是让服务器报异常算了,选择开启xpack.security.transport.ssl.enabled: true

以上问题还没处理。。

最后:

1、没有开启登录时候还好好的,啥异常都没有

2、开启登录之后,程序读取不到账号密码,导致需要写配置类,按道理springboot集成es有默认配置,但是网上太多版本、太多配置,没有一个符合的。

3、es证书生成是否有效目前成谜,一直报异常(已处理日常记录:es TransportClient添加证书处理-CSDN博客)

相关文章:

日常记录:springboot 2.2.5 + es 6.8.12

前言 最近有用到搜索引擎的功能&#xff0c;这不得把之前的es过程实践一遍&#xff0c;但发现过程坎坷&#xff0c;因为版本太低了。 一、安装es 6.8.12 安装过程跟之前写那章日常记录&#xff1a;elasticsearch 在linux安装_elasticsearch linux安装-CSDN博客一样&#xff0…...

MySQL数据库备份与恢复详解

文章目录 一、为什么需要备份数据库&#xff1f;二、MySQL数据库的备份方式1. 逻辑备份2. 物理备份3. 二进制日志备份 三、恢复数据库1. 使用mysqldump备份文件恢复2. 使用物理备份恢复3. 使用二进制日志恢复 四、备份与恢复的最佳实践五、结语 在日常的数据库运维中&#xff0…...

10.22 MySQL

存储过程 存储函数 存储函数是有返回值的存储过程&#xff0c;存储函数的参数只能是in类型的。具体语法如下&#xff1a; characteristic 特性 练习&#xff1a; 从1到n的累加 ​​​​​​ create function fun1(n int) returns int deterministic begindeclare total i…...

「AIGC」n8n AI Agent开源的工作流自动化工具

n8n AI Agent 是一个利用大型语言模型(LLMs)来设计和构建智能体(agents)的工具,这些智能体能够执行一系列复杂的任务,如理解指令、模仿类人推理,以及从用户命令中理解隐含意图。n8n AI Agent 的核心在于构建一系列提示(prompts),使 LLM 能够模拟自主行为。 传送门→ …...

Android 中获取和读取短信验证码

方法一&#xff1a;通过 SMS Retriever API SMS Retriever API 是 Google 提供的一种安全的方式&#xff0c;可以从系统中获取不需要权限的短信验证码。这种方式不需要请求 READ_SMS 权限&#xff0c;非常适合处理短信验证码的情况。 1. 在 build.gradle 中添加依赖 dependen…...

SQL语句高级查询(适用于新手)

SQL查询语句的下载脚本链接&#xff01;&#xff01;&#xff01; 【免费】SQL练习资源-具体练习操作可以查看我发布的文章资源-CSDN文库https://download.csdn.net/download/Z0412_J0103/89908378 本文旨在为那些编程基础相对薄弱的朋友们提供一份详尽的指南&#xff0c;特别聚…...

main.ts中引入App.vue报错,提示“Cannot find module ‘./App.vue’ or its corresponding type

原因 代码编辑器&#xff1a;vscode &#xff0c;使用vue3&#xff0c;所以安装了 Volar 插件&#xff0c;可以使 vue 代码高亮显示&#xff0c;不同颜色区分代码块&#xff0c;以及语法错误提示等 提示&#xff1a;如果使用的是vue2&#xff0c;则使用 Vetur 插件&#xff1…...

Android15音频进阶之组音量调试(九十)

简介: CSDN博客专家、《Android系统多媒体进阶实战》一书作者 新书发布:《Android系统多媒体进阶实战》🚀 优质专栏: Audio工程师进阶系列【原创干货持续更新中……】🚀 优质专栏: 多媒体系统工程师系列【原创干货持续更新中……】🚀 优质视频课程:AAOS车载系统+…...

【Java】常用方法合集

以 DemoVo 为实体 import lombok.Data; import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;Data ExcelIgnoreUnannotated public class ExportPromoteUnitResult {private String id;ExcelProperty(value &qu…...

深入了解Vue Router:基本用法、重定向、动态路由与路由守卫的性能优化

文章目录 1. 引言2. Vue Router的基本用法2.1 基本配置 3. 重定向和命名路由的使用3.1 重定向3.2 命名路由 4. 在Vue Router中如何处理动态路由4.1 动态路由的概念4.2 如何处理动态路由4.3 动态路由的懒加载 5. 路由守卫的实现与性能影响5.1 什么是路由守卫&#xff1f;5.2 路由…...

深入理解InnoDB底层原理:从数据结构到逻辑架构

💡 无论你是刚刚踏入编程世界的新人,还是希望进一步提升自己的资深开发者,在这里都能找到适合你的内容。我们共同探讨技术难题,一起进步,携手度过互联网行业的每一个挑战。 📣 如果你觉得我的文章对你有帮助,请不要吝啬你的点赞👍分享💕和评论哦! 让我们一起打造…...

Linux介绍及操作命令

Linux 是一种开源的操作系统,具有以下特点和优势: 一、稳定性和可靠性 内核稳定 Linux 内核经过多年的发展和优化,具有高度的稳定性。它能够长时间运行而不出现崩溃或故障,适用于服务器和关键任务应用。内核的稳定性得益于其严格的开发流程和质量控制,以及全球开发者社区…...

JS | 详解图片懒加载的6种实现方案

一、什么是懒加载&#xff1f; 懒加载是一种对网页性能优化的方式&#xff0c;比如&#xff0c;当访问一个网页的时候&#xff0c;优先显示可视区域的图片而不是一次加载全部的图片&#xff0c;当需要显示时&#xff0c;再发送请求加载图片。 懒加载 &#xff1a;延迟加载&…...

Java | Leetcode Java题解之第502题IPO

题目&#xff1a; 题解&#xff1a; class Solution {public int findMaximizedCapital(int k, int w, int[] profits, int[] capital) {int n profits.length;int curr 0;int[][] arr new int[n][2];for (int i 0; i < n; i) {arr[i][0] capital[i];arr[i][1] profi…...

JavaWeb学习(3)

目录 一、9大内置对象 二、JavaBean 三、MVC三层架构 Model View Controller&#xff08;Servlet&#xff09; 四、Filter&#xff08;过滤器&#xff09; 应用一&#xff1a;处理中文乱码 应用二&#xff1a;登录验证 五、监听器 六、JDBC 一、9大内置对象 PageCont…...

【含开题报告+文档+PPT+源码】基于SpringBoot的百货商城管理系统的设计与实现

开题报告 随着互联网技术的快速发展和电子商务的兴起&#xff0c;网上购物已成为人们日常生活中不可或缺的一部分。传统的实体店面由于时间和空间的限制&#xff0c;无法满足消费者对于便捷、快速、个性化购物体验的需求。在此背景下&#xff0c;基于 Java 的网上商城系统应运…...

Elasticsearch 实战应用与优化策略研究

一、引言 1.1 研究背景 在当今大数据时代&#xff0c;数据量呈爆炸式增长&#xff0c;对数据的存储、检索和分析提出了更高的要求。Elasticsearch 作为一款强大的分布式搜索和分析引擎&#xff0c;在这个时代背景下显得尤为重要。 随着数据密集型应用场景的不断增加&#xf…...

植物大战僵尸杂交版游戏分享

植物大战僵尸杂交版游戏下载&#xff1a;夸克网盘分享 无捆绑之类的隐形消费&#xff0c;下载即玩...

ProteinMPNN中DecLayer类介绍

PositionWiseFeedForward 类的代码 class PositionWiseFeedForward(nn.Module):def __init__(self, num_hidden, num_ff):super(PositionWiseFeedForward, self).__init__()self.W_in = nn.Linear(num_hidden, num_ff, bias=True)self.W_out = nn.Linear(num_ff, num_hidden, …...

Flux.all 使用说明书

all public final Mono<Boolean> all(Predicate<? super T> predicate)Emit a single boolean true if all values of this sequence match the Predicate. 如果该序列中的所有值都匹配给定的谓词&#xff08;Predicate&#xff09;&#xff0c;则发出一个布尔值…...

19c补丁后oracle属主变化,导致不能识别磁盘组

补丁后服务器重启&#xff0c;数据库再次无法启动 ORA01017: invalid username/password; logon denied Oracle 19c 在打上 19.23 或以上补丁版本后&#xff0c;存在与用户组权限相关的问题。具体表现为&#xff0c;Oracle 实例的运行用户&#xff08;oracle&#xff09;和集…...

云原生核心技术 (7/12): K8s 核心概念白话解读(上):Pod 和 Deployment 究竟是什么?

大家好&#xff0c;欢迎来到《云原生核心技术》系列的第七篇&#xff01; 在上一篇&#xff0c;我们成功地使用 Minikube 或 kind 在自己的电脑上搭建起了一个迷你但功能完备的 Kubernetes 集群。现在&#xff0c;我们就像一个拥有了一块崭新数字土地的农场主&#xff0c;是时…...

简易版抽奖活动的设计技术方案

1.前言 本技术方案旨在设计一套完整且可靠的抽奖活动逻辑,确保抽奖活动能够公平、公正、公开地进行,同时满足高并发访问、数据安全存储与高效处理等需求,为用户提供流畅的抽奖体验,助力业务顺利开展。本方案将涵盖抽奖活动的整体架构设计、核心流程逻辑、关键功能实现以及…...

练习(含atoi的模拟实现,自定义类型等练习)

一、结构体大小的计算及位段 &#xff08;结构体大小计算及位段 详解请看&#xff1a;自定义类型&#xff1a;结构体进阶-CSDN博客&#xff09; 1.在32位系统环境&#xff0c;编译选项为4字节对齐&#xff0c;那么sizeof(A)和sizeof(B)是多少&#xff1f; #pragma pack(4)st…...

云启出海,智联未来|阿里云网络「企业出海」系列客户沙龙上海站圆满落地

借阿里云中企出海大会的东风&#xff0c;以**「云启出海&#xff0c;智联未来&#xff5c;打造安全可靠的出海云网络引擎」为主题的阿里云企业出海客户沙龙云网络&安全专场于5.28日下午在上海顺利举办&#xff0c;现场吸引了来自携程、小红书、米哈游、哔哩哔哩、波克城市、…...

Cilium动手实验室: 精通之旅---20.Isovalent Enterprise for Cilium: Zero Trust Visibility

Cilium动手实验室: 精通之旅---20.Isovalent Enterprise for Cilium: Zero Trust Visibility 1. 实验室环境1.1 实验室环境1.2 小测试 2. The Endor System2.1 部署应用2.2 检查现有策略 3. Cilium 策略实体3.1 创建 allow-all 网络策略3.2 在 Hubble CLI 中验证网络策略源3.3 …...

Golang dig框架与GraphQL的完美结合

将 Go 的 Dig 依赖注入框架与 GraphQL 结合使用&#xff0c;可以显著提升应用程序的可维护性、可测试性以及灵活性。 Dig 是一个强大的依赖注入容器&#xff0c;能够帮助开发者更好地管理复杂的依赖关系&#xff0c;而 GraphQL 则是一种用于 API 的查询语言&#xff0c;能够提…...

质量体系的重要

质量体系是为确保产品、服务或过程质量满足规定要求&#xff0c;由相互关联的要素构成的有机整体。其核心内容可归纳为以下五个方面&#xff1a; &#x1f3db;️ 一、组织架构与职责 质量体系明确组织内各部门、岗位的职责与权限&#xff0c;形成层级清晰的管理网络&#xf…...

跨链模式:多链互操作架构与性能扩展方案

跨链模式&#xff1a;多链互操作架构与性能扩展方案 ——构建下一代区块链互联网的技术基石 一、跨链架构的核心范式演进 1. 分层协议栈&#xff1a;模块化解耦设计 现代跨链系统采用分层协议栈实现灵活扩展&#xff08;H2Cross架构&#xff09;&#xff1a; 适配层&#xf…...

【Zephyr 系列 10】实战项目:打造一个蓝牙传感器终端 + 网关系统(完整架构与全栈实现)

🧠关键词:Zephyr、BLE、终端、网关、广播、连接、传感器、数据采集、低功耗、系统集成 📌目标读者:希望基于 Zephyr 构建 BLE 系统架构、实现终端与网关协作、具备产品交付能力的开发者 📊篇幅字数:约 5200 字 ✨ 项目总览 在物联网实际项目中,**“终端 + 网关”**是…...