机器有两块网卡,kafka的host.name
开始只绑定在了内部IP上,另一块对外网卡无法访问,把值设置为空的话会kafka监听端口在所有的网卡上绑定,但是在外网访问时,客户端又遇到了java.nio.channels.ClosedChannelException
异常信息,server端用tcpdump分析的时候发现客户端有传递kafka所在机器的机器名过来。在client里断点跟踪一下发现是findLeader
的时候返回的元信息是机器名而不是IP。客户端无法解析这个机器名所以出现了前面的异常。
在server.properties 里还有另一个参数是解决这个问题的, advertised.host.name参数用来配置返回的host.name值,把这个参数配置为外网IP地址即可。
这个参数默认没有启用,默认是返回的java.net.InetAddress.getCanonicalHostName
的值,在我的mac上这个值并不等于hostname
的值而是返回IP,但在linux上这个值就是hostname
的值。
多谢博主, this save my day
公司的机房不知为何有一个很奇怪的配置, A机器可以ping 通 B机器的hostname, B机器无法ping通A机器的hostname,
B机器上有一个线上的kafka, 需要在A机器上搭一个测试的kafka, 结果愣是所有的remote的机器都无法连接,
而且因为配置是直接拷贝过来的,所以更是让我困惑不已
0.8.2.1
# Hostname the broker will bind to. If not set, the server will bind to all interfaces
#host.name=localhost
# 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=
0.10.0.0 里把 host.name 改为 listeners 了
# The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured.
# FORMAT:
# listeners = security_protocol://host_name:port
# EXAMPLE:
# listeners = PLAINTEXT://your.host.name:9092
#listeners=PLAINTEXT://:9092
# 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