您的位置:首页 > 游戏 > 游戏 > 网络游戏大型_网页制作与设计表白设计_怎么给产品做网络推广_小熊代刷推广网站

网络游戏大型_网页制作与设计表白设计_怎么给产品做网络推广_小熊代刷推广网站

2024/12/23 14:52:40 来源:https://blog.csdn.net/weixin_42173947/article/details/144176605  浏览:    关键词:网络游戏大型_网页制作与设计表白设计_怎么给产品做网络推广_小熊代刷推广网站
网络游戏大型_网页制作与设计表白设计_怎么给产品做网络推广_小熊代刷推广网站

服务器操作系统版本: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-testprofiles:active: dev
machine-no: 1

3.3 application-dev.yml的配置

test,prod,自行配置

spring:elasticsearch:uris: http://192.168.100.200:9200
logging:file:path: D:/log/SpringBoot3-Testname: ${logging.file.path}/test.log

4 正式测试

4.1 基本插入

实体类

package com.sliverbullet.bean;import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;import java.math.BigDecimal;
import java.util.Date;@Document(indexName = "employee_info")
public class EmployeeInfo {@Idprivate Long id;/*** 工号*/@Field(name = "job_no")@JsonProperty("job_no")private String jobNo;/*** 姓名*/@Field(name = "name")private String name;/*** 英文名*/@Field(name = "english_name")@JsonProperty("english_name")private String englishName;/*** 工作岗位*/private String job;/*** 性别*/private Integer sex;/*** 年龄*/private Integer age;/*** 薪资*/private BigDecimal salary;/*** 入职时间*/@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+08:00")@Field(name = "job_day")@JsonProperty("job_day")private Date jobDay;/*** 备注*/private String remark;public Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getJobNo() {return jobNo;}public void setJobNo(String jobNo) {this.jobNo = jobNo;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getEnglishName() {return englishName;}public void setEnglishName(String englishName) {this.englishName = englishName;}public String getJob() {return job;}public void setJob(String job) {this.job = job;}public Integer getSex() {return sex;}public void setSex(Integer sex) {this.sex = sex;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}public BigDecimal getSalary() {return salary;}public void setSalary(BigDecimal salary) {this.salary = salary;}public Date getJobDay() {return jobDay;}public void setJobDay(Date jobDay) {this.jobDay = jobDay;}public String getRemark() {return remark;}public void setRemark(String remark) {this.remark = remark;}public EmployeeInfo() {}public EmployeeInfo(Long id, String jobNo, String name, String englishName, String job, Integer sex, Integer age, BigDecimal salary, Date jobDay, String remark) {this.id = id;this.jobNo = jobNo;this.name = name;this.englishName = englishName;this.job = job;this.sex = sex;this.age = age;this.salary = salary;this.jobDay = jobDay;this.remark = remark;}@Overridepublic String toString() {return "EmployeeInfo{" +"id=" + id +", jobNo='" + jobNo + '\'' +", name='" + name + '\'' +", englishName='" + englishName + '\'' +", job='" + job + '\'' +", sex=" + sex +", age=" + age +", salary=" + salary +", jobDay=" + jobDay +", remark='" + remark + '\'' +'}';}
}

实体类实现接口

package com.sliverbullet.repository;import com.sliverbullet.bean.EmployeeInfo;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;public interface EmployeeInfoRepository extends ElasticsearchRepository<EmployeeInfo, Long> {}

