烂笔头

不积跬步无以至千里

0%

lua-resty-kafka 出现no resolver defined to resolve的解决方法

kafka集群版本:2.6.0

发生的原因

默认kafka集群节点配置(config/server.properties)中包含如下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
############################# Socket Server Settings #############################

# 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

# 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://host_name:9092

# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL

可以发现,默认广播给producers和consumers的节点host是通过java.net.InetAddress.getCanonicalHostName()获取的,这个方法获取到的数据是centos设置的hostname
lua-resty-kafka运行在nginx中,nginx不能解析本地的hostname,导致no resolver defined to resolve问题。

ISSUE

解决办法

在kafka集群每个node上修改config/server.properties,用本机IP代替获取hostname

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
############################# Socket Server Settings #############################

# 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://192.168.0.202: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://192.168.0.202:9092

# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL