码迷,mamicode.com
首页 > 其他好文 > 详细

Kafka的使用和错误解决

时间:2018-11-20 18:18:32      阅读:1684      评论:0      收藏:0      [点我收藏+]

标签:解压缩   port   --   解压   read   apache   环境   .sh   admin   

Kafka的使用和错误解决

一、下载kafka解压缩:配置环境变量

vim /etc/profile

export KAFKA_HOME=/root/kafka_2.11-1.0.0
export PATH=$PATH:$KAFKA_HOME/bin

source /etc/profile

二 、kafka中需要使用zookeeper

  1. 先将zookeeper启动,如果在伪分布式下,kafka已经集成了zk,在kafka中的config目录下。

       可以编辑config/zookeeper.properties修改zookeeper的端口号。

    后台启动zookeeper:
    [root@mail bin]# nohup zookeeper-server-start.sh ../config/zookeeper.properties &

  2. 启动broker
`[root@mail bin]# nohup kafka-server-start.sh ../config/server.properties &`

3.测试:模拟消息的消费和生产

(1)创建主题

[root@mail bin]# kafka-topics.sh --create --zookeeper localhost:2281 --topic KafkaTestTopic --partitions 1 --replication-factor 1

Created topic "KafkaTestTopic".

(2)创建生产者

[root@mail bin]# kafka-console-producer.sh --topic KafkaTestTopic --broker-list localhost:9092

查看server.properties中的#listeners=PLAINTEXT://:9092,获取kafka的端口

(3)创建消费者

[root@mail bin]# kafka-console-consumer.sh --topic KafkaTestTopic --zookeeper localhost:2281

三、可能出现的错误:
(1)
[root@mail bin]# kafka-topics.sh --create --zookeeper localhost:2281 --topic KafkaTestTopic --partitions 1 --replication-factor 1
Error while executing topic command : Replication factor: 1 larger than available brokers: 0.
[2018-11-20 16:44:16,269] ERROR org.apache.kafka.common.errors.InvalidReplicationFactorException: Replication factor: 1 larger than available brokers: 0.
(kafka.admin.TopicCommand$)

解决:修改server.properties中的:zookeeper.connect=localhost:2281,让2281端口号和zookeeper.properties中的zookeeper端口号一致,然后重启kafka。**

(2)
kafka.common.KafkaException: fetching topic metadata for topics [Set(KafkaTestTopic)] from broker [ArrayBuffer(BrokerEndPoint(0,123.125.50.7,9092))] failed
at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:77)
at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:98)
at kafka.consumer.ConsumerFetcherManager$LeaderFinderThread.doWork(ConsumerFetcherManager.scala:67)
(3)
[2018-11-20 17:28:53,411] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 52 : {KafkaTestTopic=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
[2018-11-20 17:28:53,513] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 53 : {KafkaTestTopic=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
[2018-11-20 17:28:53,617] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 54 : {KafkaTestTopic=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
[2018-11-20 17:28:53,721] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 55 : {KafkaTestTopic=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

解决(2)和(3)的错误:
修改server.properties中的
(1) listeners=PLAINTEXT://localhost:9092
(2) advertised.listeners=PLAINTEXT://localhost:9092

Kafka的使用和错误解决

标签:解压缩   port   --   解压   read   apache   环境   .sh   admin   

原文地址:http://blog.51cto.com/59465168/2319494

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!