kafka安装和使用

安装 kafka

下载地址:http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.3.0/kafka_2.11-2.3.0.tgz

tar -zxvf kafka_2.11-2.3.0.tgz
cd /usr/local/kafka_2.11-2.3.0/

 

修改 kafka-server 的配置文件

vi /usr/local/kafkaa_2.11-2.3.0/config/server.properties

修改如下

broker.id=1
log.dir=/data/kafka/logs-1

常用功能

1、启动 zookeeper

使用安装包中的脚本启动单节点 Zookeeper 实例:

sh bin/zookeeper-server-start.sh -daemon config/zookeeper.properties

2、启动Kafka 服务

使用 kafka-server-start.sh 启动 kafka 服务:

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

3、创建 topic

使用 kafka-topics.sh 创建单分区单副本的 topic test:

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

查看是否创建成功

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

5、消费消息

使用 kafka-console-consumer.sh 接收消息并在终端打印:

 sh bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic second-kafka-topic--from-beginning

会卡在这里,启动一个窗口

输入命令

sh bin/kafka-console-producer.sh --broker-list localhost:9092 --topic second-kafka-topic

会出现箭头输入发送信息

 

这里就接受到了

 

6、查看描述 topics 信息

sh bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic second-kafka-topic

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值