View a markdown version of this page

禁用或启用 Apache ZooKeeper 客户端的直接访问 - Amazon Managed Streaming for Apache Kafka

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

禁用或启用 Apache ZooKeeper 客户端的直接访问

您可以禁用 Amazon MSK 预置集群上的 Apache ZooKeeper 客户端直接访问,以验证您的应用程序不依赖直接 ZooKeeper 连接。禁用 ZooKeeper 访问权限后,客户端将无法再通过端口 2181(纯文本)和 2182(TLS)连接到阿帕奇 ZooKeeper 节点。您可以随时重新启用 ZooKeeper 访问权限。

注意

此功能仅适用于使用 ZooKeeper 元数据模式和标准代理的 Amazon MSK 预置集群。它不适用于以下群集类型:

  • 在 Kraft 元数据模式下运行的集群

  • 使用 Express 代理的集群。 ZooKeeper 访问权限在 Express 集群中自动管理,无法手动配置。

  • 亚马逊 MSK 无服务器集群

使用控制台禁用 ZooKeeper 访问权限
  1. 登录并打开亚马逊 MSK 控制台 AWS 管理控制台,网址为?https://console.aws.amazon.com/msk/homeregion=us -east-1#/home/。

  2. 在集群列表中,选择要禁用 ZooKeeper 访问权限的集群。

  3. 选择属性选项卡,然后找到网络设置部分。

  4. 选择 “禁用 ZooKeeper 访问权限”

使用禁用 ZooKeeper 访问权限 AWS CLI
  1. 运行以下 AWS CLI 命令,将ClusterArnCurrent-Cluster-Version替换为 ARN 和当前版本的集群。要查找集群的当前版本,请使用DescribeCluster操作或 describe-clu AWS CLI ster 命令。示例版本是 KTVPDKIKX0DER

    aws kafka update-connectivity --cluster-arn ClusterArn --current-version Current-Cluster-Version --zookeeper-access '{"Enabled": false}'

    update-connectivity 命令的输出如以下 JSON 示例所示。

    { "ClusterArn": "arn:aws:kafka:us-east-1:012345678012:cluster/exampleClusterName/abcdefab-1234-abcd-5678-cdef0123ab01-2", "ClusterOperationArn": "arn:aws:kafka:us-east-1:012345678012:cluster-operation/exampleClusterName/abcdefab-1234-abcd-5678-cdef0123ab01-2/0123abcd-abcd-4f7f-1234-9876543210ef" }
    注意

    要重新启用 ZooKeeper 访问权限,请--zookeeper-access改用具有以下值的类似 AWS CLI 命令:

    '{"Enabled": true}'
  2. 要获得update-connectivity操作结果,请运行以下命令,ClusterOperationArn替换为您在update-connectivity命令输出中获得的 ARN。

    aws kafka describe-cluster-operation --cluster-operation-arn ClusterOperationArn

    describe-cluster-operation 命令的输出如以下 JSON 示例所示。

    { "ClusterOperationInfo": { "ClientRequestId": "982168a3-939f-11e9-8a62-538df00285db", "ClusterArn": "arn:aws:kafka:us-east-1:012345678012:cluster/exampleClusterName/abcdefab-1234-abcd-5678-cdef0123ab01-2", "CreationTime": "2026-01-15T21:08:57.735Z", "OperationArn": "arn:aws:kafka:us-east-1:012345678012:cluster-operation/exampleClusterName/abcdefab-1234-abcd-5678-cdef0123ab01-2/0123abcd-abcd-4f7f-1234-9876543210ef", "OperationState": "UPDATE_COMPLETE", "OperationType": "UPDATE_CONNECTIVITY", "SourceClusterInfo": { "ZookeeperAccess": { "Enabled": true } }, "TargetClusterInfo": { "ZookeeperAccess": { "Enabled": false } } } }

    如果 OperationState 的值为 UPDATE_IN_PROGRESS,请等待一段时间,然后再次运行 describe-cluster-operation 命令。

使用亚马逊 MSK API 禁用 ZooKeeper 访问权限
  • 要使用 API 禁用或启用对集群的 ZooKeeper 访问权限,请参阅UpdateConnectivity