kafka the external network to access the configuration parameters advertised.host.name

kafka of server.properties file

`` `Host.name``` start only bound to the internal IP, can not access the external network adapter.

The set value is empty, then will kafka listening port binding on all cards. But outside the network access client has encountered `` `java.nio.channels.ClosedChannelException``` exception information, server-side using tcpdump analysis found that when a client has passed the machine where the machine name kafka over. Keep track of where the breakpoint in the client is found when findLeader returned meta-information is the machine name instead of IP. The client can not resolve the machine name so appeared in front of the exception.

There is also another argument in server.properties solve this problem,  advertised.host.name parameter values used to configure the host.name return, this parameter is configured to the external network IP address.

This parameter is not enabled by default, the default value is java.net.InetAddress.getCanonicalHostName return on my mac This value is not equal to the value of hostname but returns IP, but this value is the hostname value on linux.

In addition to IP, as well as PORT, PORT corresponding external network need to be modified. The following is server.properties file corresponding position.

# Hostname the broker will advertise to producers and consumers. If not set, it uses the

# value for "host.name" if configured. Otherwise, it will use the value returned from

# java.net.InetAddress.getCanonicalHostName().

#advertised.host.name=<hostname routable by clients>

 

# The port to publish to ZooKeeper for clients to use. If this is not set,

# it will publish the same port that the broker binds to.

#advertised.port=<port accessible by clients>

 

When Kafka broker starts, it will register their IP and port number on the ZK, the client will be connected via the IP and port number.

In this AWS IaaS environment, due java.net.InetAddress.getCanonicalHostName call to get HostName is similar ip-172-31-10-199 so only within the network can access the host name, so the default is registered ZK the IP within the network to access the internal network IP.

At this point you need to display the specified  advertised.host.nameadvertised.listeners parameters, allows registered to the IP ZK is outside the network IP.

For example, 59.64.11.22 IP corresponding broker, arranged in the following three needs to be increased server.properties configuration file:

 

The new configuration

advertised.listeners=PLAINTEXT://59.64.11.22:9092

 

Why do we need three parameters to configure IP and port number too, with a advertised.listeners not to get it?

Later found the latest version 0.10.x broker configuration abandoned advertised.host.name and advertised.port two all configuration items to configure advertised.listeners it.

发布了107 篇原创文章 · 获赞 29 · 访问量 18万+

Guess you like

Origin blog.csdn.net/zhangyingchengqi/article/details/104492578