kafka 安装和操作命令
最编程
2024-04-25 19:15:33
...
安装kafka及操作命令
先安装jdk
安装kafka的条件:jdk、zookeeper
在新版kafka内置了zookeeper,先安装jdk即可
# ubuntu中安装
apt-get install openjdk-8-jdk
# 安装完后执行 java -version 能看到版本即安装成功
下载kafka
说明:
我的安装下载目录:/usr/local/src
安装目录: /usr/local/kafka
# 官网下载地址:
https://kafka.apachecn.org/downloads.html # 挑最新版下载
# 下载示例:
cd /usr/local/src
wget https://downloads.apache.org/kafka/3.5.0/kafka_2.12-3.5.0.tgz
tar -zxvf kafka_2.12-3.5.0.tgz
mv kafka_2.12-3.5.0 ../kafka
cd ../kafka/
实时运行:
# 先启动zookeeper
bin/zookeeper-server-start.sh config/zookeeper.properties
或后台运行:nohup bin/zookeeper-server-start.sh config/zookeeper.properties >/dev/null 2>&1 &
# 再启动kafka
bin/kafka-server-start.sh config/server.properties
或后台运行:nohup bin/kafka-server-start.sh config/server.properties >dev>null 2>&1 &
# 关闭
bin/zookeeper-server-stop.sh
bin/kafka-server-stop.sh
后台运行:
# 启动kafka即可,zookeeper是自动运行的
bin/kafka-server-start.sh -daemon config/server.properties
操作命令
# 启动生产者
bin/kafka-console-producer.sh --topic <topic-name> --bootstrap-server <broker-list>
例子:
bin/kafka-console-producer.sh --topic my-topic --bootstrap-server localhost:9092
# 启动消费者
bin/kafka-console-consumer.sh --bootstrap-server <broker-list> --topic <topic-name> --from-beginning --property print.timestamp=true --from-beginning就从最新的开始消费, --property print.timestamp=true 显示入kafka时间
例子:
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic my-topic --from-beginning --property print.timestamp=true
# 指定消费某个分区或偏移量(从第几条开始消费):--partition 2 --offset 3
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic my-topic --partition 2 --offset 3
# 指定消费时间
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic my-topic --from-beginning --property print.timestamp=true | awk -F 'CreateTime:|\t' '$2 >= 1688107994655 && $2 <= 1688107995686 {print $0}'
# 查看所有消费者
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
# 查看正在消费的组和
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group 1 #1是上一条命令查到的组
# 创建主题:创建一个名为together的主题,有2个分区,每个分区1个副本
bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic my-topic --partitions 2 --replication-factor 1 --config retention.ms=259200000
# 查看主题列表
bin/kafka-topics.sh --bootstrap-server localhost:9092 --list
# 查看主题详情:查看together主题的详情
bin/kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic together
# 删除主题
kafka-topics.sh --delete --topic my-topic --bootstrap-server localhost:9092
报错
- window下连接虚拟机中的kafka报错:failed to dial: failed to open connection to ubuntu-xenial:9092: dial tcp: lookup ubuntu-xenial: no such host
解决:在hosts中增加ip指向
虚拟机的ip 虚拟机系统名称
如:192.168.4.3 ubuntu-xenial
上一篇: Honky Tonk 本地应用程序笑话书
下一篇: 西部世界》女主角的爱情线一览!少女心碎
推荐阅读
-
C 语言学习路径 - 第一站 vs2022(Visual Studio)的安装和基本操作
-
B0102 Linux centos7.9 操作系统的安装和维护
-
使用 pip update 命令和清华镜像快速安装 OpenCV-python
-
第 2 章 文件和目录操作命令
-
树莓派 4B 使用 docker 安装 kafka 和 kafka-manger
-
ORCA 5.0 安装和操作
-
Linux *.tar.gz/.tar.bz2 文件提取和安装命令
-
使用 winzip 生成的扩展名为 -ZIP 的压缩文件通常使用".zip "扩展名,其 MIME 格式为 application/zip。(推荐学习:phpstorm) 目前,ZIP 格式属于几种主流压缩格式之一,其竞争对手包括 RAR 格式和开源的 7z 格式。 从性能对比来看,RAR 和 7z 格式比 ZIP 格式压缩率更高,而 7-Zip 由于提供免费压缩工具而逐渐在更多领域得到应用。 微软从 Windows ME 操作系统开始就内置了对 zip 格式的支持,即使用户没有在电脑上安装解压软件,也可以打开和创建 zip 格式的压缩文件,OS X 和流行的 Linux 操作系统也提供了类似的 zip 格式支持。 因此,如果要在网络上传播和分发文件,zip 格式往往是最常见的选择。
-
kafka 安装和操作命令
-
Linux 和 Raspberry Pi 4B:不使用图形用户界面,从零开始构建 Pagoda Panel Raspberry Pi 服务器_系统安装、连接 WiFi 和 SSH、安装 LNMP、关机命令、备份