如何从外面到私人网络上的Kafka?

时间:2018-03-24 15:18:05

标签: apache-kafka kafka-producer-api

我在10.242.44.55的私有网络中有一个带Zookeeper和Kafka的服务器。我已将网关上的端口从[public_ip]:39092转发到10.242.44.55:9092。我从another question获取了Kafka的以下设置:

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.

I saw that another man had such problem,但没有解决方案。  谁知道我做了什么?

2 个答案:

答案 0 :(得分:1)

我不小心解决了我的问题。当端口转发使用相同的端口时,Kafka工作正常。

这是我经纪人配置的一部分:

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

答案 1 :(得分:0)

这里是kafka的工作端口转发简单配置。 端口19082应该在外部ip上打开

    broker.id=0
    advertised.host.name=192.168.129.36
    listeners=PLAINTEXT://:9092
    advertised.listeners=PLAINTEXT://122.112.92.146:19092