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

配置项作用 #

cluster.remote.connect 配置项用于控制节点是否支持连接到远程集群。

当设置为 true 时,节点可以与配置的远程集群建立连接,支持跨集群搜索(CCS)功能。当设置为 false 时,节点将不会建立到任何远程集群的连接。

配置项属性 #

  • 配置路径: cluster.remote.connect
  • 数据类型: boolean
  • 默认值: true
  • 是否可选: 是
  • 弃用状态: 已标记为弃用(建议使用 cluster.remote.<cluster_name> 配置格式)

配置项详解 #

工作模式 #

启用模式(connect = true,默认) #

本地集群                远程集群
    │                        │
    │  ←────── 连接 ──────→  │
    │                        │
    │  跨集群搜索请求        │
    │  ←────── 查询 ──────→  │
    │                        │
    │  ←───── 返回结果 ────── │
    │                        │
  • 节点可以连接到配置的远程集群
  • 支持跨集群搜索语法(如 cluster1:index1,cluster2:index2
  • 作为协调节点时可以发起跨集群查询

禁用模式(connect = false) #

本地集群                远程集群
    │                        │
    │  ╳ 不建立连接          │
    │                        │
    │  跨集群搜索请求         │
    │  ╳ 失败(不支持)       │
    │                        │
  • 节点不会连接到任何远程集群
  • 使用远程集群语法的搜索请求将失败
  • 节点不承担远程集群客户端角色

节点角色影响 #

此配置影响节点是否获得 REMOTE_CLUSTER_CLIENT_ROLE 角色:

  • true: 节点具备远程集群客户端能力
  • false: 节点不具备远程集群客户端能力

配置建议 #

启用远程集群(默认) #

cluster.remote.connect: true

建议: 保持默认值 true,适用于需要跨集群搜索的场景。

禁用远程集群 #

cluster.remote.connect: false

建议: 设置为 false 的场景:

  • 节点只需要处理本地集群数据
  • 出于安全考虑,不允许跨集群访问
  • 节点资源有限,不需要承担远程连接开销
  • 纯数据节点,不承担协调节点角色

代码示例 #

easysearch.yml 配置 #

# 启用远程集群连接
cluster:
  remote:
    connect: true

# 配置具体的远程集群
cluster:
  remote:
    cluster_one:
      seeds: ["remote1.example.com:9300", "remote2.example.com:9300"]
    cluster_two:
      seeds: ["remote3.example.com:9300"]

禁用远程集群 #

# 完全禁用远程集群连接
cluster:
  remote:
    connect: false

新版配置方式(推荐) #

# 推荐使用新的配置格式
cluster:
  remote:
    production:
      seeds: ["prod-node1:9300", "prod-node2:9300"]
      mode: "sniff"
    dr:
      seeds: ["dr-node1:9300"]
      connect: false  # 可以针对特定集群禁用

相关配置 #

配置项作用默认值
cluster.remote.<name>.seeds远程集群的种子节点列表-
cluster.remote.connections_per_cluster每个远程集群的连接数3
cluster.remote.node.attr远程节点属性筛选-
cluster.remote.initial_connect_timeout初始连接超时时间30s
node.remote_cluster_client节点是否作为远程集群客户端true

跨集群搜索示例 #

启用远程集群后的搜索 #

# 搜索多个集群的索引
GET cluster1:index1,cluster2:index2/_search
{
  "query": {
    "match_all": {}
  }
}

# 搜索所有集群的索引
GET *,*:logs-*/_search
{
  "query": {
    "range": {
      "@timestamp": {
        "gte": "now-1d"
      }
    }
  }
}

禁用远程集群后的行为 #

# 如果 connect = false,以下请求将失败
GET cluster1:index1/_search
# 错误:No remote cluster matches the alias pattern

使用场景 #

推荐启用(connect = true) #

  • 多数据中心部署: 需要在多个数据中心的集群间进行联合查询
  • 数据湖架构: 中心集群需要查询多个边缘集群的数据
  • 灾备场景: 需要定期验证灾备集群的数据
  • 数据分析: 需要跨多个历史数据集群进行聚合分析

推荐禁用(connect = false) #

  • 纯数据节点: 只负责存储和查询本地数据
  • 安全隔离: 需要严格隔离集群间的访问
  • 资源限制: 节点资源有限,不承担跨集群连接开销
  • 单集群部署: 只有一个集群,无需跨集群功能

注意事项 #

  1. 配置已弃用: 此配置项已被标记为弃用,建议使用新的 cluster.remote.<cluster_name> 格式配置远程集群。

  2. 节点级别配置: 这是节点级别的配置,不同节点可以有不同的设置。

  3. 非动态配置: 修改此配置需要重启节点才能生效。

  4. 与种子节点的关系: 即使设置 connect = true,如果未配置远程集群的种子节点,也无法建立连接。

  5. 协调节点角色: 只有作为协调节点的节点才需要启用此配置,纯数据节点可以禁用以节省资源。

  6. 连接资源: 每个远程集群连接都会占用网络和内存资源,根据实际需求配置。