本文最后更新于54 天前,其中的信息可能已经过时,如有错误请发送邮件到3095478042@qq.com
以下部署来源于Elasticsearch 8.10安装 – 法老的内卫的小站,不过是windows版本,仅供个人参考
1. 安装 Elasticsearch
步骤 1:下载 Elasticsearch
访问 Elasticsearch 官方下载页面:
https://www.elastic.co/cn/downloads/elasticsearch
选择 Windows 版本的 8.10.0 下载:
- 下载
elasticsearch-8.10.0-windows-x86_64.zip
步骤 2:解压文件
- 将下载的 zip 文件解压到合适的位置,比如
C:\elasticsearch-8.10.0 - 或者使用 PowerShell 解压:
powershell
Expand-Archive -Path elasticsearch-8.10.0-windows-x86_64.zip -DestinationPath C:\
步骤 3:启动 Elasticsearch
方式一:命令行启动(推荐测试用)
- 打开命令提示符或 PowerShell
- 进入 Elasticsearch 目录:
cmd
cd C:\elasticsearch-8.10.0
- 启动 Elasticsearch:
cmd
.\bin\elasticsearch.bat
方式二:设置堆内存后启动
如果系统内存较小,可以设置堆内存:
cmd
set ES_JAVA_OPTS="-Xms2g -Xmx2g" .\bin\elasticsearch.bat
方式三:作为 Windows 服务安装(推荐生产用)
- 以管理员身份打开命令提示符
- 安装服务:
cmd
cd C:\elasticsearch-8.10.0 .\bin\elasticsearch-service.bat install
- 启动服务:
cmd
.\bin\elasticsearch-service.bat start
- 其他服务命令:
cmd
.\bin\elasticsearch-service.bat stop # 停止服务 .\bin\elasticsearch-service.bat remove # 删除服务
2. ES 安全功能配置
方法 1:使用 HTTPS 访问(推荐)
步骤 1:获取凭据
首次启动时,控制台会显示:
- 用户名:
elastic - 密码:自动生成的密码(请保存)
- CA 证书路径:
config/certs/http_ca.crt
步骤 2:使用 PowerShell 测试连接
powershell
# 使用 Invoke-RestMethod 测试连接 $credential = Get-Credential -UserName "elastic" -Message "Enter password" Invoke-RestMethod -Uri "https://localhost:9200" -Credential $credential -Certificate (Get-PfxCertificate -FilePath "config\certs\http_ca.crt")
步骤 3:使用 curl 测试(如果有 curl)
cmd
curl --cacert config/certs/http_ca.crt -X GET "https://localhost:9200" -u elastic:你的密码
方法 2:禁用安全功能(仅开发环境)
步骤 1:修改配置文件
编辑 config/elasticsearch.yml,添加或修改:
yaml
xpack.security.enabled: false xpack.security.http.ssl.enabled: false
步骤 2:重启 Elasticsearch
如果以服务方式运行:
cmd
.\bin\elasticsearch-service.bat stop .\bin\elasticsearch-service.bat start
如果以命令行方式运行,直接重启即可。
步骤 3:测试 HTTP 访问
cmd
curl -X GET "http://localhost:9200"
方法三:使用浏览器验证
打开 Chrome/Edge 浏览器
访问:https://localhost:9200
输入:
用户名:
密码:
3. 安装 IK 分词器插件
方式一:在线安装(推荐)
cmd
.\bin\elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.10.0/elasticsearch-analysis-ik-8.10.0.zip
但很遗憾,我这里执行失败了。
方式二:离线安装
- 下载 IK 分词器:
- 访问:infinilabs/analysis-ik: 🚌 The IK Analysis plugin integrates Lucene IK analyzer into Elasticsearch and OpenSearch, support customized dictionary.
- 下载
elasticsearch-analysis-ik-8.10.0.zip
- 本地安装:
cmd
.\bin\elasticsearch-plugin install file:///C:/path/to/elasticsearch-analysis-ik-8.10.0.zip
验证安装
重启 Elasticsearch 后,验证插件:
cmd
Invoke-RestMethod -Uri "http://localhost:9200/_cat/plugins?v" -Headers @{Authorization = "Basic $credential"}
4. 常见问题解决(可选)
JDK 要求
Elasticsearch 8.10.0 需要 JDK 17:
- 下载:https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html
- 或使用 OpenJDK:https://adoptium.net/
设置 JAVA_HOME
cmd
set JAVA_HOME=C:\Program Files\Java\jdk-17 set ES_JAVA_HOME=%JAVA_HOME%
端口冲突
如果 9200 端口被占用,修改 config/elasticsearch.yml:
yaml
http.port: 9201
内存设置
编辑 config/jvm.options:
text
-Xms2g -Xmx2g
5. 验证安装成功
测试 Elasticsearch 运行
cmd
curl -X GET "http://localhost:9200"
测试 IK 分词器
cmd
curl -X POST "http://localhost:9200/_analyze" -H "Content-Type: application/json" -d'
{
"analyzer": "ik_max_word",
"text": "程序员爱编程"
}'
应该返回类似:
json
{
"tokens": [
{"token": "程序员", "start_offset": 0, "end_offset": 3, "type": "CN_WORD", "position": 0},
{"token": "程序", "start_offset": 0, "end_offset": 2, "type": "CN_WORD", "position": 1},
{"token": "员", "start_offset": 2, "end_offset": 3, "type": "CN_CHAR", "position": 2},
{"token": "爱", "start_offset": 3, "end_offset": 4, "type": "CN_CHAR", "position": 3},
{"token": "编程", "start_offset": 4, "end_offset": 6, "type": "CN_WORD", "position": 4}
]
}
这样就完成了 Windows 系统下 Elasticsearch 8.10.0 的安装和 IK 分词器的配置!


