报错日志
Connection to node 0 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
Connection to node 1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
问题描述
服务器已经开通了对应的端口,防火墙也都均属于关闭状态 , 能够telnet ,也用netstat看过了对应端口,确实已经建立了连接,却一直报错
解决办法
后来参考这篇博客 , kafka - advertised.listeners and listeners 发现 listeners,用于server真正bind
advertisedListeners, 用于开发给用户,如果没有设定,直接使用listeners ,
修改 Kafka 集群配置文件 server.properties
broker.id=1
# 监听端口指定为 9093
listeners=PLAINTEXT://:9093
# 对外部暴露端口 本机IP:端口
advertised.listeners=PLAINTEXT://192.168.206.155:9093
numwork.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/tmp/kafka-logs-1
其实这块在原本配合文件中也有描述
# 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.InetAddress.getCanonicalHostName().
如果没有设置, 代理将向生产者和消费者通告。(这里代理就是指 上面的监听 , 而监听的ip地址为 127.0.0.1 , 外部自然是访问不到)
如果配置了,它会使用“listener”的值。否则,它将使用该值 java.InetAddress.getCanonicalHostName()。
更多推荐
Kafka使用代码连接时日志频繁提示Broker may not be available.
发布评论