kafka配置listeners
# 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
kafka配置advertised
# 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
下面演示现象:
第一种情况:
默认都不配置
zookeeper查看kafka地址:
kafka创建topic
添加主机hosts访问正常
192.168.11.103 xuliang-PC
第二种情况
配置 listeners=PLAINTEXT://192.168.11.103:9092
默认advertised.listeners也是 192.168.11.103:9092
此时访问要通过:bin/kafka-topics.sh --list --bootstrap-server 192.168.11.103:9092
第三种情况:
配置如下:
第四种情况:
配置如下:
监听地址:
总结:
listeners
是kafka真正bind的地址
advertised.listeners
是暴露给外部的listeners,如果没有设置,会用listeners