> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-trino-dialect.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# BYOC 在 AWS 上的私有网络设置

> 为 AWS 上的 BYOC 配置 VPC 对等互连或 PrivateLink

export const Image = ({img, alt, size = "lg"}) => {
  const normalizedSize = ["sm", "md", "lg"].includes(size) ? size : "lg";
  return <div className={`ch-image-${normalizedSize}`}>
      <Frame>
        <img src={img} alt={alt} />
      </Frame>
    </div>;
};

ClickHouse BYOC on AWS 支持两种私有连接方式：VPC Peering 和 AWS PrivateLink。

<div id="common-prerequisites">
  ## 前置条件
</div>

VPC 对等互连 和 PrivateLink 均需执行的通用步骤。

<div id="step-enable-private-load-balancer-for-clickhouse-byoc">
  ### 为 ClickHouse BYOC 启用私有负载均衡器
</div>

在 ClickHouse Cloud 控制台中，为您的 BYOC 基础设施启用 **私有负载均衡器**。

<Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/wrAOYL3DquclMwbQ/images/cloud/reference/byoc-private-load-balancer.webp?fit=max&auto=format&n=wrAOYL3DquclMwbQ&q=85&s=c2d79269321210679ad00c0afe098632" size="md" alt="BYOC 启用私有负载均衡器" border width="2438" height="1724" data-path="images/cloud/reference/byoc-private-load-balancer.webp" />

<div id="aws-vpc-peering">
  ## 设置 VPC 对等互连
</div>

要为 ClickHouse BYOC 创建或删除 VPC 对等互连，请按以下步骤操作：

<Steps>
  <Step title="创建对等连接" id="step-1-create-a-peering-connection">
    1. 在 ClickHouse BYOC 账户中，前往 VPC 仪表板。
    2. 选择 Peering Connections。
    3. 点击 Create Peering Connection
    4. 将 VPC Requester 设置为 ClickHouse VPC ID。
    5. 将 VPC Accepter 设置为目标 VPC ID。 (如适用，选择另一个账户)
    6. 点击 Create Peering Connection。

    <Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/wrAOYL3DquclMwbQ/images/cloud/reference/byoc-vpcpeering-1.webp?fit=max&auto=format&n=wrAOYL3DquclMwbQ&q=85&s=367e59cf2d6f6c91d18c1582115039ae" size="lg" alt="BYOC 创建对等连接" border width="1600" height="1042" data-path="images/cloud/reference/byoc-vpcpeering-1.webp" />
  </Step>

  <Step title="接受对等连接请求" id="step-2-accept-the-peering-connection-request">
    前往对等账户后，客户可在 (VPC -> Peering connections -> Actions -> Accept request) 页面批准此 VPC 对等互连请求。

    <Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/wrAOYL3DquclMwbQ/images/cloud/reference/byoc-vpcpeering-2.webp?fit=max&auto=format&n=wrAOYL3DquclMwbQ&q=85&s=b5b55e354b03934a034f96c8fdcbf962" size="lg" alt="BYOC 接受对等连接" border width="1600" height="81" data-path="images/cloud/reference/byoc-vpcpeering-2.webp" />
  </Step>

  <Step title="将目标端添加到 ClickHouse VPC 路由表" id="step-3-add-destination-to-clickhouse-vpc-route-tables">
    在 ClickHouse BYOC 账户中，

    1. 在 VPC 仪表板中选择 Route Tables。
    2. 搜索 ClickHouse VPC ID，并编辑每个附加到私有子网的路由表。
    3. 点击 Routes 选项卡下的 Edit 按钮。
    4. 点击 Add another route。
    5. 在 Destination 中输入目标 VPC 的 CIDR 范围。
    6. 在 Target 中选择“Peering Connection”和该对等连接的 ID。

    <Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/wrAOYL3DquclMwbQ/images/cloud/reference/byoc-vpcpeering-3.webp?fit=max&auto=format&n=wrAOYL3DquclMwbQ&q=85&s=43d0d62630ef109fe147247fee58d3fa" size="lg" alt="BYOC 添加路由表" border width="1600" height="112" data-path="images/cloud/reference/byoc-vpcpeering-3.webp" />
  </Step>

  <Step title="将目标端添加到目标 VPC 路由表" id="step-4-add-destination-to-the-target-vpc-route-tables">
    在对等 AWS 账户中，

    1. 在 VPC 仪表板中选择 Route Tables。
    2. 搜索目标 VPC ID。
    3. 点击 Routes 选项卡下的 Edit 按钮。
    4. 点击 Add another route。
    5. 在 Destination 中输入 ClickHouse VPC 的 CIDR 范围。
    6. 在 Target 中选择“Peering Connection”和该对等连接的 ID。

    <Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/wrAOYL3DquclMwbQ/images/cloud/reference/byoc-vpcpeering-4.webp?fit=max&auto=format&n=wrAOYL3DquclMwbQ&q=85&s=687e12300dbe6429394128ff64efec72" size="lg" alt="BYOC 添加路由表" border width="1600" height="105" data-path="images/cloud/reference/byoc-vpcpeering-4.webp" />
  </Step>

  <Step title="编辑安全组以允许对等 VPC 访问" id="step-5-edit-security-group-to-allow-peered-vpc-access">
    在 ClickHouse BYOC 账户中，您需要更新安全组 (Security Group) 设置，以允许来自对等 VPC 的流量。请联系 ClickHouse 支持团队，请求添加包含对等 VPC CIDR 范围的入站规则。

    ***

    现在应已可从对等 VPC 访问 ClickHouse 服务。
  </Step>
