📣 极限科技诚招搜索运维工程师(Elasticsearch/Easysearch)- 全职/北京 👉 : 立即申请加入

配置项作用 #

http.publish_port 配置项指定向客户端发布的 HTTP 服务端口号,用于内部端口与外部端口不一致的场景。

是否可选 #

默认值 #

-1 (自动检测,使用 http.port 的值)

配置项类型 #

静态配置 - 需要重启节点才能生效

配置格式 #

# 自动检测(默认)
http.publish_port: -1

# NAT 端口转发
http.port: 9200
http.publish_port: 80

# 容器端口映射
http.port: 80
http.publish_port: 9200

与 http.port 的关系 #

┌─────────────────────────────────────────────────────────┐
│                   http.port vs publish_port               │
└─────────────────────────────────────────────────────────┘

http.port                    http.publish_port
     │                              │
     ▼                              ▼
  实际监听端口                    对外发布的端口
  (服务绑定)                      (客户端使用)

     │                              │
     └──────────┐           ┌───────┘
                │           │
                ▼           ▼
            [内部网络]   [外部网络]

示例:NAT 环境
http.port: 9200          http.publish_port: 80
(内网端口)                (公网端口)

推荐设置 #

场景推荐值说明
默认配置-1自动检测
NAT 环境外部端口客户端使用外部端口
容器环境主机端口容器端口映射
端口转发转发后端口负载均衡器端口

使用示例 #

默认配置:

http.port: 9200
http.publish_port: -1  # 自动使用 9200

NAT 环境配置:

# 内网监听 9200,外网访问 80
http.port: 9200
http.publish_port: 80

容器环境配置:

# 容器内 80,映射到主机 9200
http.port: 80
http.publish_port: 9200

负载均衡环境:

http.port: 9200
http.publish_port: 9200
http.publish_host: search.example.com

配置验证 #

# 查看发布端口
GET /_nodes?filter_path=nodes.*.http.publish_port

# 查看完整 HTTP 信息
GET /_nodes/http

常见问题 #

问题 1:客户端无法连接

原因:

  • 发布的端口不正确
  • 客户端使用了错误的端口

解决方案:

# 设置正确的发布端口
http.publish_port: 80

问题 2:端口范围自动检测失败

解决方案:

# 明确设置发布端口
http.port: 9200-9210
http.publish_port: 9200

自动检测逻辑 #

http.publish_port = -1
    │
    ▼
检查 http.port
    │
    ├── 单个端口 → 使用该端口
    └── 端口范围
        │
        ├── 所有地址使用相同端口 → 使用该端口
        └── 不同端口 → 报错

注意事项 #

  1. 静态配置:修改端口需要重启节点
  2. 端口冲突:确保发布端口未被占用
  3. 可达性:确保客户端能访问发布的端口
  4. 一致性:集群节点应使用一致的配置
  5. 自动检测:-1 值会自动使用 http.port

相关配置项 #

配置项默认值说明
http.port9200-9300实际监听端口
http.publish_host[]发布主机地址
transport.publish_port-1传输发布端口

完整配置示例 #

# easysearch.yml

# NAT 环境配置
http.port: 9200
http.publish_port: 80
http.publish_host: search.example.com

# 容器环境配置
http.port: 80
http.publish_port: 9200
http.publish_host: localhost

# 默认配置
http.port: 9200
http.publish_port: -1