How to reach Kafka on private network from outside?

假如想象 提交于 2019-12-11 08:28:39

问题


I have a server with Zookeeper and Kafka in private network on 10.242.44.55. I have forwarded port on gateway from [public_ip]:39092 to 10.242.44.55:9092. I took the following settings for Kafka from another question:

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

Everything works fine in private network. I can produce and consume messages from different computers. Unfortunatelly when I tried to produce a message from outside I got an error:

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)

The same time I can reach this socket with 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, but there are no solutions. Anybody knows what I'm doing worng?


回答1:


I accidentally solved my problem. Kafka works fine when the same ports are used in ports forwarding.

This is part of my broker's config:

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


来源:https://stackoverflow.com/questions/49466377/how-to-reach-kafka-on-private-network-from-outside

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!