gpt4 book ai didi

apache-kafka - 卡夫卡监听器不工作!内网隔离

转载 作者:行者123 更新时间:2023-12-01 13:11:38 24 4
gpt4 key购买 nike

我的 Kafka 节点托管在 Google Cloud Dataproc 中。但是,我们意识到通过默认初始化脚本安装的Kafka设置为只允许内网访问。它与外界完全隔绝。谷歌云网络之外的生产者无法将消息发布到 Kafka,并且 Kafka 消息无法链接到其外网订阅者。
备注
我已将生产者 IP 列入白名单
通读其他 StackOverflow、博客文章和文档后。我认为这可能是由于 advertised.listeners Socket Server Settings 的零件在 /usr/lib/kafka/server.properties .
第一个解决方案

I added advertised.listeners=PLAINTEXT://[External_IP]:19092

then sudo /etc/init.d/kafka-server restart


Kafka Restart Successfully
成果
但是,当我尝试 Kafkacat 或 telnet 时,它总是失败。我还用各种端口测试了advertised.listeners
Ping Success, telnet and kafkacat failed
第二种解决方案来自 https://rmoff.net/2018/08/02/kafka-listeners-explained/
enter image description here
############################# Server Basics #############################

# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0

############################# Socket Server Settings #############################

# The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured.
# FORMAT:
# listeners = listener_name://host_name:port
# EXAMPLE:
# listeners = PLAINTEXT://your.host.name:9092
#

# Hostname and port the broker will advertise to producers and consumers. If not set,
# it uses the value for "listeners" if configured. Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().


->>>>>>> I added below listener config according to https://rmoff.net/2018/08/02/kafka-listeners-explained/

listeners=INTERNAL://0.0.0.0:9092,EXTERNAL://0.0.0.0:19092
listener.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
advertised.listeners=EXTERNAL://[External_IP]:19092,INTERNAL://[Internal_IP]:9092
inter.broker.listener.name=INTERNAL
成果
结果和上面一样,不工作。
防火墙规则 [更新]
这是我当前的防火墙规则配置。我做错了吗?
Firewall Rules
谁能帮我解决这个问题?

最佳答案

这是对我的集群有效的方法:

我已经从第二个解决方案中设置了以下属性:

listeners=INTERNAL://0.0.0.0:9092,EXTERNAL://0.0.0.0:19092
listener.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
advertised.listeners=EXTERNAL://[External_IP]:19092,INTERNAL://[Internal_IP]:9092
inter.broker.listener.name=INTERNAL

我创建了一个防火墙规则,向我的个人开发机器 IP 开放端口 19092,并将其应用到网络。 从我的机器 ,我尝试 telnet kafka 服务器,我得到:
$ telnet [EXTERNAL-IP] 19092
Trying [EXTERNAL-IP]...
Connected to [EXTERNAL-IP].
Escape character is '^]'.

然后我尝试使用 kafkacat,但出现错误。在调试中运行,我看到错误是因为我没有设置任何主题:
%7|1578351264.551|METADATA|rdkafka#producer-1| [thrd:main]: [EXTERNAL-IP]:19092/bootstrap: ===== Received metadata: application requested =====
%7|1578351264.551|METADATA|rdkafka#producer-1| [thrd:main]: [EXTERNAL-IP]:19092/bootstrap: ClusterId: jYxfi6zzR0euAovYyKCFZg, ControllerId: -1
%7|1578351264.551|METADATA|rdkafka#producer-1| [thrd:main]: [EXTERNAL-IP]:19092/bootstrap: 0 brokers, 0 topics
%7|1578351264.551|METADATA|rdkafka#producer-1| [thrd:main]: [EXTERNAL-IP]:19092/bootstrap: No brokers or topics in metadata: should retry
%7|1578351264.551|REQERR|rdkafka#producer-1| [thrd:main]: [EXTERNAL-IP]:19092/bootstrap: MetadataRequest failed: Local: Partial response: explicit actions Retry
%7|1578351264.551|RETRY|rdkafka#producer-1| [thrd:[EXTERNAL-IP]:19092/bootstrap]: [EXTERNAL-IP]:19092/bootstrap: Retrying MetadataRequest (v2, 25 bytes, retry 1/2, prev CorrId 3) in 100ms

请注意,我已经尝试从集群外部连接到 kafka 服务器。题中telnet和kafkacat运行在kafka服务器(kafka-tng-w-0)同一台机器上。

关于apache-kafka - 卡夫卡监听器不工作!内网隔离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59589978/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com