容器配置
2026年3月15日小于 1 分钟
基础配置
示例:
先进入正在运行的 es-single 容器:
docker exec -it es-single bash1配置单节点,基础配置完善
vi config/elasticsearch.yml添加 / 修改以下配置(确保是单节点模式):
# 默认配置
cluster.name: "docker-cluster"
network.host: 0.0.0.0
#新增
node.name: es-single
http.port: 9200
# 单节点配置
discovery.type: single-node2开启安全认证(用户名 / 密码)
xpack.security.enabled: true
xpack.security.http.ssl.enabled: false
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate重启生效
exit
docker restart es-single进入容器生成密码(自动生成,记住elastic的密码!)
docker exec -it es-single bash./bin/elasticsearch-setup-passwords auto
# 如果提示索引已存在,就用手动模式:
# ./bin/elasticsearch-setup-passwords interactive
exit验证
# 1. 验证安全认证(替换成你的密码)
curl -u elastic:你的密码 http://localhost:9200
# 2. 验证IK分词器
curl -u elastic:你的密码 http://localhost:9200/_cat/plugins
# 3. 验证单节点
curl -u elastic:你的密码 http://localhost:9200/_cat/nodes?v