赞
踩
因为第三方要对接我们的kafka结果数据一直无法进来,经过排查发现是hostname解析没有配置。
第三方提示要我们配置
advertised.listeners,由此进行了相关的资料整理学历
kafka版本:kafka_2.11-2.3.0
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
listeners
就是主要用来定义Kafka Broker的Listener的配置项。
advertised.listeners
参数的作用就是将Broker的Listener信息发布到Zookeeper中
默认都不配置
默认是hostname,如果第三方需要对接。需要配置hostname
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
配置如下:
配置如下:
listener.security.protocol.map=EXTERNAL:PLAINTEXT,INTERNAL:PLAINTEXT listeners=EXTERNAL://192.168.11.103:9092,INTERNAL://192.168.11.103:9093 inter.broker.listener.name=INTERNAL #advertised.listeners=EXTERNAL://192.168.11.103:9094,INTERNAL://192.168.11.103:9093
[zk: localhost:2181(CONNECTED) 8] get /brokers/ids/0
{"listener_security_protocol_map":{"EXTERNAL":"PLAINTEXT","INTERNAL":"PLAINTEXT"},"endpoints":["EXTERNAL://192.168.11.103:9092","INTERNAL://192.168.11.103:9093"],
"jmx_port":-1,"host":"192.168.11.103",
"timestamp":"1573920483772","port":9092,"version":4}
内网访问可以使用:192.168.11.103:9093
外网访问使用:192.168.11.103:9092
这在kafka部署到kubernetes时候就很有用了
listeners
就是主要用来定义Kafka Broker的Listener的配置项。
advertised.listeners
参数的作用就是将Broker的Listener信息发布到Zookeeper中
inter.broker.listener.name:专门用于Kafka集群中Broker之间的通信
配置监听者的安全协议的,比如PLAINTEXT
、SSL
、SASL_PLAINTEXT
、SASL_SSL
xuliang@xuliang:/usr/local/kafka_2.11-2.3.0$ bin/kafka-console-producer.sh --broker-list 192.168.11.103:9092 --topic test >this is a test xuliang@xuliang:/usr/local/kafka_2.11-2.3.0$ 0$ bin/kafka-consoconsumer.sh --bootstrap-server 192.168.11.103:9092 --from-beginning --topic test this is a test this is a test
是kafka真正bind的地址
是暴露给外部的listeners,如果没有设置,会用listeners
参考:kafka listeners和advertised配置 - 时光依然轻擦 - 博客园
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。