当前位置: 首页 > article >正文

Kafka常用指令(详细)

Kafka常用指令(详细)

启停命令

前台启动

前台启动命令
./bin/kafka-server-start.sh config/server.properties

后台启动方式1

后台启动命令加上参数-daemon,窗口关闭之后kafka后台程序继续运行
./bin/kafka-server-start.sh -daemon config/server.properties

后台启动方式2

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

停止命令

./bin/kafka-server-stop.sh

Topic命令相关

创建Topic

bin/kafka-topics.sh -zookeeper localhost:2181 --create --partitions 5 --replication-factor 2 --topic test_topic
参数说明:
localhost:2181:zk的IP地址和端口号;
–partitions 5:创建主题分区数量为5;
== --replication-factor 2==:创建主题分区副本为2;
–topic topic_name:创建主题名称为topic_name。

查询Topic列表

列出指定服务器主题
./bin/kafka-topics.sh --bootstrap-server 192.168.1.1:9092 --list
列出kafka集群中的主题列表,192.168.1.1:9092,192.168.1.2:9092为多个kafka服务地址
./bin/kafka-topics.sh --bootstrap-server 192.168.1.1:9092,192.168.1.2:9092 --list

查询Topic详细信息

查询指定主题详细信息
./bin/kafka-topics.sh --bootstrap-server localhost:9092 --topic topic_name --describe
查询多个kafka的主题详细信息
./bin/kafka-topics.sh --bootstrap-server 192.168.1.1:9092,192.168.1.2:9092 --topic topic_name --describe
删除指定的Topic
./bin/kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic topic_name
修改主题的分区数,注意:分区数只能增加不能减少
./bin/kafka-topics.sh --bootstrap-server localhost:9092 --alter --topic topic_name --partitions 3
在这里插入图片描述

Procuder命令相关

发送消息

./bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic topic_name
在这里插入图片描述
#Consumer命令相关

指定主题从最新位置开始消费

消费topic_name中的最新消息
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic_name
消费topic_name中的所有消息,包含历史消息
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic topic_name
消费者组消费主题信息
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic_name --group groupId

在这里插入图片描述


http://www.kler.cn/a/580543.html

相关文章:

  • 阿里云操作系统控制台实战评测:提升云资源管理与监控效率
  • 加油站小程序实战教程10用户登录授权
  • 《网络安全》中RSA加密算法的计算过程
  • 一学就会的深度学习基础指令及操作步骤(6)迁移学习
  • mysql部分概念解答(索引、事务数据字典、MVCC、单表文件表空间与通用表空间、元数据、重做日志和还原日志)
  • 正则表达式(复习)
  • FPGA基础 -- 仿真初识
  • 开源、创新与人才发展:机器人产业的战略布局与稚晖君成功案例解析
  • 用DEEPSEEK做数据看板:高效、实用与创新的融合
  • 算法008——四数之和
  • 深度学习模型训练过程的加速方法介绍
  • 【大前端】【Android】whistle配置Android手机代理脚本
  • Yashan DB 存储结构
  • python语言API接口采集电商平台数据,json数据格式
  • SpringBoot全栈开发:从数据库到Markdown文件导出的终极实践指南
  • 并发服务器的实现
  • 虚幻C++插件胚胎级入门 | Slate Widget开发
  • 【09】单片机编程核心技巧:变量赋值,从定义到存储的底层逻辑
  • 机器学习(李宏毅)——Auto-Encoder
  • 基于SpringBoot+Vue的瑜伽课体验课预约系统【附源码】