</Steps>

要通过私网方式访问 ClickHouse，系统会预配私有负载均衡器和端点，以便用户从其对等 VPC 安全连接。专用终结点遵循公网端点的格式，并带有 `-private` 后缀。例如：

* **公网端点**: `h5ju65kv87.mhp0y4dmph.us-west-2.aws.clickhouse-byoc.com`
* **专用终结点**: `h5ju65kv87-private.mhp0y4dmph.us-west-2.aws.clickhouse-byoc.com`

可选：在确认对等连接正常工作后，您可以申请移除 ClickHouse BYOC 的公网负载均衡器。

<div id="setup-privatelink">
  ## 设置 PrivateLink
</div>

AWS PrivateLink 可为您的 ClickHouse BYOC 服务提供安全的私网连接，无需进行 VPC peering 或使用互联网网关。所有流量均在 AWS 网络内传输，确保不会经过公网。

<Note>
  **跨区域连接。** ClickHouse 控制台中的 **Enable private link** 开关会预配端点服务，但仅适用于**同一区域**的消费者。AWS 默认禁用端点服务的跨区域访问，ClickHouse 控制台也不会对此进行管理——如果您的客户端位于其他区域，需由您自行启用：端点服务位于您的 BYOC 账户中，因此请在您的 AWS 控制台中，将消费者所在区域添加到其 **Supported regions** 列表中 (请参阅下方第 3 步) 。ClickHouse 不会更改或重置这些配置值。AWS 跨区域数据传输费率适用。
</Note>

