Kafka 消费者远程读不到数据

kafka远程消费不到数据,但是也不报错
远程主机用telnet命令去测试kafka以及zookeeper节点的9200端口以及2181端口都畅通。
这是因为没有配置advertised.host.name,所以kafka获取ip信息的时候使用的是java.net.InetAddress.getCanonicalHostName(),在linux下该方法获取的是主机名。

说明:在老版本的kafka中,broker注册到zookeeper的IP是用的server.properties中host.name配置的信息,查看server.properties的注释:(配置了,使用advertised.host.name的信息,不然使用host.name的信息,如果Host.name也是空,则使用java.net.InetAddress.getCanonicalHostName()),新版本中该配置改为listeners/advertised.listeners

以下是摘抄自kafka的配置server.properties
老版本配置:

############################# Socket Server Settings #############################

# The port the socket server listens on
port=9092

# Hostname the broker will bind to. If not set, the server will bind to all interfaces
host.name=***

# Hostname the broker will advertise to producers and consumers. If not set, it uses the
# value for "host.name" if configured.  Otherwise, it will use the value returned from
# java.net.InetAddress.getCanonicalHostName().
#advertised.host.name=<hostname routable by clients>

# The port to publish to ZooKeeper for clients to use. If this is not set,
# it will publish the same port that the broker binds to.
#advertised.port=<port accessible by clients>

新版本配置:

############################# Socket Server Settings #############################
# The address the socket server listens on. It will get the value returned from 
# java.net.InetAddress.getCanonicalHostName() if not configured.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
#listeners=PLAINTEXT://:9092

# Hostname and port the broker will advertise to producers and consumers. If not set, 
# it uses the value for "listeners" if configured.  Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
#advertised.listeners=PLAINTEXT://your.host.name:9092

解决办法:
方法一:
在远程主机上hosts文件里配上kafka节点主机。
格式:IP地址 主机名
方法二:
老版本:配置kafka 的server.properties中,host.name=IP地址
新版本:编辑 Kafka 目录下 config/server.properties,主要是添加listeners项:
listeners=PLAINTEXT://IP地址:9092
或者
advertised.listeners = PLAINTEXT://IP地址:9092
备注:除 advertised.listeners 外,也可一同配置 advertised.host.name 和 advertised.port,不过这两个配置项已废弃,仅在 advertised.listeners 和 listeners 均未设置时使用。

另外,在linux中,consumer启动的时候,注册到zookeeper的IP信息应该也是通过java.net.InetAddress.getCanonicalHostName()获取的,所以,在linux上启动consumer需要配置host

参考文章:
https://blog.csdn.net/o_victorain/article/details/84107713
https://www.cnblogs.com/snifferhu/p/5102629.html
https://my.oschina.net/chiyong/blog/522998
http://www.it610.com/article/3616964.htm

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

香山上的麻雀1008

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值