栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

kafka 安装和启动

kafka 安装和启动

kafka中文教程 学习记录

首先准备好linux机器环境,参考此篇文章:快速搭建Linux服务器环境

单机版 1. 下载代码

https://kafka.apache.org/downloads.html

官方的下载链接比较慢,这里可以使用第三方下载转发的链接地址:

wget --no-check-certificate https://dl0.serctl.com/downloads8/2021-11-05-12-14-20--kafka_2.13-3.0.0.tgz
$ ll
total 84372
-rw-rw-r--. 1 vagrant vagrant 86396520 Sep 20 08:46 2021-11-05-12-14-20--kafka_2.13-3.0.0.tgz

$ tar -xzf 2021-11-05-12-14-20--kafka_2.13-3.0.0.tgz
$ cd kafka_2.13-3.0.0/
2. 启动服务

启动kafka 需要jdk环境,可参考这篇文章:在linux上面安装jdk

kafka自带打包和配置好的Zookeeper

启动Apache Kafka 内置的zookeeper
$ cd kafka_2.13-3.0.0/
$ bin/zookeeper-server-start.sh config/zookeeper.properties

启动kafka服务
$ cd kafka_2.13-3.0.0/
$ bin/kafka-server-start.sh config/server.properties

3. 创建一个主题(topic)

创建一个名为“test”的Topic,只有一个分区和一个备份

$ cd kafka_2.13-3.0.0/
$ bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test

查看已创建的topic信息:

$ cd kafka_2.13-3.0.0/
$ bin/kafka-topics.sh --describe --topic test --bootstrap-server localhost:9092
Topic: test     TopicId: DdW4QskuTH2DwnGvM0Mjdg PartitionCount: 1       ReplicationFactor: 1    Configs: segment.bytes=1073741824
        Topic: test     Partition: 0    Leader: 0       Replicas: 0     Isr: 0
4. 发送消息

生产者

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

5. 消费消息
$ cd kafka_2.13-3.0.0/
$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning


上面我们使用命令的方式简单演示了一下kafka的基本流程。

你有哪些疑问吗?

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/433935.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号