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

linux系统,kafka常用命令的更多相关文章

  1. Linux 系统巡检常用命令

    Linux系统巡检常用命令   # uname -a # 查看内核/操作系统# cat /etc/centos-release # 查看centos操作系统版本# cat /proc/cpuinfo ...

  2. linux系统的常用命令

    linux系统中常用的命令如下(以后经常补充): cd ..   返回上一级 cd use  进入use目录

  3. 用xshell操作linux系统的常用命令

    (1)命令ls——列出文件 ls -la 给出当前目录下所有文件的一个长列表,包括以句点开头的“隐藏”文件 ls a* 列出当前目录下以字母a开头的所有文件 ls -l *.doc 给出当前目录下以. ...

  4. linux系统学习(常用命令)

    今天调休,闲来无事,研究一下linux系统. Linux常用命令: 一:文件管理 ctrl+alt:在虚拟机与windows之间切换ctrl+g:进入linux输入模式 pwd:查看当前目录 ls:列 ...

  5. Linux系统巡检常用命令-乾颐堂

    Linux系统需要定期巡检,以检查服务器软硬件使用情况,相当于对人的体检,确保可以及时发现问题.解决问题,降低损失,常用的巡检命令如下: # uname -a # 查看内核/操作系统/CPU信息 # ...

  6. Linux系统之-常用命令及技巧

    一. 通用命令:1.date :print or set the system date and time2. stty -a: 可以查看或者打印控制字符(Ctrl-C, Ctrl-D, Ctrl-Z ...

  7. Linux系统一些常用命令(持续增加)

    这些命令什么的全是从网上找的,防止忘记,留下来备忘 1.linux服务器如何从另一台服务器拷东西:可以用scp命令scp user@remote.machine:/remote/path /local ...

  8. LINUX系统一一常用命令

    前言 LINUX UNIX Centos RedHat Ubuntu SHELL shell脚本 shell shell命令 类似windows系统的bat 批处理文件 里面都是脚本 CentOS6. ...

  9. Linux 系统监控常用命令

    简介 列举操作系统级监控常用的几个方法,建议收藏使用 CPU top 命令可用于监控系统整体负载,包括cpu.内存使用等,能够实时显示系统中各个进程的资源占用状况 输出样例 top - 19:37:4 ...

  10. linux系统最常用命令(持续更新)

    1.重启服务器 ubuntu系统重启apache:/etc/init.d/apache2 restart linux重启nginx: service nginx restart 重新加载:servic ...

随机推荐

  1. 力扣66(java)-加一(简单)

    题目: 给定一个由 整数 组成的 非空 数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. ...

  2. Flink 在唯品会的实践

    简介: Flink 在唯品会的容器化实践应用以及产品化经验. 唯品会自 2017 年开始基于 k8s 深入打造高性能.稳定.可靠.易用的实时计算平台,支持唯品会内部业务在平时以及大促的平稳运行.现平台 ...

  3. 快手基于 Flink 构建实时数仓场景化实践

    简介: 一文了解快手基于 Flink 构建的实时数仓架构,以及一些难题的解决方案. 本文整理自快手数据技术专家李天朔在 5 月 22 日北京站 Flink Meetup 分享的议题<快手基于 F ...

  4. Nacos 开源、自研、商业化三位一体战略解读

    简介: Nacos作为整个阿里云原生三位战略中的核心组成部分,我们在2018年以Configserver/VIPServer/Diamond为基础通过Nacos开源输出阿里十年沉淀的注册中心和配置中心 ...

  5. [ML] 数据预处理 - 特性归一化的目的

    简而言之,归一化的目的就是使得预处理的数据被限定在一定的范围内(比如[0,1]或者[-1,1]), 从而消除奇异样本数据导致的不良影响. 是否归一化主要在于是否关心变量取值. Tool:ChatAI ...

  6. dotnet C# 在 finally 抛异常会发生什么

    如果我在一个方法的 finally 里面抛出异常,而在 try 里面也抛出,那在上层拿到的是什么 如下面代码 private void F1() { try { A(); } catch (Excep ...

  7. 还需要学习JDBC吗?如果需要该了解到怎么样的程度?

    前言 只有光头才能变强. 文本已收录至我的GitHub精选文章,欢迎Star:https://github.com/ZhongFuCheng3y/3y 不知道大家在工作中还有没有写过JDBC,我在大三 ...

  8. Kafka源码分析(四) - Server端-请求处理框架

    系列文章目录 https://zhuanlan.zhihu.com/p/367683572 一. 总体结构 先给一张概览图: 服务端请求处理过程涉及到两个模块:kafka.network和kafka. ...

  9. Vs2019在发布过程中遇到xxx-Web.config Connection String"参数不能为 Null 或 空 的错误

    原文地址:https://www.zhaimaojun.top/Note/5465234 如下图: 当使用的数据库更换或者修改后数据库字段会失效,当我们从webconfig中清除数据库字段后,依然会报 ...

  10. iptables命令详解

    安装iptables yum install iptables-services 编写允许访问的策略 vim /etc/sysconfig/iptables # sample configuratio ...