news 2026/5/1 7:13:30

ES升级至:8.15.3

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
ES升级至:8.15.3

建议先阅读这篇博客,本文中只描述了关键信息,整体流程可以看下面文章中间件升级-CSDN博客

说明:

检索文档,jdk=1.8客户端最高支持到elasticsearch-rest-client=7.17.x。不推荐进行升级,如升级后使用需充分验证当前使用功能是否正常。

  1. es原始版本: 8.1.3

  2. Kibana 等版本需同步升级。

  3. springboot版本:2.7.18 , 默认elasticsearch-rest-client =7.17.15

平台指定: elasticsearch-rest-client =8.1.3
升级后推荐指定:elasticsearch-rest-client =8.15.3

  1. 下载地址:https://www.elastic.co/downloads/elasticsearch

服务安装

Docker 安装:

详见: https://www.elastic.co/guide/en/elasticsearch/reference/8.15/docker.html

docker pull docker.elastic.co/elasticsearch/elasticsearch:8.15.3

docker run -d --name elasticsearch-8.15.3 -p 9200:9200 docker.elastic.co/elasticsearch/elasticsearch:8.15.3

linux安装包下载:

# 下载地址: https://www.elastic.co/downloads/past-releases/elasticsearch-8-15-3 # 进入目录 cd /opt/easy-cloud # 下载文件(arm框架请自行调整,当前标记的为centos7版本,其它版本请自行调整) wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.15.3-linux-x86_64.tar.gz # 解压文件 tar --no-same-owner -zxvf elasticsearch-8.15.3-*.tar.gz # 创建用户 useradd elastic && passwd elastic # 赋权限给elastic用户 chown -R elastic:elastic /opt/easy-cloud/elasticsearch-8.15.3 # 进入目录 cd elasticsearch-8.15.3 # 备份配置文件 cp config/elasticsearch.yml config/elasticsearch.yml.bak # 核实内存是否更改:本文设置为2g,默认是4g,如果服务内存充足,可不进行修改 # vim config/jvm.options # 推荐更改-xms=2g -xmx=2g

windows安装包下载:

载地址:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.15.3-windows-x86_64.zip

服务升级:

数据备份:

数据备份:
1. 进入文件夹
cd /opt/easy-cloud
2. 历史安装文件备份
tar -zcvf elasticsearch-8.1.3.tar.gz elasticsearch-8.1.3 /
3. 创建路径并授权
mkdir -p /data/es/backup_repo
chown -R elastic:elastic /data/es/backup_repo
-- 报错:mkdir: cannot create directory '/data': Permission denied 使用docker exec -u root -it xxx bash 进入容器
4. 设置备份路径:(先查看是否存在 cat config/elasticsearch.yml |grep "path.repo")
echo 'path.repo: ["/data/es/backup_repo"]' >> config/elasticsearch.yml
5. 重启当前es服务:
systemctl restart elasticsearch
6. 创建快照仓库
curl -k -u elastic:elastic -XPUT "https://localhost:9200/_snapshot/my_local_repo" -H "Content-Type: application/json" -d '{
"type": "fs",
"settings": {
"location": "/data/es/backup_repo",
"compress": true,
"chunk_size": "100mb"
}
}'
7. 验证快照仓库创建是否成功
curl -k -u elastic:elastic -XGET "https://localhost:9200/_snapshot/my_local_repo?pretty"
8. 真实创建快照
curl -k -u elastic:elastic -XPUT "https://localhost:9200/_snapshot/my_local_repo/upgrade_backup_8.1.3?wait_for_completion=true" -H "Content-Type: application/json" -d '{
"indices": "*",
"include_global_state": true
}'
9. 验证快照有效性
curl -k -u elastic:elastic -XGET "https://localhost:9200/_snapshot/my_local_repo/upgrade_backup_8.1.3?pretty"

新服务启动:

1. 停止历史服务
pgrep -f -u elastic elasticsearch | xargs -r kill -15
2. 进入目录
cd /opt/easy-cloud/elasticsearch-8.15.3
3. 配置文件检查(是否替换为了期望的配置文件):
cat config/elasticsearch.yml
4. JVM内存检查。
cat config/jvm.options |grep -E "Xms|Xmx"
5. 系统内存检查
sysctl -p
-- 如果输出没有:vm.max_map_count=262144
-- 执行指令追加配置到文件:echo "vm.max_map_count=262144" >> /etc/sysctl.conf
6. 默认文件数检查
ulimit -Hn
ulimit -Sn
--期望> 65535,否则执行以下指令:vim /etc/security/limits.conf 在 #End of file之前写入以下信息
* hard nofile 65536
* soft nofile 65536
7. 最后再次重新授权一下
chown -R elastic:elastic /opt/easy-cloud/elasticsearch-8.15.3
8. 启动新服务
su - elastic
cd /opt/easy-cloud/elasticsearch-8.15.3 && ./bin/elasticsearch -d
9. 生成并重置默认密码
bin/elasticsearch-reset-password -u elastic -i
bin/elasticsearch-users useradd easy-es -p easyES@123 -r superuser
10. 验证服务是否启动
curl -k -XGET -u elastic:elastic -k "https://127.0.0.1:9200"
-- 看到版本号8.15.3输出说明正常生成。
11. copy配置文件到目录(空环境easy-cloud-linux\es-config\elasticsearch.yml)
对比给出配置文件和当前配置文件(config/elasticsearch.yml)(验证先更改配置文件对应的证书无法生成)
12. 停止服务
pgrep -f -u elastic elasticsearch | xargs -r kill -15
13. 重新启动
./bin/elasticsearch -d

数据恢复

此时不要启动业务服务,不要让业务服务连接es并创建索引,否则索引相同会导致恢复失败。
1. 创建快照仓库
curl -k -u elastic:elastic -XPUT "https://localhost:9200/_snapshot/my_local_repo" -H "Content-Type: application/json" -d '{
"type": "fs",
"settings": {
"location": "/data/es/backup_repo",
"compress": true,
"chunk_size": "100mb"
}
}'
2. 从快照恢复指定索引(恢复前建议关闭目标索引,恢复后重新打开)
curl -k -u elastic:elastic -XPOST "https://localhost:9200/_snapshot/es_backup_repo/upgrade_backup_8.1.3/_restore?wait_for_completion=true" -H "Content-Type: application/json" -d '{
"indices": "*",
"include_global_state": true,
"ignore_unavailable": true,
"partial": false
}'
3. 报错:cannot restore index [hs_log_trace_20251205] because an open index with same name already exists in the cluster. Either close or delete the existing index or restore the index under a different name by providing a rename pattern and replacement name"
如果已经产生了索引,可以进行索引的删除或者关闭。
curl -k -XDELETE -u elastic:elastic -k "https://127.0.0.1:9200/[需要删除的索引id]?pretty"
-- 示例:curl -k -XDELETE -u elastic:elastic -k "https://127.0.0.1:9200/hs_log_trace_20251205?pretty"

功能验证:

  • 数据恢复后,数据条数验证。

  • 程序是否可以正常构建新的索引。

  • 数据能正常写入

版本回退

1. 停止新服务
pgrep -f -u elastic elasticsearch | xargs -r kill -15
2. 进入文件夹
cd /opt/hussar-cloud
3. 解压老版本数据(如果原始文件夹未删除可忽略)
tar -zxvf elasticsearch-8.1.3.tar.gz
4. 启动老服务
cd /opt/hussar-cloud/elasticsearch-8.1.3 && ./bin/elasticsearch -d
5. 验证服务正常启动(返回版本号8.1.3)
curl -k -XGET -u elastic:elastic -k "https://127.0.0.1:9200"
6. 风险点:
新版本的快照,老版本加载较慢,需要删除所有索引重新创建。新版本运行期间数据丢失。

备注:

1. 启动报错:java.nio.file.AccessDeniedException
没有权限,root账号执行:chown -R elastic:elastic /opt/hussar-cloud/elasticsearch-8.15.3
2. 启动报错:config/certs/transport.p12 because the file does not exist
缺少证书,从之前项目copy(config/certs目录)或者以下命令重新生成。
./bin/elasticsearch-certutil cert --self-signed -out config/certs/transport.p12 -pass "elastic"
./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
3. 如果https 访问报错时, 可以更改curl 的地址为http

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/28 11:09:59

Vim 常用快捷键速查

一、gf 快捷键说明gf(goto file)用于在普通模式下,跳转到光标所在位置的文件名对应的文件。使用场景: - 脚本中 include / source 的文件 - 日志、Makefile、Tcl、Verilog 中的文件路径如何退出 / 返回: 1. :q …

作者头像 李华
网站建设 2026/4/30 8:57:33

Linux系统下搭建TensorFlow-GPU深度学习环境

Linux系统下搭建TensorFlow-GPU深度学习环境 在现代AI研发中,一个稳定且高效的GPU加速训练环境几乎是标配。尤其是在企业级项目中,面对大规模数据和复杂模型,CPU训练动辄数天甚至数周,而借助NVIDIA GPU与CUDA生态的并行计算能力&…

作者头像 李华
网站建设 2026/4/29 13:19:08

Dify本地部署指南:源码与Docker双模式启动

Dify 本地部署实战:从源码到容器的完整搭建路径 在 AI 应用开发日益普及的今天,如何快速构建一个稳定、可扩展且支持复杂逻辑的 LLM 工具平台,成为开发者面临的核心挑战。Dify 正是为此而生——它不仅提供可视化编排界面,还深度整…

作者头像 李华
网站建设 2026/4/22 13:24:46

LLaMA-Factory框架参数详解

LLaMA-Factory框架参数详解 在大模型落地进入“工业化”阶段的今天,一个核心挑战浮出水面:如何让复杂的微调流程不再依赖专家级的手动调参和脚本拼接?当研究团队需要快速迭代多个LoRA适配器、产品部门希望将SFT与DPO对齐无缝衔接上线时&#…

作者头像 李华
网站建设 2026/4/30 16:54:20

飞拍进行相机选型计算

计算公式如下: 曝光时间 *物体运动速度 ≤ 运动方向精度需求 即(1/实际帧率) *物体运动速度 ≤ 运动方向精度需求 飞拍一般要求:精度要求拖影不超过 1/2像素 像素精度x 方向视野范围 / x 方向分辨率 运动精度曝光时间 *物体运动速度 计算像素精度 a , 运…

作者头像 李华