Controller层

    @Value("${machine-no}")private String machineNo;@Resourceprivate EmployeeInfoRepository elasticRepository;@RequestMapping("/save")public String save(@RequestBody EmployeeInfo param) {DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSSSS");LocalDateTime localDateTime = LocalDateTime.now();String formattedDate = dateTimeFormatter.format(localDateTime);log.info("【SpringBoot3测试】-【ElasticSearch测试】:{}", formattedDate);EmployeeInfo employeeInfo = new EmployeeInfo(param.getId(), param.getJobNo(), param.getName(), param.getEnglishName(), param.getJob(), param.getSex(), param.getAge(), param.getSalary(), param.getJobDay(), param.getRemark());EmployeeInfo result = elasticRepository.save(employeeInfo);log.info("【ElasticSearch测试】-【插入结果】:{}", JSONObject.toJSONString(result));return JSONObject.toJSONString(result);}

测试

    /*** 基本插入** @return void*/@Testpublic void save() {String url = "http://127.0.0.1:8003/save";JSONObject request = new JSONObject();request.put("id", 6001L);request.put("job_no", "2001");request.put("name", "张三");request.put("english_name", "zhangsan");request.put("job", "Java");request.put("sex", 1);request.put("age", 21);request.put("salary", new BigDecimal("10000.00"));request.put("job_day", new Date());request.put("remark", request.toJSONString());String resp = HttpUtil.post(url, JSONObject.toJSONString(request));log.info("基本同步消息请求结果:{}", resp);}
11:24:04.114 [main] INFO ElasticSearchTest -- 基本同步消息请求结果:{"age":21,"english_name":"ZhangSan","id":6001,"job":"Java","job_day":"2024-12-05 11:24:03.857","job_no":"2001","name":"张三","remark":"remark","salary":10000.00,"sex":1}
2024-12-05T11:24:03.998+08:00  INFO 31564 --- [elasticsearch-test] [nio-8003-exec-7] c.s.controller.ElasticSearchController   : 【SpringBoot3测试】-【ElasticSearch测试】:2024-12-05 11:24:03.998820800
2024-12-05T11:24:04.093+08:00  INFO 31564 --- [elasticsearch-test] [nio-8003-exec-7] c.s.controller.ElasticSearchController   : 【ElasticSearch测试】-【插入结果】:{"age":21,"english_name":"ZhangSan","id":6001,"job":"Java","job_day":"2024-12-05 11:24:03.857","job_no":"2001","name":"张三","remark":"remark","salary":10000.00,"sex":1}

4.2 ID查询

Controller层

    @Value("${machine-no}")private String machineNo;@Resourceprivate EmployeeInfoRepository elasticRepository;@RequestMapping("/find")public String find(@RequestBody EmployeeInfo param) {DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSSSS");LocalDateTime localDateTime = LocalDateTime.now();String formattedDate = dateTimeFormatter.format(localDateTime);log.info("【SpringBoot3测试】-【ElasticSearch测试】:{}", formattedDate);Optional<EmployeeInfo>  employeeInfo = elasticRepository.findById(param.getId());log.info("【ElasticSearch测试】-【单条查询结果】:{}", JSONObject.toJSONString(employeeInfo));return JSONObject.toJSONString(employeeInfo);}

测试

    /*** 基本查询** @return void*/@Testpublic void find() {String url = "http://127.0.0.1:8003/find";JSONObject request = new JSONObject();request.put("id", 6001L);String resp = HttpUtil.post(url, JSONObject.toJSONString(request));log.info("基本同步查询请求结果:{}", resp);}
11:25:09.248 [main] INFO ElasticSearchTest -- 基本同步查询请求结果:{"age":21,"english_name":"ZhangSan","id":6001,"job":"Java","job_day":"2024-12-05 11:24:03.857","job_no":"2001","name":"张三","remark":"remark","salary":10000.0,"sex":1}
2024-12-05T11:25:09.223+08:00  INFO 31564 --- [elasticsearch-test] [nio-8003-exec-5] c.s.controller.ElasticSearchController   : 【SpringBoot3测试】-【ElasticSearch测试】:2024-12-05 11:25:09.223267400
2024-12-05T11:25:09.234+08:00  INFO 31564 --- [elasticsearch-test] [nio-8003-exec-5] c.s.controller.ElasticSearchController   : 【ElasticSearch测试】-【单条查询结果】:{"age":21,"english_name":"ZhangSan","id":6001,"job":"Java","job_day":"2024-12-05 11:24:03.857","job_no":"2001","name":"张三","remark":"remark","salary":10000.0,"sex":1}

4.3 ID修改

其实修改和插入是一个接口

测试

    /*** 基本插入** @return void*/@Testpublic void save() {String url = "http://127.0.0.1:8003/save";JSONObject request = new JSONObject();request.put("id", 6001L);request.put("job_no", "2001");request.put("name", "李四");request.put("english_name", "LiSi");request.put("job", "Java");request.put("sex", 1);request.put("age", 21);request.put("salary", new BigDecimal("12000.00"));request.put("job_day", new Date());request.put("remark", "remark");String resp = HttpUtil.post(url, JSONObject.toJSONString(request));log.info("基本同步消息请求结果:{}", resp);}
11:46:45.086 [main] INFO ElasticSearchTest -- 基本同步消息请求结果:{"age":21,"english_name":"LiSi","id":6001,"job":"Java","job_day":"2024-12-05 11:46:44.908","job_no":"2001","name":"李四","remark":"remark","salary":12000.00,"sex":1}
2024-12-05T11:46:45.039+08:00  INFO 31564 --- [elasticsearch-test] [nio-8003-exec-9] c.s.controller.ElasticSearchController   : 【SpringBoot3测试】-【ElasticSearch测试】:2024-12-05 11:46:45.039450500
2024-12-05T11:46:45.073+08:00  INFO 31564 --- [elasticsearch-test] [nio-8003-exec-9] c.s.controller.ElasticSearchController   : 【ElasticSearch测试】-【插入结果】:{"age":21,"english_name":"LiSi","id":6001,"job":"Java","job_day":"2024-12-05 11:46:44.908","job_no":"2001","name":"李四","remark":"remark","salary":12000.00,"sex":1}

查询

11:47:47.040 [main] INFO ElasticSearchTest -- 基本同步查询请求结果:{"age":21,"english_name":"LiSi","id":6001,"job":"Java","job_day":"2024-12-05 11:46:44.908","job_no":"2001","name":"李四","remark":"remark","salary":12000.0,"sex":1}
2024-12-05T11:47:47.022+08:00  INFO 31564 --- [elasticsearch-test] [nio-8003-exec-1] c.s.controller.ElasticSearchController   : 【SpringBoot3测试】-【ElasticSearch测试】:2024-12-05 11:47:47.022578700
2024-12-05T11:47:47.027+08:00  INFO 31564 --- [elasticsearch-test] [nio-8003-exec-1] c.s.controller.ElasticSearchController   : 【ElasticSearch测试】-【单条查询结果】:{"age":21,"english_name":"LiSi","id":6001,"job":"Java","job_day":"2024-12-05 11:46:44.908","job_no":"2001","name":"李四","remark":"remark","salary":12000.0,"sex":1}

4.4 ID删除

Controller层

    @Value("${machine-no}")private String machineNo;@Resourceprivate EmployeeInfoRepository elasticRepository;@RequestMapping("/delete")public String delete(@RequestBody EmployeeInfo param) {DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSSSS");LocalDateTime localDateTime = LocalDateTime.now();String formattedDate = dateTimeFormatter.format(localDateTime);log.info("【SpringBoot3测试】-【ElasticSearch测试】:{}", formattedDate);elasticRepository.deleteById(param.getId());JSONObject result = new JSONObject();result.put("msg", "success");log.info("【ElasticSearch测试】-【单条删除结果】:{}", result.toJSONString());return result.toJSONString();}

测试

    /*** 基本删除** @return void*/@Testpublic void delete() {String url = "http://127.0.0.1:8003/delete";JSONObject request = new JSONObject();request.put("id", 6001L);String resp = HttpUtil.post(url, JSONObject.toJSONString(request));log.info("基本删除请求结果:{}", resp);}
11:53:49.456 [main] INFO ElasticSearchTest -- 基本删除请求结果:{"msg":"success"}
2024-12-05T11:53:49.206+08:00  INFO 49360 --- [elasticsearch-test] [nio-8003-exec-1] c.s.controller.ElasticSearchController   : 【SpringBoot3测试】-【ElasticSearch测试】:2024-12-05 11:53:49.206563800
2024-12-05T11:53:49.438+08:00  INFO 49360 --- [elasticsearch-test] [nio-8003-exec-1] c.s.controller.ElasticSearchController   : 【ElasticSearch测试】-【单条删除结果】:{"msg":"success"}

查询

11:54:56.173 [main] INFO ElasticSearchTest -- 基本同步查询请求结果:null
2024-12-05T11:54:56.139+08:00  INFO 49360 --- [elasticsearch-test] [nio-8003-exec-3] c.s.controller.ElasticSearchController   : 【SpringBoot3测试】-【ElasticSearch测试】:2024-12-05 11:54:56.139854100
2024-12-05T11:54:56.160+08:00  INFO 49360 --- [elasticsearch-test] [nio-8003-exec-3] c.s.controller.ElasticSearchController   : 【ElasticSearch测试】-【单条查询结果】:null

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com