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 正式测试

相关推荐
大丈夫立于天地间几秒前
OSPF - 1类LSA(Router-LSA)
网络·网络协议·学习·信息与通信
Anna_Tong34 分钟前
引领实时数据分析新时代:阿里云实时数仓 Hologres
大数据·阿里云·数据分析·实时数仓
jinan8863 小时前
电子图纸怎么保障安全?
大数据·安全
生信碱移3 小时前
万字长文:机器学习的数学基础(易读)
大数据·人工智能·深度学习·线性代数·算法·数学建模·数据分析
Chrikk4 小时前
NCCL学习笔记-概念全解
笔记·学习
GHL2842710904 小时前
redis学习-value数据结构
数据库·redis·学习
vortex54 小时前
正则表达式进阶学习(一):环视、捕获分组与后向引用
学习·正则表达式
武昌库里写JAVA4 小时前
Redis奇幻之旅(四)4. Redis Cluster
java·开发语言·spring boot·学习·课程设计
酒与花生米4 小时前
【Vue学习】Vue 组件实例的生命周期(四个阶段,八个钩子)
javascript·vue.js·学习