首页 > 系统相关 >linux系统,kafka常用命令

linux系统,kafka常用命令

时间:2023-07-20 15:36:48浏览次数:44  
标签:-- 常用命令 server topic sh linux test kafka

kafka版本过高所致,2.2+=的版本,已经不需要依赖zookeeper来查看/创建topic,新版本使用 --bootstrap-server替换老版本的 --zookeeper-server。

[root@kwephis1160698 bin]# ./kafka-topics.sh --list --zookeeper localhost:2181
Exception in thread "main" joptsimple.UnrecognizedOptionException: zookeeper is not a recognized option
        at joptsimple.OptionException.unrecognizedOption(OptionException.java:108)
        at joptsimple.OptionParser.handleLongOptionToken(OptionParser.java:510)
        at joptsimple.OptionParserState$2.handleArgument(OptionParserState.java:56)
        at joptsimple.OptionParser.parse(OptionParser.java:396)
        at kafka.admin.TopicCommand$TopicCommandOptions.<init>(TopicCommand.scala:567)
        at kafka.admin.TopicCommand$.main(TopicCommand.scala:47)
        at kafka.admin.TopicCommand.main(TopicCommand.scala)

1、开启动
./kafka-server-start.sh ../config/server.properties

后台启动
./kafka-server-start.sh -daemon ../config/server.properties

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

2、停止
./kafka-server-stop.sh

3、查看topic列表

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

[root@071-009-058-079 bin]# ./kafka-topics.sh --bootstrap-server localhost:9092 --list
__consumer_offsets
test

4、创建topic,指定分区数、副本数

./kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test_002

[root@071-009-058-079 bin]# ./kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 3 --topic test_002
WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to use either, but not both.
Created topic test_002.
[root@071-009-058-079 bin]# ./kafka-topics.sh --bootstrap-server localhost:9092 --list
__consumer_offsets
test
test_002

5、查看topic详情,包括 Partition 个数,副本数,ISR 信息

./kafka-topics.sh  --bootstrap-server localhost:9092 --describe --topic test

[root@071-009-058-079 bin]# ./kafka-topics.sh  --bootstrap-server localhost:9092 --describe --topic test
Topic: test     TopicId: P_594pX_Q7q5ggCdCCjJ4Q PartitionCount: 1       ReplicationFactor: 1    Configs: 
        Topic: test     Partition: 0    Leader: 0       Replicas: 0     Isr: 0

6、修改指定 Topic 的 Partition 个数

./kafka-topics.sh  --bootstrap-server localhost:9092 --alter --topic test_002 --partitions 5

[root@071-009-058-079 bin]# ./kafka-topics.sh  --bootstrap-server localhost:9092 --list
__consumer_offsets
test
test_002
[root@071-009-058-079 bin]# ./kafka-topics.sh  --bootstrap-server localhost:9092 --describe --topic test_002
Topic: test_002 TopicId: QLwblYmBSx2HbTsppVokUQ PartitionCount: 3       ReplicationFactor: 1    Configs: 
        Topic: test_002 Partition: 0    Leader: 0       Replicas: 0     Isr: 0
        Topic: test_002 Partition: 1    Leader: 0       Replicas: 0     Isr: 0
        Topic: test_002 Partition: 2    Leader: 0       Replicas: 0     Isr: 0
[root@071-009-058-079 bin]# ./kafka-topics.sh  --bootstrap-server localhost:9092 --alter --topic test_002 --partitions 5 
[root@071-009-058-079 bin]# 
[root@071-009-058-079 bin]# ./kafka-topics.sh  --bootstrap-server localhost:9092 --describe --topic test_002
Topic: test_002 TopicId: QLwblYmBSx2HbTsppVokUQ PartitionCount: 5       ReplicationFactor: 1    Configs: 
        Topic: test_002 Partition: 0    Leader: 0       Replicas: 0     Isr: 0
        Topic: test_002 Partition: 1    Leader: 0       Replicas: 0     Isr: 0
        Topic: test_002 Partition: 2    Leader: 0       Replicas: 0     Isr: 0
        Topic: test_002 Partition: 3    Leader: 0       Replicas: 0     Isr: 0
        Topic: test_002 Partition: 4    Leader: 0       Replicas: 0     Isr: 0

7、删除Topic

./kafka-topics.sh  --bootstrap-server localhost:9092 --delete --topic test_002

只会删除zookeeper中的元数据,消息文件须手动删除

[root@071-009-058-079 bin]# ./kafka-topics.sh  --bootstrap-server localhost:9092 --list
__consumer_offsets
test
test_002
[root@071-009-058-079 bin]# ./kafka-topics.sh  --bootstrap-server localhost:9092 --delete --topic test_002
[root@071-009-058-079 bin]# ./kafka-topics.sh  --bootstrap-server localhost:9092 --list
__consumer_offsets
test

8、控制台生产消息
./kafka-console-producer.sh --broker-list localhost:9092 --topic test

