ElasticSearch学习记录

服务器操作系统版本:Ubuntu 24.04

Java版本:21

Spring Boot版本:3.3.5

如果打算用GUI,虚拟机安装Ubuntu 24.04,见

虚拟机安装Ubuntu 24.04及其常用软件(2024.7)_ubuntu24.04-CSDN博客文章浏览阅读6.6k次,点赞37次,收藏100次。虚拟机安装Ubuntu 24.04及其常用软件(2024.7)_ubuntu24.04https://blog.csdn.net/weixin_42173947/article/details/140335522

如果打算用纯命令行,见

虚拟机安装Ubuntu 24.04服务器版(命令行版)_ubuntu24.04 download-CSDN博客文章浏览阅读1k次,点赞19次,收藏13次。这个是专门用于服务器使用的,没有GUI,常用软件安装,见虚拟机安装Ubuntu 24.04及其常用软件(2024.7)_ubuntu24.04-CSDN博客这里只记录独特的安装步骤。_ubuntu24.04 downloadhttps://blog.csdn.net/weixin_42173947/article/details/143747375

1 Ubuntu上部署ElasticSearch

准备一台服务器,IP是192.168.100.200

1.1 安装JDK8

首先需要部署JDK8+,这里我使用了JDK8

复制代码
sudo apt-get install -y openjdk-8-jdk;

1.2 下载ElasticSearch

复制代码
mkdir -p /home/user/softwares;
cd /home/user/softwares;
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.16.1-linux-x86_64.tar.gz;

1.3 解压,改文件夹名

复制代码
tar -zxvf elasticsearch-8.16.1-linux-x86_64.tar.gz;
mv elasticsearch-8.16.1 elasticsearch;

1.4 修改参数,减少内存消耗量

复制代码
vim /home/user/softwares/elasticsearch/config/jvm.options;
复制代码
-Xms1g    
-Xmx1g

vim /home/user/softwares/elasticsearch/config/elasticsearch.yml;

node.name: node-1            #配置当前es节点名称(默认是被注释的,并且默认有一个节点名)
cluster.name: my-application #默认是被注释的,并且默认有一个集群名
path.data: /home/user/elasticsearch/data     # 数据目录位置
path.logs: /home/user/elasticsearch/logs     # 日志目录位置
network.host: 0.0.0.0        #绑定的ip:默认只允许本机访问,修改为0.0.0.0后则可以远程访问cluster.initial_master_nodes: ["node-1", "node-2"] #默认是被注释的 设置master节点列表 用逗号分隔
xpack.security.enabled: false
xpack.security.http.ssl:
  enabled: false
xpack.security.transport.ssl:
  enabled: false

mkdir -p /home/user/elasticsearch/data;
mkdir -p /home/user/elasticsearch/logs;

1.5 启动

复制代码
cd /home/user/softwares/elasticsearch/bin;
nohup ./elasticsearch &

1.6 宿主机访问

复制代码
http://192.168.100.200:9200/

{
    "name": "node-1",
    "cluster_name": "my-application",
    "cluster_uuid": "GFf-TSlmQkuV_aceGLv--A",
    "version": {
        "number": "8.16.1",
        "build_flavor": "default",
        "build_type": "tar",
        "build_hash": "ffe992aa682c1968b5df375b5095b3a21f122bf3",
        "build_date": "2024-11-19T16:00:31.793213192Z",
        "build_snapshot": false,
        "lucene_version": "9.12.0",
        "minimum_wire_compatibility_version": "7.17.0",
        "minimum_index_compatibility_version": "7.0.0"
    },
    "tagline": "You Know, for Search"
}

2 Java连接ElasticSearch环境搭建

2.2 父节点pom.xml

复制代码
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.sliverbullet</groupId>
    <artifactId>jdk21-maven-test</artifactId>
    <packaging>pom</packaging>

    <version>1.0</version>

    <properties>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>21</java.version>
        <spring-boot.version>3.3.5</spring-boot.version>
    </properties>

    <modules>
        <module>springboot3-test</module>
        <module>rocketmq-test</module>
        <module>elasticsearch-test</module>
    </modules>

    <repositories>
        <repository>
            <id>public</id>
            <name>aliyun nexus</name>
            <url>https://maven.aliyun.com/repository/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>public</id>
            <name>aliyun nexus</name>
            <url>https://maven.aliyun.com/repository/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</project>

2.3 子节点xml

复制代码
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.sliverbullet</groupId>
        <artifactId>jdk21-maven-test</artifactId>
        <version>1.0</version>
    </parent>

    <artifactId>elasticsearch-test</artifactId>

    <properties>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>21</java.version>
        <spring-boot.version>3.3.5</spring-boot.version>
        <fastjson2-version>2.0.53</fastjson2-version>
        <lombok-version>1.18.34</lombok-version>
        <elasticsearch-spring-boot-starter-version>3.4.0</elasticsearch-spring-boot-starter-version>
        <hutool-version>4.6.8</hutool-version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.fastjson2</groupId>
            <artifactId>fastjson2</artifactId>
            <version>${fastjson2-version}</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
            <version>${elasticsearch-spring-boot-starter-version}</version>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>${hutool-version}</version>
        </dependency>
    </dependencies>

</project>

3 ElasticSearch基本配置

3.2 application.yml的配置

复制代码
server:
  port: 8003
spring:
  application:
    name: elasticsearch-test
  profiles:
    active: dev
machine-no: 1

3.3 application-dev.yml的配置

test,prod,自行配置

复制代码
spring:
  elasticsearch:
    rest:
      uris: 192.168.100.200:9200
logging:
  file:
    path: D:/log/SpringBoot3-Test
    name: ${logging.file.path}/test.log

4 正式测试

相关推荐
aigcapi3 小时前
RAG 系统的黑盒测试:从算法对齐视角解析 GEO 优化的技术指标体系
大数据·人工智能·算法
做cv的小昊4 小时前
计算机图形学:【Games101】学习笔记05——着色(插值、高级纹理映射)与几何(基本表示方法)
笔记·opencv·学习·计算机视觉·图形渲染·几何学
车载测试工程师4 小时前
CAPL学习-CAN相关函数-统计API函数
网络·网络协议·学习·capl·canoe
cui17875684 小时前
排队免单模式深度拆解:闭环逻辑、裂变内核与落地法则
大数据
热爱专研AI的学妹5 小时前
数眼搜索API与博查技术特性深度对比:实时性与数据完整性的核心差异
大数据·开发语言·数据库·人工智能·python
好奇龙猫5 小时前
【AI学习-comfyUI学习-第二十四节-open(contorlnet多重处理)+图生图openpose-各个部分学习】
人工智能·学习
wanzhong23336 小时前
CUDA学习5-矩阵乘法(共享内存版)
深度学习·学习·算法·cuda·高性能计算
方向研究7 小时前
管仲治国
大数据
成长之路5147 小时前
【实证分析】数据资产信息披露程度数据集-含原始数据及do代码(2007-2024年)
大数据
Elastic 中国社区官方博客7 小时前
Elasticsearch:在 X-mas 吃一些更健康的东西
android·大数据·数据库·人工智能·elasticsearch·搜索引擎·全文检索