配置专用池

处理直播需要管理多个组件,这些组件负责执行提取、转码和多路复用等任务。Live Stream API 会使用在内部管理这些组件和资源。池是指为每个 Google Cloud 项目在每个区域分配的处理单元,并在给定区域的所有渠道之间共享。

默认情况下,当您创建 Input 资源时,系统会为您提供一个包含公共 IP 地址的端点 URI,您可以将输入数据流发送到该地址。无论您是从本地网络还是 Google Cloud 虚拟私有云 (VPC) 网络进行流式传输,数据都会穿越公共互联网才能到达直播服务端点。

流式传输到公共互联网。

或者,您也可以设置对直播服务的专用服务访问权限。专用服务访问通道是您的Google Cloud 虚拟私有云 (VPC) 网络与 Google 代管式服务或第三方服务之间的安全专用连接。通过此连接,您的 VPC 网络中的虚拟机实例可以使用内部 IP 地址与这些服务通信,而无需将流量公开到互联网。在 Live Stream API 中启用专用服务访问权限后,系统会从您的 VPC 网络中预留一个内部 IP 地址,以用作输入端点。这样做具有以下优势:

  • 增强的安全性:借助专用服务访问通道,您无需将流量公开到互联网,即可连接到 Live Stream API 输入端点。这有助于改善您的安全状况并降低数据泄露风险。
  • 提高性能:专用服务访问通道可避免使用公共互联网,从而提高连接性能。这对于实现更低的延迟时间和更高的吞吐量特别有益。

您还可以将专用服务访问权限与 Cloud Interconnect 或 Cloud VPN 搭配使用,以便在本地网络和直播服务之间建立端到端私有连接。

流式传输到专用端点。

准备工作

如需配置专用池,请先满足以下前提条件:

  • 您必须有一个可用于接入服务提供方网络的现有 VPC 网络。虚拟机实例必须使用此 VPC 网络通过专用连接接入服务。
  • 您必须在 VPC 网络上配置专用服务访问通道
  • 必须停止该区域中的所有频道,否则 Live Stream API 会拒绝更新池的对等网络的请求。
  • 在更新广告资源池期间,该区域中的所有渠道都无法启动。

