无法从本地机器连接到谷歌计算引擎上的 kafka 服务器 [英] Not able to connect to kafka server on google compute engine from local machine

查看:28
本文介绍了无法从本地机器连接到谷歌计算引擎上的 kafka 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在谷歌计算引擎上运行我的 zookeeper 和 kafka 服务器.两者都在默认端口上运行(2181 上的 Zookeeper 和 9092 上的 kafka).两者都在同一个实例上运行.我也打开了两个端口.在我的 server.properties 中,我已经配置了

I am running my zookeeper and kafka server on google compute engine. Both are running on default ports(zookeeper on 2181 an kafka on 9092). Both are running on the same instance. I have opened up both the ports as well. In my server.properties I have configured

zookeeper.connect=<InternalIP>:2181
host.name=localhost

如果我尝试从同一台服务器推送/消费消息,我可以这样做推送/消费我使用

If I try to push/consume message form the same server, I am able to do so To push/consume I use

 bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
 bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning

但是,如果尝试从我的本地机器上进行相同的操作,我会在生产者中得到 kafka.common.FailedToSendMessageException 和 java.net.ConnectException: connection refueed in case of consumer我尝试通过

However, If try to the same from my local machine I get kafka.common.FailedToSendMessageException in producer and java.net.ConnectException: connection refuesed in case of consumer I try to push/consume via

bin/kafka-console-producer.sh --broker-list <ExternalIP>:9092 --topic topic1
bin/kafka-console-consumer.sh --zookeeper <ExternalIP>:2181 --topic topic1 --from-beginning

请注意,我可以从本地系统 ping 外部 IP.

Please note that i am able to ping the external ip from my local system.

我已经在计算引擎中配置了下面提到的防火墙规则

I have configured the below mentioned firewall rules in compute engine

Description

kafka port enabled
Network

default
Source filter

Allow from any source (0.0.0.0/0)
Allowed protocols and ports

tcp:9092

说明

zookeeper port enabled
Network

default
Source filter

Allow from any source (0.0.0.0/0)
Allowed protocols and ports

tcp:2181

推荐答案

必须通过SSH访问云计算VM实例,然后编辑kafka配置文件.

You must access to the cloud compute VM instance through SSH, then edit the kafka configuration file.

$ sudo vim /opt/bitnami/kafka/config/server.properties

取消注释#advertised.listeners=PLAINTEXT://:9092 并替换为advertised.listeners=PLAINTEXT://[instance_public_id_address]:9092

Uncomment the line # advertised.listeners=PLAINTEXT://:9092 and replace with advertised.listeners=PLAINTEXT://[instance_public_id_address]:9092

最后一步重启kafka服务

As a last step restart the kafka service

sudo /opt/bitnami/ctlscript.sh restart

重要的是要考虑 GCP 计算 VM 的默认 IP 地址是临时的,因此您必须在 Kafka 实例的 GCP 配置面板中将其更改为静态,以避免每次更改 IP 地址时更改配置文件变化.

It's important to consider which the default IP address of the GCP compute VM is ephemeral so you must change it to static in the GCP Configuration panel of the Kafka instance, in order to avoid change the configuration file each time that the IP address changes.

这篇关于无法从本地机器连接到谷歌计算引擎上的 kafka 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