kafka系列之安装及初步使用,单节点部署使用(一)

1、下载kafka,因为公司使用的版本是0.9的,所以在官网找到该版本下载。链接地址:
http://mirror.bit.edu.cn/apache/kafka/0.9.0.1/
2、kafka自带了zookeeper,可以不用下载zookeeper。
3、解压kafka压缩包。
tar -zxvf kafka_2.11-0.9.0.1.tgz
cd kafka_2.11-0.9.0.1
4、因为kafka依赖zookeeper,需要先启动zookeeper,zookeeper的配置文件是在config/zookeeper.properties,默认使用端口2181。
bin/zookeeper-server-start.sh config/zookeeper.properties&
后面加&的作用是释放鼠标,可以继续输入下一个命令。
5、启动kafka,kafka的配置文件在config/server.properties,默认使用端口号是9092。
bin/kafka-server-start.sh config/server.properties&
6、创建topic,topic名称为test,该topic的分区为1个,副本因子为1。
bin/kafka-topics.sh –create –zookeeper localhost:2181 –replication-factor 1 –partitions 1 –topic test
7、查看注册在该zookeeper上的所有的topic。
bin/kafka-topics.sh –list –zookeeper localhost:2181
8、模拟向topic为test的发送消息。
bin/kafka-console-producer.sh –broker-list localhost:9092 –topic test
This is a test message.
This is annother test message.
heheda.
9、启动消费者消费。查看消费的消息。
bin/kafka-console-consumer.sh –bootstrap-server localhost:9092 –topic test –from-beginning –zookeeper localhost:2181
This is a test message.
This is annother test message.
heheda
效果如下图:
生产者:
生产者
消费者:
消费者
10、关闭zookeeper/kafka
1)bin/zookeeper-server-stop.sh
2)bin/kafka-server-stop.sh

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值