kafkalisteners和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
# CanonicalHostName() if not configured.
# FORMAT:
kafka最新版本# 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 CanonicalHostName().
#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":
内⽹访问可以使⽤: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
配置监听者的安全协议的,⽐如PLAINTEXT、SSL、SASL_PLAINTEXT、SASL_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
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论