如何从外部访问私网上的kafka集群?

识趣 发表于: 2021-09-13   最后更新时间: 2022-09-02 19:43:29   2,141 游览

我在私有网络的10.242.44.55上有一台装有Zookeeper和Kafka的集群。我把网关上的端口从[public_ip]:39092转发到10.242.44.55:9092

listeners=INTERNAL://:9092,EXTERNAL://:39092
advertised.listeners=INTERNAL://10.242.44.55:9092,EXTERNAL://[public_ip]:39092
listener.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
inter.broker.listener.name=INTERNAL

在私有网络中一切工作正常。我可以从不同的电脑上生产和消费信息。不幸的是,当我试图从外面生产消息时,返回了一个错误。

pers@pc:/opt/kafka$ bin/kafka-console-producer.sh —broker-list [public_ip]:39092 —topic test
>testMessage
>[2018-03-24 17:51:04,393] ERROR Error when sending message to topic test with key: null, value: 11 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
org.apache.kafka.common.errors.TimeoutException: Expiring 1 record(s) for test-1: 1505 ms has passed since batch creation plus linger time
[2018-03-24 17:53:13,970] WARN [Producer clientId=console-producer] Connection to node 0 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

但是,我用telnet是可以通的。

pers@pc:/opt/kafka$ telnet [public_ip] 39092
Trying [public_ip]...
Connected to [public_ip].
Escape character is '^]'.
test
Connection closed by foreign host.

有该怎么办呢?

发表于 2021-09-13

broker配置的一部分:

listeners=EXTERNAL://:39092,INTERNAL://:9092
advertised.listeners=EXTERNAL://77.1.1.1:39092,INTERNAL://10.1.1.1:9092
listener.security.protocol.map=EXTERNAL:PLAINTEXT,INTERNAL:PLAINTEXT
inter.broker.listener.name=INTERNAL

你可以试试看。

你的答案

查看kafka相关的其他问题或提一个您自己的问题