【发布时间】:2017-12-04 02:25:07
【问题描述】:
我一直在尝试在 Kafka 集群上运行我的生产者和消费者 API,但它不起作用。
1) Zookeeper 在一个 GCP 虚拟机实例上运行
2) Kafka 正在另一个 GCP 虚拟机实例上运行
遵循的步骤:
步骤 1) 使用以下命令运行 Zookeeper:
bin/zookeeper-server-start.sh config/zookeeper.properties
Zookeeper.properties:
#the directory where the snapshot is stored.
dataDir=/tmp/zookeeper
#the port at which the clients will connect
clientPort=2181
#disable the per-ip limit on the number of connections since this is a non-production config
maxClientCnxns=0
# In milliseconds
tickTime=2000
# In ticks
initLimit=10
syncLimit=5
maxClientCnxns=30
# All Zookeeper servers need to be aware of other Zookeepers part of the cluster
server.1=zook-1:2888:3888
注意:zook-1 是 Zookeeper 实例的名称
第 2 步)
在另一个 GCP 虚拟机实例上运行 Kafka:
bin/kafka-console-producer.sh --broker-li de-kafka-1:9092 --topic test
server.properties:
############################# Server Basics ############################# # The id of the broker. This must be set to a unique integer for each broker.
broker.id=0
############################ Zookeeper ############################# #
# root directory for all kafka znodes.
zookeeper.connect=zook-1:2181
# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=6000
host.name=de-kafka-1
第 3 步)
从第 2 步开始在 Kafka 实例上运行生产者 api(使用另一个 SSH 隧道),如下所示:
bin/kafka-console-producer.sh --broker-list de-kafka-1:9 092 --topic test
注意:这里 de-kafka-1 是我尝试过的 GCP Kafka VM 实例的名称,并将 de-kafka-1 替换为 de-Kafka-1 实例的外部 IP、localhost、zook-1(Zookeeper 的名称VM 实例),zook-1 vm 实例的外部 IP
Error: OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N Sending msg1 sending msg2
Error: error when sending message to topic test single node with key: null, value: 5 bytes with error (org.apache.kafka.clients.producer.internals.errorloggingcallback)org.apache.kafka.common.errors.timeoutexception: failed to update metadata after 60000 ms.
第 4 步:
在 Kafka 实例上运行 Consumer API(使用第三个 SSH 隧道):
bin/kafka-console-consumer.sh --bootstrap-server de-kafka-1:2181 --topic test --from-beginning
如果有人能提供帮助,我们将不胜感激。谢谢
【问题讨论】:
-
尝试从kafka vm运行
telnet zook-1 2181,如果成功,输入stats并回车。这将检查您的 kafka-zookepper 连接和 zookeeper 的状态。 -
@Gal 感谢您的回复,这是我得到的:------------ 'Zookeeper 版本: 3.4.9-1757313,建于 08/23/2016 06:50 GMT 客户端:/xx.xxx.x.xx:45284[1](queued=0,recved=275,sent=277) /xx.xxx。 x.xx:45384[0](queued=0,recved=1,sent=0) 延迟最小/平均/最大:0/0/6 接收:276 发送:277 连接:2 未完成:0 Zxid:0x113 模式:独立节点数:36 连接被外部主机关闭。'
-
@Gal 知道这意味着什么
-
看起来不错,
Mode: standalone表示您正在运行 zk 独立模式。尝试在kafka vm上运行netstat -nlp | grep 9092并发布输出.. -
@Gal tcp6 0 0 xx.xxx.x.xx:9092 :::* LISTEN 890/java 。这是运行 netstat -nlp | 后的输出grep 9092
标签: apache-kafka apache-zookeeper kafka-producer-api gcp