为什么我无法从外部连接到 Kafka? [英] Why I cannot connect to Kafka from outside?

查看:32
本文介绍了为什么我无法从外部连接到 Kafka?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ec2 实例上运行 kafka.所以亚马逊 ec2 实例有两个 ip,一个是内部 ip,第二个是供外部使用.

I am running kafka on ec2 instance. So amazon ec2 instance has two ips one is internal ip and second one is for external use.

我从本地机器创建了生产者,但它重定向到内部 IP 并给我连接不成功的错误.任何人都可以帮助我在 ec2 实例上配置 kafka,以便我可以从本地机器运行生产者.我尝试了很多组合,但没有奏效.

I created producer from local machine, but it redirect to internal ip and give me connection unsuccessful error. Can anybody help me to configure kafka on ec2 instance, so that I can run producer from local machine. I am tried many combinations but didn't work.

推荐答案

Kafka 常见问题(针对新属性进行了更新),您可以阅读:

In the Kafka FAQ (updated for new properties) you can read:

当代理启动时,它会在 ZK 中注册其 ip/端口.您需要确保注册的 ip 与生产者配置中 bootstrap.servers 中列出的内容一致.默认情况下,注册的 ip 由 InetAddress.getLocalHost.getHostAddress() 给出.通常,这应该返回主机的真实 IP.但是,有时(例如,在 EC2 中),返回的 IP 是内部 IP,无法从外部连接.解决方案是通过设置server.properties 中的advertised.listeners 属性,显式设置要在ZK 中注册的主机ip 和端口.

When a broker starts up, it registers its ip/port in ZK. You need to make sure the registered ip is consistent with what's listed in bootstrap.servers in the producer config. By default, the registered ip is given by InetAddress.getLocalHost.getHostAddress(). Typically, this should return the real ip of the host. However, sometimes (e.g., in EC2), the returned ip is an internal one and can't be connected to from outside. The solution is to explicitly set the host ip and port to be registered in ZK by setting the advertised.listeners property in server.properties.

这篇关于为什么我无法从外部连接到 Kafka?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