[root@071-009-058-079 bin]# ./kafka-console-producer.sh --broker-list localhost:9092 --topic test
>hello
>nihao
>haha

9、控制台消费消息

a)消费消息从头开始

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

b)消费从最新的开始

./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --offset latest --partition 0

10、其它(暂未详细补充)

./kafka-run-class.sh kafka.tools.GetOffsetShell --topic test01  --time -1 --broker-list 0.0.0.0:9092 --partitions 2
结果:test01:2:12495

彻底删除topic,要到zookeeper客户端
    --(1)删除kafka存储目录(server.properties文件log.dirs配置,默认为"/tmp/kafka-logs")相关topic目录
    --(2)如果配置了delete.topic.enable=true直接通过命令删除,如果命令删除不掉,直接通过zookeeper-client 删除掉broker下的topic即可。
    
step1:cd /usr/local/zookeeper-3.6.2/bin/
step2:进入zookeeper客户端
    # ./zkCli.sh
step3:查看有哪些topics./zkCli.sh./
    # ls /brokers/topics
step4:删除某一topic
    # deleteall  /brokers/topics/test02

./kafka-consumer-groups.sh --bootstrap-server kafkadev:9091 --list --command-config ../config/producer.properties
./kafka-consumer-groups.sh --bootstrap-server 0.0.0.0:9092,0.0.0.0:9092,0.0.0.0:9092 --list --command-config ../config/producer.properties
查看kafka服务是否启动
jps -l
ps -ef|grep kafka

标签:--,常用命令,server,topic,sh,linux,test,kafka
From: https://www.cnblogs.com/cavan2021/p/15473254.html

相关文章

  • docker常用命令
    dockeroperationcommand:查询镜像sudodockerimages删除镜像dockerrmibf756fb1ae65(镜像id)#启动镜像#sudodockerrun-it-d--nametest01ubuntu18.04:docker_test1/bin/sh创建macvlan网络sudodockernetworkcreate-dmacvlan--subnet=172.16.2.1/23--......
  • windows10下安装kafka
    安装JDK下载地址:www.oracle.com/java/technologies/downloads我是装的java17.0.8X64Installer,不是javer所以不懂区别。下好以后开始安装,一路下一步就是了,安装目录装在的D盘 D:\kafka\jdk-17.0.1现在开始添加环境变量在用户变量path里添加 %JAVA_HOME%\bin和 %JAVA_HO......
  • linux 8- 线程 守护进程
    linux8day1.终端在unix系统中用户通过终端登录系统得到shell进程,这个终端成为shell进程的控制终端前台进程于后台进程tty可以直接获取终端函数说明:#include<unistd.h>char*ttyname(intfd);功能:由文件描述符查出对应的文件名参数:fd:文件描述符返回值:成功:......
  • linux9 互斥锁 死锁 读写锁 条件变量 信号量
    1.linux9day1.线程竞争![01-打印机模型](I:\9day\01-打印机模型.png)2.同步和互斥互斥同一时刻只能一个进程或线程使用多个进程或线程不能同时使用同步:是指散步在不同任务之间的若干程序片断,它们的运行必须严格按照规定的某种先后次序来运行,这种先后次序依赖于要完成的特......
  • linux环境中,一个目录下,除了特定的目录和这个目录里面的内容,删除所有其他的目录和文件
    有个tomcat目录,如下: [[email protected]]#ls-ltotal148drwxr-x---2rootroot4096Jul2014:37bin-rw-r-----1rootroot19992May421:04BUILDING.txtdrwx------2rootroot4096May421:04conf-rw-r-----1rootroot62......
  • Linux服务器上设置或修改ip
    临时修改永久修改1、超级用户修改配置文件:/etc/sysconfig/network-scripts/ifcfg-${网卡名},模板可以参考下边的···TYPE=EthernetPROXY_METHOD=noneBROWSER_ONLY=noBOOTPROTO=staticDEFROUTE=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=y......
  • linux7-信号
    1.信号的概念信号->电话铃声是一种抽象的概念接电话->动作信号是软件中断,它是在软件层次上对中断机制的一种模拟,是一种异步通信的方式。信号可以导致一个正在运行的进程被另一个正在运行的异步进程中断,转而处理某一个突发事件。![信号实现](I:\7day\信号实现.png)一个完......
  • Linux 下运行.NET 6 7 8 程序遇到的两个问题
    一、/lib64/libstdc++.so.6:version`GLIBCXX_3.4.21‘notfound的解决办法1.下载libstdc++.so.6.0.21文件注意区分x84_64和aarch64架构,下载对应的版本2.把libstdc++.so.6.0.21复制到/lib64/libstdc++.so.6.0.213.运行命令exportLD_PRELOAD="/lib64/libstdc++.s......
  • 【项目实战】Java 开发 Kafka 生产者
    ......
  • 【项目实战】Java 开发 Kafka 消费者
    ......