kafka bootstrap.servers 作为具有多个 IP 的 DNS A 记录

kafka bootstrap.servers as DNS A-Record with multiple IPs

我有一个包含 5 个代理的 Kafka 集群,我正在使用 Consul Service Discovery 将它们的 IP 放入 dns 记录中。

kafka.service.domain.cc A 1.1.1.1 2.2.2.2 ... 5.5.5.5

是否建议只使用一个域名: kafka.bootstrap.servers = kafka.service.domain.cc:30000

还是多个域名(至少2个)更好,每个域名解析一个代理

kafka1.service.domain.cc A 1.1.1.1
kafka2.service.domain.cc A 2.2.2.2

然后在kafka中使用它们

kafka.bootstrap.servers = kafka1.service.domain.cc:30000,kafka2.service.domain.cc:30000

我对第一种方法的担忧,即域名只会被随机代理解析一次,如果该代理已关闭,则不会进行新的 DNS 解析。

摘自书 精通 Apache Kafka

bootstrap.servers is a comma-separated list of host and port pairs that are the addresses of the Kafka brokers in a "bootstrap" Kafka cluster that a Kafka client connects to initially to bootstrap itself.

bootstrap.servers provides the initial hosts that act as the starting point for a Kafka client to discover the full set of alive servers in the cluster. Since these servers are just used for the initial connection to discover the full cluster membership (which may change dynamically), this list does not have to contain the full set of servers (you may want more than one, though, in case a server is down).

Clients (producers or consumers) make use of all servers irrespective of which servers are specified in bootstrap.servers for bootstrapping.

因此,由于 属性 bootstrap.servers 提供了初始主机,作为 Kafka 客户端发现集群中所有活动服务器的起点,我认为这两种方法都会做。但是由于他们将 属性 的值保留为逗号分隔列表,我想第二种方法将是推荐的方法。而且方法 1 中的一个问题是,在引导过程中,随机代理可能会关闭,客户端将无法继续获取集群信息。因此,如果一个代理在引导过程中出现故障,最好提供多个作为后备。

Kafka 2.1 支持在 bootstrap.servers 中处理多个 DNS 资源记录。

如果您在客户端配置中设置 client.dns.lookup="use_all_dns_ips",它将使用 DNS 返回的所有 IP 地址,而不仅仅是第一个(或随机的)。

有关详细信息,请参阅 KIP-235 and KIP-302