elasticsearch安装教程,-Elasticsearch 在 Windows安装 - logs:
以下是 Elasticsearch 在 Windows 系统上的详细下载安装指南:
一、准备工作
系统要求
操作系统:Windows 10/11 或 Windows Server 2016+Java 环境:Elasticsearch 8.x 需要 JDK 17+(自带 JDK,也可自定义)内存:至少 4GB RAM,推荐 8GB+存储:至少 2GB 可用空间
二、下载 Elasticsearch
方式1:官网下载(推荐)
访问 Elastic 官网下载页选择 Windows 平台点击 Download(8.x版本包含免费安全功能)文件格式为 .zip 压缩包(约 600MB)
方式2:直接下载链接
当前最新版(8.x):https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.13.4-windows-x86_64.zip
历史版本:可在官网选择其他版本
三、安装步骤
步骤1:解压文件
将下载的 elasticsearch-8.x.x-windows-x86_64.zip 解压到任意目录
例如:C:\Elasticsearch\ 或 D:\Programs\elasticsearch-8.x.x\路径避免中文和空格
步骤2:配置环境变量(可选)
右键“此电脑” → 属性 → 高级系统设置 → 环境变量在 系统变量 中编辑 Path,添加 Elasticsearch 的 bin 目录路径:C:\Elasticsearch\elasticsearch-8.x.x\bin
方便后续命令行直接使用 elasticsearch 命令
步骤3:调整配置(重要)
编辑 config/elasticsearch.yml:
# 集群名称(单机可保持默认)
cluster.name: my-elasticsearch
# 节点名称
node.name: node-1
# 数据存储路径(确保目录存在且有权限)
path.data: ./data
# 日志路径
path.logs: ./logs
# 网络绑定(允许外部访问)
network.host: 0.0.0.0
# HTTP 端口(默认 9200)
http.port: 9200
# 集群初始主节点(单机部署)
cluster.initial_master_nodes: ["node-1"]
# 安全功能(8.x默认开启,学习时可关闭)
xpack.security.enabled: false
⚠️ 生产环境务必开启安全配置(用户名/密码)
四、启动 Elasticsearch
方式1:命令行启动(推荐)
以 管理员身份 打开命令提示符(CMD)或 PowerShell进入 Elasticsearch 的 bin 目录:cd C:\Elasticsearch\elasticsearch-8.x.x\bin
启动服务:# 前台运行(显示日志)
elasticsearch.bat
# 或后台运行
elasticsearch-service.bat install # 安装为Windows服务
elasticsearch-service.bat start # 启动服务
方式2:作为 Windows 服务安装
# 安装服务
elasticsearch-service.bat install
# 启动服务
elasticsearch-service.bat start
# 停止服务
elasticsearch-service.bat stop
# 卸载服务
elasticsearch-service.bat remove
服务管理:
也可以在 services.msc 中搜索 “Elasticsearch” 服务进行管理
五、验证安装
1. 检查服务状态
访问浏览器或使用 curl:
http://localhost:9200/
成功响应示例:
{
"name" : "node-1",
"cluster_name" : "my-elasticsearch",
"cluster_uuid" : "xxxxxx",
"version" : {
"number" : "8.13.4",
"build_flavor" : "default",
"build_type" : "zip",
"build_hash" : "xxxxxx",
"build_date" : "2024-xx-xx",
"build_snapshot" : false,
"lucene_version" : "xx.x.x",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
2. 查看集群健康状态
http://localhost:9200/_cluster/health
六、常见问题与解决
问题1:Java 版本不兼容
症状:启动时提示 Java 版本错误解决:
安装 JDK 17+ 并设置 JAVA_HOME 环境变量或使用 Elasticsearch 自带的 JDK(在 jdk 目录中)
问题2:端口冲突(9200/9300)
症状:启动失败,端口被占用解决:
修改 elasticsearch.yml 中的端口号或关闭占用端口的程序:netstat -ano | findstr :9200
taskkill /PID <进程ID>/F
问题3:内存不足
症状:启动时崩溃,日志显示内存错误解决:
编辑 config/jvm.options:# 初始堆大小(根据机器内存调整)
-Xms1g
# 最大堆大小(建议不超过物理内存的50%)
-Xmx1g
32位系统需使用 Elasticsearch 6.x 或更低版本
问题4:文件权限不足
症状:无法创建数据/日志目录解决:
以管理员身份运行命令行或修改 elasticsearch.yml 中的路径到有权限的目录
问题5:无法远程访问
症状:localhost 可访问,但 IP 无法访问解决:
确保防火墙允许端口 9200:netsh advfirewall firewall add rule name="Elasticsearch" dir=in action=allow protocol=TCP localport=9200
确认 elasticsearch.yml 中 network.host: 0.0.0.0
七、安装 Kibana(可选可视化工具)
步骤:
下载 Kibana Windows 版解压并编辑 kibana.yml:server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://localhost:9200"]
运行 bin\kibana.bat访问 http://localhost:5601
八、生产环境建议
安全配置(必须)
启用内置安全功能:# 启动时自动生成密码
elasticsearch-keystore add bootstrap.password
或手动设置:xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
性能优化
调整 JVM 堆大小(jvm.options)禁用交换文件:bootstrap.memory_lock: true
配置合适的垃圾回收器
九、常用命令速查
# 启动(前台)
elasticsearch.bat
# 服务管理
elasticsearch-service.bat install/start/stop/remove
# 检查节点
curl http://localhost:9200/_cat/nodes?v
# 创建索引
curl -X PUT "localhost:9200/my_index"
# 删除索引
curl -X DELETE "localhost:9200/my_index"
总结 拼多多帮助力入口
项目说明安装方式ZIP 解压版(Windows 无 MSI 安装包)默认端口HTTP: 9200, 集群通信: 9300数据目录./data(相对安装路径)配置文件config/elasticsearch.yml启动方式命令行运行或安装为 Windows 服务首次访问http://localhost:9200
异常解决缺少包 https://download.oracle.com/otn/java/jdk/8u202-b08/1961070e4c9b4e26a04e7f5a083f551e/jdk-8u202-linux-i586.tar.gz?AuthParam=1768361617_ec805dc221d5309cfb64312f70c8766e
\elasticsearch-8.13.4\config\elasticsearch.yml
# ------------------------ 基本配置 ------------------------
# 节点名称(可自定义)
node.name: "single-node"
# 网络配置(仅本地访问)
network.host: 0.0.0.0
http.port: 9200
# ------------------------ 数据存储 ------------------------
path.data: ./data
path.logs: ./logs
# ------------------------ 单机模式关键配置 ------------------------
# 关闭集群发现,强制单节点模式
discovery.type: single-node
# 单节点模式无需配置初始主节点
# cluster.initial_master_nodes: [] # 注释掉或删除
# ------------------------ 性能优化(可选) ------------------------
# 减少内存使用
bootstrap.memory_lock: false
# 调整线程池(单机可减少)
thread_pool.search.size: 3
thread_pool.search.queue_size: 200
# ------------------------ 安全配置 ------------------------
# 开发学习时关闭安全(简化访问)
xpack.security.enabled: false
xpack.security.transport.ssl.enabled: false
# 关闭其他不需要的功能(减少资源占用)
xpack.ml.enabled: false
xpack.watcher.enabled: false
xpack.graph.enabled: false
xpack.security.http.ssl.enabled: false
\elasticsearch-8.13.4\bin\start-es-isolated.bat
@echo off
REM ====== 1. 彻底清空所有 Java 相关变量 ======
set JAVA_HOME=
set JDK_HOME=
set ES_JAVA_HOME=
REM ====== 2. 明确只给 Elasticsearch 指一条路 ======
set ES_JAVA_HOME=D:\Program\elasticsearch-8.13.4\jdk
REM ====== 3. 切断 PATH 中的 Java ======
set PATH=%SystemRoot%\system32;%SystemRoot%
REM ====== 4. 启动 ======
cd /d D:\Program\elasticsearch-8.13.4
bin\elasticsearch.bat
推荐新版本 https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-9.2.4-windows-x86_64.zip
elasticsearch.yml
cluster.name: elasticsearch
node.name: node-1
discovery.type: single-node
network.host: 192.168.3.122
http.port: 9200
xpack.security.enabled: true
设置密码: .\elasticsearch-reset-password.bat -u elastic -i,elasticsearch安装教程