我有一个Kafka运行在码头与ssl启用。 docker ps
:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b8f6b1c573a1 nginx:1.13.9-alpine "nginx -g 'daemon of…" 9 hours ago Up 9 hours 80/tcp, 0.0.0.0:8081->443/tcp ng
761ce6ee2960 confluentinc/cp-schema-registry:4.0.0 "/etc/confluent/dock…" 9 hours ago Up 9 hours 0.0.0.0:8080->8080/tcp, 8081/tcp sr
16d7b81dfbc8 confluentinc/cp-kafka:4.0.0 "/etc/confluent/dock…" 9 hours ago Up 9 hours 0.0.0.0:9092-9093->9092-9093/tcp k1
9be579992536 confluentinc/cp-zookeeper:4.0.0 "/etc/confluent/dock…" 9 hours ago Up 9 hours 2888/tcp, 0.0.0.0:2181->2181/tcp, 3888/tcp zk
如何从命令行写入主题?
已尝试(主题“test”存在):
kafka-console-producer --broker-list kafka:9093 --topic test
# [2018-04-23 17:55:14,325] ERROR Error when sending message to topic test with key: null, value: 2 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
# org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms. (60s timeout)
kafka-console-producer --broker-list kafka:9092 --topic test
>aa
# [2018-04-23 18:00:59,443] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 1 : {test=TOPIC_AUTHORIZATION_FAILED} (org.apache.kafka.clients.NetworkClient)
# [2018-04-23 18:00:59,444] ERROR Error when sending message to topic test with key: null, value: 2 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
# org.apache.kafka.common.errors.TopicAuthorizationException: Not authorized to access topics: [test]
kafka-console-producer --broker-list localhost:9092 --topic test dnk306@9801a7a5b33d
>aa
# [2018-04-23 21:52:47,056] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 1 : {test=TOPIC_AUTHORIZATION_FAILED} (org.apache.kafka.clients.NetworkClient)
# [2018-04-23 21:52:47,056] ERROR Error when sending message to topic test with key: null, value: 2 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
# org.apache.kafka.common.errors.TopicAuthorizationException: Not authorized to access topics: [test]
1条答案
按热度按时间zvokhttg1#
在模式注册表或kafka容器中时,如果您使用docker compose配置,这是可能的,因为容器将通过compose链接,但是,您的容器主机名可能是
k1
而不是kafka
如果您在kafka容器内,或者在容器外使用cli命令,那么localhost:9093
(因为您转发了端口)。如果您在Kafka容器以外的容器中,并且希望通过主机名解析Kafka容器,则必须添加
--link kafka
在docker run。有关链接容器的信息,请参阅docker文档同样重要的是,您需要将kafka容器链接到zookeeper容器,并将schema registry链接到一个或另一个zk或kafka,具体取决于它的配置方式。
https://docs.confluent.io/current/installation/docker/docs/quickstart.html
这里还有Kafka Docker 的例子
topicauthorizationexception:无权访问主题:[test]
这表示已成功连接到kafka容器。下一步是确保java环境具有通过ssl访问代理所需的密钥