You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法连接TLS启用的AWS MSK Kafka集群,创建主题超时求助

问题:本地Windows机器无法连接启用TLS的AWS MSK Kafka集群

我希望从本地Windows机器连接启用TLS的AWS MSK Kafka集群,已通过CloudFormation配置集群的TLS加密,配置如下:

EncryptionInfo:
  EncryptionInTransit:
    ClientBroker: TLS
    InCluster: True

按照AWS官方文档配置客户端TLS,复制本地Java信任库cacerts到指定路径,创建了client.properties配置文件:

security.protocol=SSL
ssl.truststore.location=C:\\Program Files (x86)\\Java\\jre-1.8\\lib\\security\\cacerts
ssl.endpoint.identification.algorithm=https
ssl.truststore.password=changeit

执行创建主题命令:

kafka-topics.bat --create --bootstrap-server b-2.xxx.amazonaws.com:9094,b-1.xxx.amazonaws.com:9094 --command-config client.properties --replication-factor 2 --partitions 1 --topic TLSTestTopic

但出现超时错误:

E:\kafka_2.13-3.2.1\bin\windows>kafka-topics.bat --create --bootstrap-server  b-2.xxx.amazonaws.com:9094,b-1.xxx.amazonaws.com:9094 --command-config client.properties --replication-factor 2 --partitions 1 --topic TLSTestTopic
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/E:/kafka_2.13-3.2.1/libs/slf4j-reload4j-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/E:/Edifecs/TM/sdk/lib/log4j-slf4j-impl-2.17.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Reload4jLoggerFactory]
[2023-07-18 00:03:52,275] WARN [AdminClient clientId=adminclient-1] Connection to node -1 (b-2.kafkatlsmskcluster.1lyy3o.c14.kafka.us-west-2.amazonaws.com/10.151.46.36:9094) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
Error while executing topic command : Timed out waiting for a node assignment. Call: createTopics
[2023-07-18 00:04:14,090] ERROR org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment. Call: createTopics
 (kafka.admin.TopicCommand$)

我已在相关安全组入站规则中放行TLS端口9094,请问遗漏了什么?使用Java信任库应该可行吧?


解决方案

1. 核心问题:MSK集群未开启公网访问,本地无法访问私有IP

从错误日志可见,客户端尝试连接的是MSK Broker的私有IP(10.151.46.36),本地Windows机器处于公网环境,无法直接访问VPC内的私有地址。

  • 解决步骤:
    • 登录AWS控制台进入MSK集群详情页,在「联网」选项卡开启公网访问。
    • 开启后,复制生成的公网Broker端点替换原命令中的bootstrap-server地址。
    • 更新安全组入站规则,将本地Windows机器的公网IP添加为允许源,放行9094端口(避免开放0.0.0.0/0以保障安全)。

2. 验证Java信任库有效性

AWS MSK的TLS证书由AWS根CA签发,JRE 1.8及以上版本的默认cacerts信任库已包含这些根CA,理论上可直接使用,需确认:

  • ssl.truststore.location路径格式正确(你配置的路径无误)。
  • 信任库密码changeit未被修改(默认密码为该值)。
  • 可通过以下命令验证信任库是否包含AWS根CA:
    keytool -list -keystore "C:\Program Files (x86)\Java\jre-1.8\lib\security\cacerts" -storepass changeit | findstr "Amazon"
    

3. 检查网络连通性

  • 使用PowerShell测试端口连通性:
    Test-NetConnection <公网Broker端点> -Port 9094
    
  • 若连通失败,除安全组外,需检查VPC网络ACL是否允许9094端口的入站/出站流量。

4. 调整客户端超时配置

在client.properties中增加超时参数,避免因网络延迟导致超时:

admin.client.timeout.ms=60000
request.timeout.ms=30000

内容的提问来源于stack exchange,提问作者Roobal Jindal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 03:32:07