在 Amazon MSK LinkedIn 上使用 Apache Kafka 的巡航控制系统 - Amazon Managed Streaming for Apache Kafka

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

在 Amazon MSK LinkedIn 上使用 Apache Kafka 的巡航控制系统

您可以使用 LinkedIn的 Cruise Control 来重新平衡您的 Amazon MSK 集群、检测和修复异常以及监控集群的状态和运行状况。

下载并构建 Cruise Control
  1. 在与 Amazon MSK 集群相同的 Amazon VPC 中创建 Amazon EC2 实例。

  2. 在上一步中创建的 Amazon EC2 实例上安装 Prometheus。记下私有 IP 和端口。默认端口号为 9090。有关如何配置 Prometheus 以聚合集群指标的信息,请参阅 Prometheus 的开源监控系统

  3. 在 Amazon EC2 实例上下载 Cruise Control。(或者,如果您愿意,也可以针对 Cruise Control 使用单独的 Amazon EC2 实例。) 对于具有 Apache Kafka 版本 2.4.* 的集群,请使用最新的 2.4.* Cruise Control 版本。如果集群的 Apache Kafka 版本早于 2.4.*,请使用最新的 2.0.* Cruise Control 版本。

  4. 解压缩 Cruise Control 文件,然后转到解压缩后的文件夹。

  5. 运行以下命令以安装 Git:

    sudo yum -y install git
  6. 运行以下命令以初始化本地存储库。将 Your-Cruise-Control-Folder 替换为当前文件夹(解压缩 Cruise Control 下载文件时获得的文件夹)的名称。

    git init && git add . && git commit -m "Init local repo." && git tag -a Your-Cruise-Control-Folder -m "Init local version."
  7. 运行以下命令以安装并构建源代码。

    ./gradlew jar copyDependantLibs
配置和运行 Cruise Control
  1. config/cruisecontrol.properties 文件进行以下更新。将示例引导服务器和引导代理字符串替换为集群的值。要获取集群的这些字符串,您可以在控制台中查看集群详细信息。或者,您可以使用GetBootstrapBrokersDescribeClusterAPI 操作或它们的 CLI 等效操作。

    # If using TLS encryption, use 9094; use 9092 if using plaintext bootstrap.servers=b-1.test-cluster.2skv42.c1.kafka.us-east-1.amazonaws.com:9094,b-2.test-cluster.2skv42.c1.kafka.us-east-1.amazonaws.com:9094,b-3.test-cluster.2skv42.c1.kafka.us-east-1.amazonaws.com:9094 # SSL properties, needed if cluster is using TLS encryption security.protocol=SSL ssl.truststore.location=/home/ec2-user/kafka.client.truststore.jks # Use the Prometheus Metric Sampler metric.sampler.class=com.linkedin.kafka.cruisecontrol.monitor.sampling.prometheus.PrometheusMetricSampler # Prometheus Metric Sampler specific configuration prometheus.server.endpoint=1.2.3.4:9090 # Replace with your Prometheus IP and port # Change the capacity config file and specify its path; details below capacity.config.file=config/capacityCores.json
  2. 编辑 config/capacityCores.json 文件以指定正确的磁盘大小、CPU 核心和网络输入/输出限制。您可以使用 DescribeClusterAPI 操作(或其等效的 CLI)来获取磁盘大小。有关 CPU 核心和网络输入/输出限制,请参阅 Amazon EC2 实例类型

    { "brokerCapacities": [ { "brokerId": "-1", "capacity": { "DISK": "10000", "CPU": { "num.cores": "2" }, "NW_IN": "5000000", "NW_OUT": "5000000" }, "doc": "This is the default capacity. Capacity unit used for disk is in MB, cpu is in number of cores, network throughput is in KB." } ] }
  3. 您可以选择安装 Cruise Control UI。如需下载,请转到 Setting Up Cruise Control Frontend

  4. 运行以下命令以启动 Cruise Control。考虑使用类似 screentmux 的工具来保持长时间运行的会话处于开放状态。

    <path-to-your-kafka-installation>/bin/kafka-cruise-control-start.sh config/cruisecontrol.properties 9091
  5. 使用 Cruise Control API 或 UI 来确保 Cruise Control 拥有集群加载数据并提出重新平衡建议。获得有效的指标窗口可能需要几分钟时间。

适用于 Amazon MSK 的巡航控制系统的自动部署模板

您还可以使用此CloudFormation 模板轻松部署 Cruise Control 和 Prometheus,从而更深入地了解您的 Amazon MSK 集群的性能并优化资源利用率。

主要功能:
  • 自动配置预配置巡航控制和 Prometheus 的 Amazon EC2 实例。

  • 支持 Amazon MSK 预配置集群。

  • 使用PlainText 和 IAM 进行灵活的身份验证。

  • Cruise Control 不依赖动物园管理员。

  • 通过提供存储在 Amazon S3 存储桶中的您自己的配置文件,轻松自定义 Prometheus 目标、巡航控制容量设置和其他配置。