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

来源:互联网 发布:淘宝1元包邮怎么赚钱 编辑:程序博客网 时间:2024/06/04 03:53

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

原创粉丝点击