kafka常用命令

查看主题

./kafka-topics.sh --list --bootstrap-server 10.1.1.2:9092

创建主题

./kafka-topics.sh --bootstrap-server 10.1.1.2:9092 --create --topic mytopic --partitions 1

查看消费者列表--list

./kafka-consumer-groups.sh --bootstrap-server 10.1.1.2:9092 --list

查看消费者组详情--describe

查看指定消费组详情--group

./kafka-consumer-groups.sh --bootstrap-server 10.1.1.2:9092 --describe --group defaultConsumerGroup

查看所有消费组详情--all-groups

./kafka-consumer-groups.sh --bootstrap-server 10.1.1.2:9092 --describe --all-groups

查询消费者成员信息--members

所有消费组成员信息

./kafka-consumer-groups.sh --describe --all-groups --members --bootstrap-server 10.1.1.2:9092

指定消费组成员信息

./kafka-consumer-groups.sh --describe --members --group defaultConsumerGroup --bootstrap-server 10.1.1.2:9092

修改到最新offset

./kafka-consumer-groups.sh --bootstrap-server 10.1.1.2:9092 --group defaultConsumerGroup --reset-offsets --topic mytopic --to-latest --execute

重设位移位置

./kafka-consumer-groups.sh --bootstrap-server 10.1.1.2:9092 --group defaultConsumerGroup --reset-offsets --topic mytopic --to-offset 100 --execute

重设位移有几种选项:

--to-earliest: 设置到最早位移处,也就是0

--to-latest: 设置到最新处,也就是主题分区HW的位置

--to-offset NUM: 指定具体的位移位置

--shift-by NUM: 基于当前位移向前回退多少

--by-duration: 回退到多长时间

消费组参数说明:

CURRENT-OFFSET: 当前消费者位移

LOG-END-OFFSET: 分区最新位移

LAG: LOG-END-OFFSET减去CURRENT-OFFSET的值,表示积压量

CONSUMER-ID: 是Kafka自己生成的

CLIENT-ID: 是消费者代码里写的CLIENT ID,用于区分同消费者组中的不同客户端

删除指定topic与数据

./kafka-topics.sh --bootstrap-server 10.1.1.2:9092 --delete --topic inventory_topic

全局设置

修改 server.properties,如下的值:

log.retention.hours=72

log.cleanup.policy=delete

单独对某一个topic设置过期时间

但如果只有某一个topic数据量过大,想单独对这个topic的过期时间设置短点:

./kafka-configs.sh --zookeeper localhost:2181 --alter --entity-name mytopic --entity-type topics --add-config retention.ms=86400000

retention.ms=86400000 为一天,单位是毫秒。

三、查看设置:

$ ./kafka-configs.sh --zookeeper localhost:2181 --describe --entity-name mytopic --entity-type topics

Configs for topics:wordcounttopic are retention.ms=86400000

四、立即删除某个topic下的数据

./kafka-topics.sh --zookeeper localhost:2181 --alter --topic mytopic --config cleanup.policy=delete

相关推荐
0xDevNull7 小时前
Linux切换JDK版本详细教程
linux
进击的丸子7 小时前
虹软人脸服务器版SDK(Linux/ARM Pro)多线程调用及性能优化
linux·数据库·后端
初次攀爬者1 天前
Kafka的Rebalance基础介绍
后端·kafka
Johny_Zhao2 天前
OpenClaw安装部署教程
linux·人工智能·ai·云计算·系统运维·openclaw
初次攀爬者2 天前
Kafka + KRaft模式架构基础介绍
后端·kafka
初次攀爬者2 天前
Kafka + ZooKeeper架构基础介绍
后端·zookeeper·kafka
初次攀爬者2 天前
Kafka 基础介绍
spring boot·kafka·消息队列
chlk1233 天前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑3 天前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件3 天前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux