问题
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