kafka listeners和advertised配置

kafka  listeners和advertised配置

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

listeners就是主要用来定义Kafka Broker的Listener的配置项。

advertised.listeners

advertised.listeners参数的作用就是将Broker的Listener信息发布到Zookeeper中

 

下面演示现象:

第一种情况:

默认都不配置

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

第三种情况:

配置如下:

 

 

 

第四种情况:

配置如下:

 

 

 

 监听地址:

 

 内外网分流:

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

listeners就是主要用来定义Kafka Broker的Listener的配置项。

advertised.listeners

advertised.listeners参数的作用就是将Broker的Listener信息发布到Zookeeper中

inter.broker.listener.name

inter.broker.listener.name:专门用于Kafka集群中Broker之间的通信

listener.security.protocol.map

配置监听者的安全协议的,比如PLAINTEXTSSLSASL_PLAINTEXTSASL_SSL

新版本kafka product 和consumer访问集群方式:

 

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

 

总结:

 

listeners

是kafka真正bind的地址

 

advertised.listeners

是暴露给外部的listeners,如果没有设置,会用listeners

 

 
posted @ 2019-11-16 23:03  时光依然轻擦  阅读(49774)  评论(3编辑  收藏  举报