大网数据广告活动
服务器运维问答

Apache Kafka configuration behind NAT/LB

· 52CE 我爱测

In order to make our Kafka cluster available both from Internet and from our private network, we thought fine to configure Kafka this way : Private VIP:9000 => All brokers:9092 (topology query only) Private VIP:9001 => Broker #1:…

问题原文

原帖链接 · mveroone · CC BY-SA 4.0

In order to make our Kafka cluster available both from Internet and from our private network, we thought fine to configure Kafka this way :

Private VIP:9000 => All brokers:9092 (topology query only)
Private VIP:9001 => Broker #1:9092
Private VIP:9002 => Broker #2:9092
...
Public VIP:9000 => All brokers:9092 (topology query only)
Public VIP:9001 => Broker #1:9092
Public VIP:9002 => Broker #2:9092
...

We configured our Load balancer this way, and then our brokers :

listeners=PLAINTEXT://<server_priv_ip>:9092
advertised.listeners=INTERNAL://<private_VIP>:9001,EXTERNAL://<public_vip>:9001
listener.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
inter.broker.listener.name=INTERNAL

Now, as you would expect, Kafka brokers don't start :

ERROR Exiting Kafka due to fatal exception (kafka.Kafka$)
java.lang.IllegalArgumentException: requirement failed: Each listener must have a different port, listeners: INTERNAL://<private_VIP>:9001,EXTERNAL://<public_vip>:9001

From my Administrator point of view, my approach was totally logical, although I expected a problem where producer/consumers would get both addresses wherever they contacted the broker from. Using the same port on 2 different addresses seems logical and promotes clarity...

First question : Why is this wrong ?
Second question : How can I achieve my goal if not this way? (most options are on the table)

已采纳解答

原帖链接 · mveroone · CC BY-SA 4.0

We have talked to a Kafka expert and here is what came out of it.

Simply put, while kafka has the Listener Names in its knowledge to differentiate 2 listeners, he needs to know which one the client that connects wants to reach and can only do so using the incoming port.

Also listeners and advertised listeners are mapped to one another if they have the same port so you need them to match.

In the end, here is what we did :

listeners=INTERNAL://hostname:900N,EXTERNAL://hostname:910N,REPLICATION:hostname:9092
advertised.listeners==INTERNAL://vip:900N,EXTERNAL://vip:910N,REPLICATION:hostname:9092  
listeners.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT,REPLICATION:PLAINTEXT
inter.listener.protocol=REPLICATION

Where "N" is the broker ID (counting from 1 forwards)

On the Load balancer, we map each port of the VIP to the broker's IP address plus a Virtual IP on port 9000(internal network) and 9100 (external network) which map to the relevant listener of each broker.

That's a bit overkill, but it works as expected (as long as kafka internal metadata topics like __consumer_offset are replicated)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-10-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。