1、下载和安装

目前kafka的稳定版本为0.10.0.0

下载地址:http://kafka.apache.org/downloads.html

下载后解压缩安装包到系统即可完成安装

> tar -xzf kafka_2.-0.10.0.0.tgz
> cd kafka_2.-0.10.0.0

2、运行kafka服务

kafka依赖于zookeeper服务提供调度。因此在启动kafka之前,需要启动zookeeper。

如果你本地之前没有安装过zookeeper服务,kafka已提供一个内置zookeeper服务供您使用。

> bin/zookeeper-server-start.sh config/zookeeper.properties &

启动zookeeper完成后,再来启动kafka服务:

> bin/kafka-server-start.sh config/server.properties &

如果在启动过程中,报错信息为: replication factor: 1 larger than available brokers: 0

这是因为brokers和replication不匹配造成的

解决方法:在server.properties中 配置 offsets.topic.replication.factor=1

3、创建Topic

创建一个只包含一个patition和一个replication的名为'test'的Topic

> bin/kafka-topics.sh 
  --create
  --zookeeper localhost:
  --replication-factor
  --partitions
  --topic test

查看Topic列表:

> bin/kafka-topics.sh
--list
--zookeeper localhost:

查看创建的topic的详细信息:

>bin/kafka-topics.sh
--describe
--zookeeper localhost:
--topic test

4、使用producer向kafka中推送一个消息

Run the producer and then type a few messages into the console to send to the server.

> bin/kafka-console-producer.sh
--broker-list localhost:
--topic test This is a message
This is another message

通常这一步是由程序来执行,具体API参考官网。

5、查看推送到kafka的消息

> bin/kafka-console-consumer.sh
--zookeeper localhost:
--topic test
--from-beginning

番外:设置一个多broker的集群kafka服务

上述的安装和启动是基于单个broker。现在我们需要拓展下我们的集群,在一台server上安装一个包含3个broker的伪集群kafka服务。

首先,拷贝配置文件server.properties并改名:

> cp config/server.properties config/server-.properties
> cp config/server.properties config/server-.properties

其次,修改配置文件中的如下属性:

config/server-1.properties:
broker.id=1
listeners=PLAINTEXT://:9093
log.dir=/tmp/kafka-logs-1 config/server-2.properties:
broker.id=2
listeners=PLAINTEXT://:9094
log.dir=/tmp/kafka-logs-2

最后,启动新创建的这两个kafka服务:

> bin/kafka-server-start.sh config/server-.properties &
> bin/kafka-server-start.sh config/server-.properties &

现在我们可以创建一个备份为3的topic了

> bin/kafka-topics.sh 
  --create
  --zookeeper localhost:
  --replication-factor
  --partitions
  --topic my-replicated-topic

查看topic详细:

> bin/kafka-topics.sh
--describe
--zookeeper localhost:
--topic my-replicated-topic Topic:my-replicated-topic
PartitionCount:
ReplicationFactor:
Configs:
Topic: my-replicated-topic
  Partition:
  Leader:
  Replicas: ,,
  Isr: ,,

最新文章

  1. words
  2. 24个 HTML5 & CSS3 下拉菜单效果及制作教程
  3. Oracle插入时间
  4. NOIP2014 飞扬的小鸟
  5. KafkaSpout 浅析
  6. Bootstrap_排版_代码
  7. C#如何解决对ListView控件更新以及更新时界面闪烁问题
  8. Java多线程实现......(1,继承Thread类)
  9. 设计一个神经网络记住Or运算(日志一)
  10. 【特效】hover效果之十字动画
  11. 关于git post-receive 钩子
  12. 使用NPOI导出Excel引发异常(IsReadOnly = “book.IsReadOnly”引发了类型“System.NotImplementedException”的异常)
  13. android sqlite android.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5
  14. com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的区别
  15. Andorid 刷新样式一
  16. 关于form与表单操作
  17. Windows PowerShell 入門(10)-デバッグ編
  18. 对 Laravel 的 Controller 做 Unit Test
  19. 梯度下降法(BGD、SGD)、牛顿法、拟牛顿法(DFP、BFGS)、共轭梯度法
  20. Mybatis学习链接

热门文章

  1. 如何使你的Android应用记住曾经使用过的账户信息
  2. Java之JDBC①
  3. EditText: 自定义EditText 触摸时无法获取焦点
  4. 部署openfire到linux环境下
  5. Gridview排序与分页-不使用“DataSourceControl DataSource”的情况下如何分页和排序 ...
  6. RabbitMQ中各种消息类型如何处理?
  7. 基于jQuery会员中心安全修改表单代码
  8. js实现完美身份证号有效性验证(转)
  9. python 字符串和整数,浮点型互相转换
  10. JAVA ZIP 处理文件