使用原生方式部署 ElasticSearch 9.3.2(非 Docker,含安全认证)

本文记录在 Ubuntu 系统中,通过 官方 deb 包 安装 ElasticSearch 9.3.2 的完整过程,并完成基础访问与认证配置。


一、环境说明

  • 操作系统:Ubuntu 20.04 / 22.04
  • 架构:x86_64
  • 安装方式:官方 .deb 包(非 Docker)

二、下载 ElasticSearch

1. 官方下载地址

本文选择:

elasticsearch-9.3.2-amd64.deb

三、安装 ElasticSearch

1. 安装命令

dpkg -i elasticsearch-9.3.2-amd64.deb

安装完成后不会自动启动服务,会提示:

NOT starting on installation

2. 启用 systemd 服务

执行:

sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service

3. 启动服务

sudo systemctl start elasticsearch.service

检查状态:

sudo systemctl status elasticsearch.service

四、首次访问与安全机制

1. 访问接口

curl -k https://localhost:9200

返回:

{
  "error": {
    "type": "security_exception",
    "reason": "missing authentication credentials"
  },
  "status": 401
}

说明

从 ElasticSearch 8.x 开始:

默认开启安全认证(TLS + 用户认证)

因此必须使用账号密码访问。


五、初始化账号密码

1. 重置 elastic 用户密码

执行:

/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic

2. 交互确认

Please confirm that you would like to continue [y/N] y

3. 获取密码

示例输出:

Password for the [elastic] user successfully reset.
New value: IzLvs*3MRbaBq4mnREc5

六、浏览器访问验证

访问:

https://<你的服务器IP>:9200/

例如:

https://192.168.100.156:9200/

输入:

  • 用户名:elastic
  • 密码:刚刚生成的密码

返回示例

{
  "name": "xiaonv6-host",
  "cluster_name": "elasticsearch",
  "cluster_uuid": "eFg-gaqDQAyqHJl6ttQNCQ",
  "version": {
    "number": "9.3.2",
    "lucene_version": "10.3.2"
  },
  "tagline": "You Know, for Search"
}

说明:

  • 服务已正常启动
  • HTTPS + 认证机制已生效

七、可选:关闭密码验证(仅限测试环境)

如果你只是本机测试、内网调试,暂时不想每次都输入用户名和密码,也可以关闭 ElasticSearch 的安全认证。

但要先说明:

  • 不建议在生产环境关闭
  • 不要直接暴露到公网
  • 关闭后访问方式通常会从 https 变成 http

1. 修改配置文件

编辑:

sudo vi /etc/elasticsearch/elasticsearch.yml

把安全认证关闭:

xpack.security.enabled: false

如果你是首次安装后由 Elastic 自动生成过安全配置,通常还会在 elasticsearch.yml 里看到一段自动写入的安全配置,例如 xpack.security.http.sslxpack.security.transport.ssl 相关内容。

这时候建议做法是:

  • 保留你自己的基础配置
  • 把自动生成的安全配置段注释掉或删除
  • 至少确保 xpack.security.enabled: false 已生效

2. 重启服务

sudo systemctl restart elasticsearch.service
sudo systemctl status elasticsearch.service

如果启动失败,优先查看日志:

sudo journalctl -u elasticsearch.service -n 200 --no-pager

3. 重新访问接口

关闭安全认证后,可以直接使用:

curl http://localhost:9200

正常情况下会直接返回版本信息,不再提示:

{
  "error": {
    "type": "security_exception",
    "reason": "missing authentication credentials"
  }
}

如果你之前一直使用的是:

curl -k https://localhost:9200

那么关闭认证后,通常要改成:

curl http://localhost:9200

也就是说,此时访问重点不再是“带密码的 HTTPS”,而是“无认证的 HTTP”。


4. 适合什么场景

更适合下面这些情况:

  • 本机开发测试
  • 临时内网调试
  • 不需要多用户权限控制的单机环境

如果后面你还要接入 Kibana、对外提供服务、或者部署到正式环境,还是建议重新开启安全认证。


八、插件检查

/usr/share/elasticsearch/bin/elasticsearch-plugin list

如果为空:

(无输出)

说明当前没有安装任何插件。


九、客户端工具(推荐)

ElasticVue

开源地址:

https://github.com/cars10/elasticvue/releases


使用方式

  1. 下载 Windows .msi
  2. 安装并启动
  3. 填写连接信息:
地址:https://你的IP:9200
用户名:elastic
密码:******

即可可视化管理:

  • Index
  • Document
  • Mapping
  • Query DSL

参考链接

在这里插入图片描述

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