1)如何将kafka注册到zookeeper上,然后可以查询到kafka的节点信息

ls

ls会显示该节点下的子节点信息

比如:

ls /


显示zookeeper根目录下的子节点,其中kafka的broker在zookeeper根目录注册了brokers节点

kafka对外提供的meta info中的节点地址信息是直接读取zookeeper的注册信息,该注册信息是在集群启动时写入的,信息的最终来源为server.properties。依据Kafka官方文档http://kafka.apache.org/0101/documentation.html#brokerconfigs的描述,配置的优先级如下:

1.首先读取advertised.listeners的值

2.若1中值为空,使用advertised.host.name & advertised.port注册到zookeeper


连接上了broker,找到了zookeeper上对应的kafka的topic信息,接下来要往topic上发送数据的时候,zk上注册的topic对应的信息是局域网的机器名称和ip


[2020-05-18 16:33:58,912] WARN Session 0x0 for server ls:2181, unexpected error, closing socket connection and attempting reconnect (org.apache.zookeeper.ClientCnxn)
java.nio.channels.UnresolvedAddressException
 at sun.nio.ch.Net.checkAddress(Net.java:101)
 at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:622)
 at org.apache.zookeeper.ClientCnxnSocketNIO.registerAndConnect(ClientCnxnSocketNIO.java:277)
 at org.apache.zookeeper.ClientCnxnSocketNIO.connect(ClientCnxnSocketNIO.java:287)
 at org.apache.zookeeper.ClientCnxn$SendThread.startConnect(ClientCnxn.java:1021)
 at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1064)