配置专用池

  1. 确保已创建默认池。当您创建第一个 Input 资源时,系统会为相应位置创建默认池。

    在使用任何请求数据之前,请先进行以下替换:

    • PROJECT_NUMBER:您的 Google Cloud 项目编号;此值位于 IAM 设置页面上的“项目编号”字段中
    • LOCATION:使用您已在其中创建输入的受支持的地区之一
      • us-central1
      • us-east1
      • us-east4
      • us-west1
      • us-west2
      • northamerica-northeast1
      • southamerica-east1
      • asia-east1
      • asia-east2
      • asia-south1
      • asia-northeast1
      • asia-southeast1
      • australia-southeast1
      • europe-north1
      • europe-west1
      • europe-west2
      • europe-west3
      • europe-west4

    如需发送您的请求,请展开以下选项之一:

    执行以下命令:

    curl -X GET \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/pools/default"

    执行以下命令:

    $cred = gcloud auth print-access-token
    $headers = @{ "Authorization" = "Bearer $cred" }

    Invoke-WebRequest `
    -Method GET `
    -Headers $headers `
    -Uri "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/pools/default" | Select-Object -Expand Content

    您应该收到类似以下内容的 JSON 响应:

    {
      "name": "projects/PROJECT_NUMBER/locations/LOCATION/pools/default",
      "createTime": CREATE_TIME,
      "updateTime": UPDATE_TIME
    }
    

  2. 使用对等网络名称更新池。

    在使用任何请求数据之前,请先进行以下替换:

    • PROJECT_NUMBER:您的 Google Cloud 项目编号;此值位于 IAM 设置页面上的“项目编号”字段中
    • LOCATION:默认池的位置;请使用某个受支持的地区
      • us-central1
      • us-east1
      • us-east4
      • us-west1
      • us-west2
      • northamerica-northeast1
      • southamerica-east1
      • asia-east1
      • asia-east2
      • asia-south1
      • asia-northeast1
      • asia-southeast1
      • australia-southeast1
      • europe-north1
      • europe-west1
      • europe-west2
      • europe-west3
      • europe-west4
    • NETWORK:当前项目中要与服务对等互连的网络的用户定义标识符

    如需发送您的请求,请展开以下选项之一:

    将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

    cat > request.json << 'EOF'
    {
      "networkConfig": {
        "peeredNetwork": "projects/PROJECT_NUMBER/global/networks/NETWORK"
      }
    }
    EOF

    然后,执行以下命令以发送 REST 请求:

    curl -X PATCH \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    -d @request.json \
    "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/pools/default?updateMask=networkConfig"

    将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

    @'
    {
      "networkConfig": {
        "peeredNetwork": "projects/PROJECT_NUMBER/global/networks/NETWORK"
      }
    }
    '@  | Out-File -FilePath request.json -Encoding utf8

    然后,执行以下命令以发送 REST 请求:

    $cred = gcloud auth print-access-token
    $headers = @{ "Authorization" = "Bearer $cred" }

    Invoke-WebRequest `
    -Method PATCH `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/pools/default?updateMask=networkConfig" | Select-Object -Expand Content

    您应该收到类似以下内容的 JSON 响应:

    {
      "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID",
      "metadata": {
        "@type": "type.googleapis.com/google.cloud.video.livestream.v1.OperationMetadata",
        "createTime": CREATE_TIME,
        "target": "projects/PROJECT_NUMBER/locations/LOCATION/pools/default",
        "verb": "update",
        "requestedCancellation": false,
        "apiVersion": "v1"
      },
      "done": false
    }
    

    该请求会启动一项长时间运行的操作。复制返回的 OPERATION_ID 以供下一步使用。

  3. 使用 projects.locations.operations.get 方法检查更新是否已完成。更新池最多可能需要 30 分钟才能完成。如果响应包含 "done: false",请重复请求,直到响应包含 "done: true"

    在使用任何请求数据之前,请先进行以下替换:

    • PROJECT_NUMBER:您的 Google Cloud 项目编号;此值位于 IAM 设置页面上的“项目编号”字段中
    • LOCATION:资源所在的位置;请使用某个受支持的地区
      • us-central1
      • us-east1
      • us-east4
      • us-west1
      • us-west2
      • northamerica-northeast1
      • southamerica-east1
      • asia-east1
      • asia-east2
      • asia-south1
      • asia-northeast1
      • asia-southeast1
      • australia-southeast1
      • europe-north1
      • europe-west1
      • europe-west2
      • europe-west3
      • europe-west4
    • OPERATION_ID:操作的标识符

    如需发送您的请求,请展开以下选项之一:

    执行以下命令:

    curl -X GET \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID"

    执行以下命令:

    $cred = gcloud auth print-access-token
    $headers = @{ "Authorization" = "Bearer $cred" }

    Invoke-WebRequest `
    -Method GET `
    -Headers $headers `
    -Uri "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID" | Select-Object -Expand Content

    您应该收到类似以下内容的 JSON 响应:

    {
      "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID",
      "metadata": {
        "@type": "type.googleapis.com/google.cloud.video.livestream.v1.OperationMetadata",
        "createTime": CREATE_TIME,
        "endTime": END_TIME,
        "target": "projects/PROJECT_NUMBER/locations/LOCATION/pools/default",
        "verb": "update",
        "requestedCancellation": false,
        "apiVersion": "v1"
      },
      "done": true,
      "response": {
        "@type": "type.googleapis.com/google.cloud.video.livestream.v1.Pool",
        "name": "projects/PROJECT_NUMBER/locations/LOCATION/pools/default",
        "createTime": CREATE_TIME,
        "updateTime": UPDATE_TIME,
        "networkConfig": {
          "peeredNetwork": "projects/PROJECT_NUMBER/global/networks/NETWORK"
        }
      }
    

更新后,该区域中现有(和未来)输入端点的所有 URI 都是从所提供的 VPC 网络中预留的内部 IP 地址。列出输入端点,查看更新后的 URI。

切换到公共池

如需恢复为公共池,请在更新池请求中提供空字符串作为对等网络名称。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_NUMBER:您的 Google Cloud 项目编号;此值位于 IAM 设置页面上的“项目编号”字段中
  • LOCATION:默认池的位置;请使用某个受支持的地区
    • us-central1
    • us-east1
    • us-east4
    • us-west1
    • us-west2
    • northamerica-northeast1
    • southamerica-east1
    • asia-east1
    • asia-east2
    • asia-south1
    • asia-northeast1
    • asia-southeast1
    • australia-southeast1
    • europe-north1
    • europe-west1
    • europe-west2
    • europe-west3
    • europe-west4

如需发送您的请求,请展开以下选项之一:

将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

cat > request.json << 'EOF'
{
  "networkConfig": {
    "peeredNetwork": ""
  }
}
EOF

然后,执行以下命令以发送 REST 请求:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/pools/default?updateMask=networkConfig"

将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

@'
{
  "networkConfig": {
    "peeredNetwork": ""
  }
}
'@  | Out-File -FilePath request.json -Encoding utf8

然后,执行以下命令以发送 REST 请求:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://livestream.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/pools/default?updateMask=networkConfig" | Select-Object -Expand Content

您应该收到类似以下内容的 JSON 响应:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.video.livestream.v1.OperationMetadata",
    "createTime": CREATE_TIME,
    "target": "projects/PROJECT_NUMBER/locations/LOCATION/pools/default",
    "verb": "update",
    "requestedCancellation": false,
    "apiVersion": "v1"
  },
  "done": false
}

您可以再次使用 projects.locations.operations.get 方法检查更新是否已完成。