kafka listeners和advertised配置
kafka版本:kafka_2.11-2.3.0java
kafka配置listenersbootstrap
# 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的配置項。socket
advertised.listeners
advertised.listeners
參數的做用就是將Broker的Listener信息發佈到Zookeeper中this
下面演示現象:
第一種狀況:
默認都不配置spa
zookeeper查看kafka地址:
kafka建立topic
添加主機hosts訪問正常
192.168.11.103 xuliang-PC.net
第二種狀況
配置 listeners=PLAINTEXT://192.168.11.103:9092code
默認advertised.listeners也是 192.168.11.103:9092server
此時訪問要經過:bin/kafka-topics.sh --list --bootstrap-server 192.168.11.103:9092blog
第三種狀況:
配置以下:
第四種狀況:
配置以下:
監聽地址:
內外網分流:
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
配置監聽者的安全協議的,好比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