<Steps>
  <Step title="在 ClickHouse 控制台中启用 Private Link" id="step-1-enable-private-link">
    <Note>
      请确保已启用**私网负载均衡器**，这是前置条件。
    </Note>

    <Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/wrAOYL3DquclMwbQ/images/cloud/reference/byoc-privatelink.webp?fit=max&auto=format&n=wrAOYL3DquclMwbQ&q=85&s=0cce402678608f2f392274290212c7cb" size="md" alt="启用 BYOC PrivateLink" border width="2800" height="1848" data-path="images/cloud/reference/byoc-privatelink.webp" />
  </Step>

  <Step title={<>获取端点 <code>服务名称</code></>} id="step-2-obtain-endpoint-service-name">
    1. 在 ClickHouse Cloud 控制台中，前往要通过 PrivateLink 连接的服务的 Settings 页面。
    2. 点击“Set up private endpoint”。
    3. 在打开的弹出面板中，复制 `Service name` 的值——下一步会用到它。 (启用 PrivateLink 后，生成该值可能需要一段时间。)
           <Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/wrAOYL3DquclMwbQ/images/cloud/security/aws-privatelink-pe-create.webp?fit=max&auto=format&n=wrAOYL3DquclMwbQ&q=85&s=5a419857b24290742687f1c0f4e07d7e" size="md" alt="私有端点" border width="1556" height="740" data-path="images/cloud/security/aws-privatelink-pe-create.webp" />
  </Step>

  <Step title="在您的网络中创建端点" id="step-3-create-endpoint">
    1. 打开您的**自有 AWS 控制台** (即客户端应用程序所在 AWS 账户的控制台) → VPC → Endpoints → Create endpoints。

    2. 选择 "Endpoint services that use NLBs and GWLBs"，并使用上一步获取的 `Service name`。

    3. 单击 "Verify service"。
           <Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/wrAOYL3DquclMwbQ/images/cloud/security/aws-privatelink-endpoint-settings.webp?fit=max&auto=format&n=wrAOYL3DquclMwbQ&q=85&s=d3ef14b1b7a9842b73819b4b763f69b1" size="md" alt="AWS PrivateLink 端点设置" border width="1304" height="721" data-path="images/cloud/security/aws-privatelink-endpoint-settings.webp" />

    4. (可选) 如果要通过 PrivateLink 建立跨区域连接，请选中 "Cross region endpoint" 复选框，并指定服务区域。服务区域即创建 BYOC 基础设施的区域。同时：

    5. 打开您的**BYOC AWS 控制台** (即创建 BYOC 基础设施的 AWS 账户) → VPC → Endpoint services → `clickhouse-cloud-infra-xxx` → Supported regions。

    6. 将客户端应用程序所在的区域添加到支持区域列表中。默认仅支持该 BYOC 基础设施所在的区域。如果需要从不同区域连接，您可以添加多个区域；ClickHouse 不会更改或重置这些值。
           <Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/wrAOYL3DquclMwbQ/images/cloud/reference/byoc-privatelink-aws-cross-region.webp?fit=max&auto=format&n=wrAOYL3DquclMwbQ&q=85&s=d9a7131328330355dc74fa30e2684709" size="md" alt="AWS PrivateLink 跨区域端点设置" border width="3094" height="1820" data-path="images/cloud/reference/byoc-privatelink-aws-cross-region.webp" />

    7. 选择您的 VPC 和子网 (建议每个可用区选择一个子网) 。
           <Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/wrAOYL3DquclMwbQ/images/cloud/security/aws-privatelink-select-vpc-and-subnets.webp?fit=max&auto=format&n=wrAOYL3DquclMwbQ&q=85&s=ac8bd8e9e9a223db66a3db786e1ae25e" size="md" alt="选择 VPC 和子网" border width="1312" height="595" data-path="images/cloud/security/aws-privatelink-select-vpc-and-subnets.webp" />

    8. **重要**：为端点启用 "Private DNS names"——这是私有 DNS 正常工作所必需的。
       BYOC 端点的私有 DNS (使用 `*.vpce.{subdomain}` 格式) 利用 AWS PrivateLink 内置的 "Private DNS names" 功能。无需创建 Route53 记录；满足以下条件时，DNS 会自动解析：
       * 已启用 "Private DNS names"；且
       * 已启用 "DNS Hostnames"

         可在 VPC Settings → DNS resolution 和 DNS hostnames 中启用。

         这可确保使用 `vpce` 子域的连接自动经由 PrivateLink 端点路由，无需额外配置 DNS。

    9. (可选) 分配安全组 (Security Group) 和标签。

    <Note>
      确保安全组允许端口 `443`、`8443` 和 `9440`。
    </Note>

    8. 单击 "Create endpoint"，稍候片刻，等待端点创建完成。

    9. 创建端点后，复制 `Endpoint ID` 的值，您将在下一步中使用它。
           <Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/wrAOYL3DquclMwbQ/images/cloud/security/aws-privatelink-vpc-endpoint-id.webp?fit=max&auto=format&n=wrAOYL3DquclMwbQ&q=85&s=0914f5b17ad91500db5704a03546904e" size="md" alt="VPC 端点 ID" border width="467" height="212" data-path="images/cloud/security/aws-privatelink-vpc-endpoint-id.webp" />
  </Step>

  <Step title="批准端点连接请求" id="step-4-approve-endpoint-connection">
    1. 再次打开 **BYOC VPC 控制台** → Endpoint services → `clickhouse-cloud-infra-xxx` → Endpoint connections。
    2. 找到来自您自身 VPC 的连接请求，然后点击 "Accept endpoint connection request" 予以批准。
           <Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/wrAOYL3DquclMwbQ/images/cloud/reference/byoc-privatelink-2.webp?fit=max&auto=format&n=wrAOYL3DquclMwbQ&q=85&s=3dbd355ffd11bf590f9d84dc25be0751" size="md" alt="批准 BYOC PrivateLink" border width="1600" height="975" data-path="images/cloud/reference/byoc-privatelink-2.webp" />
  </Step>

  <Step title={<>将 <code>Endpoint ID</code> 添加到 ClickHouse 服务的允许列表</>} id="step-5-add-endpoint-id-to-services-allow-list">
    1. 在 ClickHouse Cloud 控制台中，前往要通过 PrivateLink 连接的服务的 Settings 页面。
    2. 点击“设置专用端点”。
    3. 在打开的弹出面板中，输入上一步获取的 `Endpoint ID`，并可选择添加说明。
    4. 点击“创建端点”。

    <Note>
      如需允许通过现有 PrivateLink 连接访问，请使用现有端点下拉列表。
      该下拉列表将显示同一基础设施中服务的现有 PrivateLink 连接。
    </Note>

    <Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/wrAOYL3DquclMwbQ/images/cloud/security/aws-privatelink-pe-filters.webp?fit=max&auto=format&n=wrAOYL3DquclMwbQ&q=85&s=8cbd609719e39e6c2fe16eba23145246" size="md" alt="专用端点过滤器" border width="1555" height="748" data-path="images/cloud/security/aws-privatelink-pe-filters.webp" />
  </Step>

  <Step title="通过 PrivateLink 访问实例" id="step-6-connect-via-privatelink">
    1. 在 ClickHouse Cloud 控制台中，前往服务的 Settings 页面。
    2. 点击“Set up private endpoint”。
    3. 在打开的弹出面板中，复制 `DNS name`。

           <Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/wrAOYL3DquclMwbQ/images/cloud/security/aws-privatelink-pe-dns-name.webp?fit=max&auto=format&n=wrAOYL3DquclMwbQ&q=85&s=e47aa556da6ec364b02f444fee1e5fbc" size="md" alt="专用终结点 DNS 名称" border width="1551" height="740" data-path="images/cloud/security/aws-privatelink-pe-dns-name.webp" />

       通过 PrivateLink 访问 ClickHouse 服务由以下两个层级控制：

       1. **Istio Authorization Policy**：由 ClickHouse 在您的 BYOC 基础设施中管理的服务级授权策略
       2. **VPC Endpoint Security Group**：关联到 VPC 端点的安全组，用于控制 VPC 中哪些资源可以使用该端点

           <Note>
             私网负载均衡器的“Enforce inbound rules on PrivateLink traffic”功能已禁用，因此访问仅受 Istio 授权策略和 VPC 端点安全组的控制。
           </Note>
  </Step>
</Steps>
