从外部连接 kafka 的问题 [英] Issue in connecting kafka from outside

查看:35
本文介绍了从外部连接 kafka 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 kafka 服务器使用 hortonwork Sandbox试图从 Eclipse 连接 kafka 与 java 代码.使用此配置连接生产者发送消息

I am using hortonwork Sandbox for kafka server trying to connect kafka from eclipse with java code . Use this configuration to connect to producer to send the message

metadata.broker.list=sandbox.hortonworks.com:45000
serializer.class=kafka.serializer.DefaultEncoder
zk.connect=sandbox.hortonworks.com:2181
request.required.acks=0
producer.type=sync

其中 sandbox.hortonworks.com 是我连接的沙箱名称

where sandbox.hortonworks.com is sandboxname to whom i connect

在 kafka server.properties 中我改变了这个配置

in kafka server.properties I changed this configuration

host.name=sandbox.hortonworks.com

advertised.host.name=System IP(on which my eclipse is running)
advertised.port=45000

端口转发也做了,

我可以从 Eclipse 连接到 kafka 服务器,但是在发送消息时出现异常异常尝试 3 次后无法发送消息."

I am able to connect to kafka server from eclipse but while sending the message get the exception Exception"Failed to send messages after 3 tries."

推荐答案

首先确保您已按照此处所述为 Hortonworks Sandbox VM 配置了仅主机网络:

First make sure you have configured host-only network for your Hortonworks Sandbox VM as described here:

http://hortonworks.com/community/forums/topic/use-host-only-networking-for-the-virtual-machine/

执行此操作后,您的沙盒虚拟机应该获得一个 IP(例如 192.168.56.101),并且应该可以通过 SSH 从您的主机访问它

After doing this your sandbox VM should get a IP (e.g. 192.168.56.101) and it should be reachable from your host via SSH like

$ ssh root@192.168.56.101

然后在 http://192.168.56.101:8080/ 处打开 Ambari 并将 Kafka 配置更改为

Then open Ambari at http://192.168.56.101:8080/ and change the Kafka configuration to

listeners=PLAINTEXT://0.0.0.0:6667
advertised.listeners=PLAINTEXT://192.168.56.101:6667 

后一个属性必须添加到自定义 kafka-broker"部分(另见 http://hortonworks.com/community/forums/topic/ambari-alerts-how-to-change-kafka-port/).

The latter property must be added in the section "Custom kafka-broker" (See also http://hortonworks.com/community/forums/topic/ambari-alerts-how-to-change-kafka-port/).

然后通过 Ambari 启动/重启 Kafka.您现在应该可以从 Hortonworks Sandbox VM 外部访问 Kafka.您可以使用例如测试(从沙盒虚拟机外部)来自 Kafka 发行版的 Kafka 控制台生产者,如

Then start/restart Kafka via Ambari. You should now be able to access Kafka from outside the Hortonworks Sandbox VM. You can test this (from outside of the sandbox VM) using e.g. the Kafka console producer from the Kafka distribution like

$ bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
$ bin/kafka-console-producer.sh --topic test --broker-list 192.168.56.101:6667

这篇关于从外部连接 kafka 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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