docker安装elasticsearch
命令
docker network create elastic
docker pull docker.elastic.co/elasticsearch/elasticsearch:9.3.3
docker run --name es01 --net elastic -p 9200:9200 -it -m 1GB docker.elastic.co/elasticsearch/elasticsearch:9.3.3
我用最简单、最直白的话给你讲清楚这 3 条命令,一看就懂:
1. docker network create elastic
作用:创建一个叫 elastic 的专属网络
- 让 Elasticsearch 容器在这个独立网络里运行
- 更安全、互不干扰,方便容器之间互相通信
- 大白话:给 Elasticsearch 单独建一个“小房间”
2. docker pull docker.elastic.co/elasticsearch/elasticsearch:9.3.3
作用:下载 Elasticsearch 9.3.3 镜像到本地
- 相当于下载安装包
- 不运行,只是把软件文件存到电脑里
- 大白话:把 Elasticsearch 下载到本地
3. docker run --name es01 --net elastic -p 9200:9200 -it -m 1GB ...
作用:启动一个 Elasticsearch 容器
我把参数拆开讲(超简单版):
--name es01:给容器起名叫 es01--net elastic:放进刚才创建的 elastic 网络里-p 9200:9200:把容器端口映射到电脑 9200,你浏览器/程序能访问-m 1GB:限制内存 1GB,防止吃满电脑- 最后是镜像名:用刚才下载的 9.3.3 版本启动
大白话:运行 Elasticsearch,让它能在 localhost:9200 访问
三句话总结(超级好记)
- 建网络 → 给 Elasticsearch 一个独立环境
- 下镜像 → 下载 Elasticsearch 安装包
- 启容器 → 运行 Elasticsearch,能在 9200 端口访问
总结
- 第1条:建网络环境
- 第2条:下载软件
- 第3条:启动服务
执行完这三条,你的 Elasticsearch 就跑起来啦!
启动之后,这些内容是干啥的
✅ Elasticsearch security features have been automatically configured!
✅ Authentication is enabled and cluster connections are encrypted.
ℹ️ Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
Lco6R*oClQMgUX=nHS9Y
ℹ️ HTTP CA certificate SHA-256 fingerprint:
fa397275a014ad34f426fd4f3e0d288eb20c4446fcb6b9df80364e7479ea6a28
ℹ️ Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjE0LjAiLCJhZHIiOlsiMTcyLjE5LjAuMjo5MjAwIl0sImZnciI6ImZhMzk3Mjc1YTAxNGFkMzRmNDI2ZmQ0ZjNlMGQyODhlYjIwYzQ0NDZmY2I2YjlkZjgwMzY0ZTc0NzllYTZhMjgiLCJrZXkiOiJpOVhlMXAwQldka1Z0TE5kbzFmWjpMLVZoYm9GaGN4WnFTZm1UNFpnZGtBIn0=
ℹ️ Configure other nodes to join this cluster:
• Copy the following enrollment token and start new Elasticsearch nodes with `bin/elasticsearch --enrollment-token <token>` (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjE0LjAiLCJhZHIiOlsiMTcyLjE5LjAuMjo5MjAwIl0sImZnciI6ImZhMzk3Mjc1YTAxNGFkMzRmNDI2ZmQ0ZjNlMGQyODhlYjIwYzQ0NDZmY2I2YjlkZjgwMzY0ZTc0NzllYTZhMjgiLCJrZXkiOiJpZFhlMXAwQldka1Z0TE5kbzFmVDpJSE5NRk9UZnNHb2RYZWNsX1BTWjVnIn0=
If you're running in Docker, copy the enrollment token and run:
`docker run -e "ENROLLMENT_TOKEN=<token>" docker.elastic.co/elasticsearch/elasticsearch:9.3.3`
这些内容到底是啥?(简单版)
它们是 Elasticsearch 自动给你生成的安全信息,
从 8.0+ 版本开始,默认开启安全,所以会自动生成:
账号、密码、证书、令牌。
逐行翻译(大白话)
✅ Elasticsearch security features have been automatically configured!
安全功能自动打开了!(密码、加密都开了)
✅ Authentication is enabled and cluster connections are encrypted.
必须用密码才能登录,传输数据也加密了
ℹ️ Password for the elastic user:
超级管理员账号 elastic 的密码
- 用户名:
elastic - 密码:
Lco6R*oClQMgUX=nHS9Y
你连接 Elasticsearch 必须用这个!
ℹ️ HTTP CA certificate SHA-256 fingerprint
证书指纹
- 用来验证你连的是真的 Elasticsearch
- 一般不用管,只有安全配置时才用
ℹ️ Configure Kibana to use this cluster:
给 Kibana(可视化面板)用的令牌
你以后装 Kibana 时,把这串令牌粘进去,就能一键连接 ES。
ℹ️ Configure other nodes to join this cluster:
给“其他 Elasticsearch 节点”加入集群用的令牌
你现在只跑了一个 ES,不用管。
你现在必须记住的只有 2 个
- 用户名:elastic
- 密码:Lco6R*oClQMgUX=nHS9Y
这两个是你访问 Elasticsearch 的钥匙。
怎么验证能不能用?
浏览器打开:
https://localhost:9200
会让你输入账号密码,就是上面那两个。
登录成功就说明 Elasticsearch 正常运行啦!
总结
这些输出 = 自动生成的安全凭证
你只需要记住:
账号:elastic
密码:Lco6R*oClQMgUX=nHS9Y
其他内容暂时不用管~
容器已经启动了。为啥访问9200端口,页面打不开
直接说核心原因+一步步解决,百分百能修好
一、核心原因(ES9.x 默认坑)
- ES 9.3.3 默认强制 HTTPS,你输的是
http://localhost:9200
✅ 正确地址:https://localhost:9200(必须加 s) - 开启了账号密码登录,裸访问直接拒绝
- Docker 容器内部安全策略,禁止匿名 HTTP 访问
二、马上测试(先验证通不通)
浏览器输入:
https://localhost:9200
- 会提示「连接不安全」,点高级 → 继续访问
- 然后弹窗输账号密码:
- 账号:
elastic - 密码:你刚才控制台看到的那串
- 账号:
三、如果还是打不开,排查3点
1. 先看容器是不是真正常运行
docker ps
看 es01 容器状态是不是 Up,9200 端口有没有映射
2. 关闭ES强制HTTPS(新手推荐,简单好用)
进入容器修改配置:
docker exec -it es01 /bin/bash
编辑配置文件
vi /usr/share/elasticsearch/config/elasticsearch.yml
加两行:
xpack.security.enabled: true
xpack.security.http.ssl.enabled: false
保存退出,重启容器:
exit
docker restart es01
之后直接用 http://localhost:9200 就能打开
3. 防火墙/本地端口占用
- 检查电脑有没有软件占用9200
- 关闭电脑防火墙测试
四、极简总结
- 打不开大概率是:用了 http ,ES 只认 https
- 临时方案:浏览器用
https://127.0.0.1:9200 - 长久方案:改配置关掉 https,只用 http 访问,开发最方便
怎么设置es开放http请求,不要强制https,也不要密码,或者密码我可以自己设置
我给你最简单、最稳妥、直接能用的方案,不用进容器、不用改文件,直接重新运行一条命令就能实现:
你要的效果:
- 关闭 HTTPS,只用 HTTP(http://localhost:9200)
- 关闭密码 / 或自定义密码
- 本地开发随便用,无限制
我直接给你一步到位的命令👇
先停掉旧容器(必须做)
docker stop es01
docker rm es01
方案 A:完全无密码 + 纯 HTTP(最适合开发)
复制直接运行:
docker run -d \
--name es01 \
--net elastic \
-p 9200:9200 \
-m 1GB \
-e "discovery.type=single-node" \
-e "xpack.security.enabled=false" \
-e "xpack.security.http.ssl.enabled=false" \
docker.elastic.co/elasticsearch/elasticsearch:9.3.3
✅ 效果:
- 无密码
- 直接访问 http://localhost:9200
- 不用登录,随便调用
方案 B:有密码 + 纯 HTTP(更安全一点)
docker run -d \
--name es01 \
--net elastic \
-p 9200:9200 \
-m 1GB \
-e "discovery.type=single-node" \
-e "xpack.security.enabled=true" \
-e "xpack.security.http.ssl.enabled=false" \
-e "ELASTIC_PASSWORD=123456" \
docker.elastic.co/elasticsearch/elasticsearch:9.3.3
✅ 效果:
- 账号:elastic
- 密码:123456(你可以自己改)
- 访问 http://localhost:9200
- 会弹框输密码
最重要的 2 个参数解释(一看就懂)
-
xpack.security.enabled=false
→ 关闭密码验证 -
xpack.security.http.ssl.enabled=false
→ 关闭 HTTPS,只开 HTTP
启动成功后怎么确认?
访问:
http://localhost:9200
直接出现 JSON,不用登录、不用 HTTPS ✅
总结
你直接用 方案 A 最舒服:
无密码 + 纯 HTTP + 本地开发随便用
更多推荐

所有评论(0)