无法从本地计算机连接到Google计算引擎上的kafka服务器 [英] Not able to connect to kafka server on google compute engine from local machine
问题描述
我正在Google计算引擎上运行我的zookeeper和kafka服务器.两者都在默认端口上运行(zookeeper在2181上,kafka在9092上).两者都在同一实例上运行.我也打开了两个端口.在我的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
但是,如果尝试从本地计算机执行相同操作,则会在生产者和java.net.ConnectException中得到kafka.common.FailedToSendMessageException:如果使用使用者,则重新建立连接 我尝试通过以下方式推送/消费
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计算虚拟机的默认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.
这篇关于无法从本地计算机连接到Google计算引擎上的kafka服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!