查看Kafka主题列表

$KAFKA_HOME/bin/kafka-topics.sh \
--zookeeper centos7-02:2181,centos7-03:2181,centos7-04:2181 \
--list

创建一个主题(Topic)

$KAFKA_HOME/bin/kafka-topics.sh \
--zookeeper centos7-02:2181,centos7-03:2181,centos7-04:2181 \
--create \
--replication-factor 3 \
--partitions 1 \
--topic TOPIC-01

参数说明:

--create 参数命令:创建
--replication-factor 指定副本数量(副本数小于等于集群数)
--partitions 指定分区数量
--topic 指定主题名字

执行输出:

[root@centos7-02 ~]# $KAFKA_HOME/bin/kafka-topics.sh \
> --zookeeper centos7-02:2181,centos7-03:2181,centos7-04:2181 \
> --create \
> --replication-factor 3 \
> --partitions 1 \
> --topic TOPIC-01
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
Created topic "TOPIC-01".

删除主题

$KAFKA_HOME/bin/kafka-topics.sh \
--zookeeper centos7-02:2181,centos7-03:2181,centos7-04:2181 \
--delete \
--topic TOPIC-01

向主题发送消息和消费消息

窗口1发送

# 发送消息 (终端占用)
$KAFKA_HOME/bin/kafka-console-producer.sh \
--broker-list centos7-02:9092,centos7-03:9092,centos7-04:9092 \
--topic TOPIC-01

窗口2消费

# 消费消息
$KAFKA_HOME/bin/kafka-console-consumer.sh \
--bootstrap-server centos7-02:9092,centos7-03:9092,centos7-04:9092 \
--topic TOPIC-01

全部获取消费

# 消费消息 格式3
# --from-beginning:会把主题中以往所有的数据都读取出来。
$KAFKA_HOME/bin/kafka-console-consumer.sh \
--bootstrap-server centos7-02:9092,centos7-03:9092,centos7-04:9092 \
--from-beginning \
--topic TOPIC-01

查看具体主题的状态:

$KAFKA_HOME/bin/kafka-topics.sh \
--zookeeper centos7-02:2181,centos7-03:2181,centos7-04:2181 \
--describe \
--topic TOPIC-01

执行输出:

[root@centos7-02 ~]# $KAFKA_HOME/bin/kafka-topics.sh \
> --zookeeper centos7-02:2181,centos7-03:2181,centos7-04:2181 \
> --describe \
> --topic TOPIC-01
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
Topic:TOPIC-01 PartitionCount:1 ReplicationFactor:3 Configs:
Topic: TOPIC-01 Partition: 0 Leader: 1 Replicas: 1,2,0 Isr: 1,2,0

更改主题的分区数量

$KAFKA_HOME/bin/kafka-topics.sh \
--zookeeper centos7-02:2181,centos7-03:2181,centos7-04:2181 \
--alter \
--partitions 2 \
--topic TOPIC-01

执行输出:

[root@centos7-02 ~]# $KAFKA_HOME/bin/kafka-topics.sh \
> --zookeeper centos7-02:2181,centos7-03:2181,centos7-04:2181 \
> --alter \
> --partitions 2 \
> --topic TOPIC-01
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected
Adding partitions succeeded!

注意,分区的数量只能增加,不能减少,改小了报错

改小的执行输出:

[root@centos7-02 ~]# $KAFKA_HOME/bin/kafka-topics.sh \
> --zookeeper centos7-02:2181,centos7-03:2181,centos7-04:2181 \
> --alter \
> --partitions 1 \
> --topic TOPIC-01
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected
Error while executing topic command : The number of partitions for a topic can only be increased. Topic TOPIC-01 currently has 2 partitions, 1 would not be an increase.
[2022-01-31 16:14:02,014] ERROR org.apache.kafka.common.errors.InvalidPartitionsException: The number of partitions for a topic can only be increased. Topic TOPIC-01 currently has 2 partitions, 1 would not be an increase.
(kafka.admin.TopicCommand$)

【Kafka】03 Shell 操作的更多相关文章

  1. shell操作典型案例--FTP操作

    从FTP服务器上下载文件或上传文件到FTP服务器是生产环境中比较常见的场景之一. shell操作FTP的方式整理如下: 思路一:使用shell调用ftp等客户端 使用FTP方式,通过shell调用ft ...

  2. Zookeeper学习之路 (三)shell操作

    Zookeeper的shell操作 Zookeeper命令工具 在启动Zookeeper服务之后,输入以下命令,连接到Zookeeper服务: [hadoop@hadoop1 ~]$ zkCli.sh ...

  3. HDFS的基本shell操作,hadoop fs操作命令

    (1)分布式文件系统 随着数据量越来越多,在一个操作系统管辖的范围存不下了,那么就分配到更多的操作系统管理的磁盘中,但是不方便管理和维护,因此迫切需要一种系统来管理多台机器上的文件,这就是分布式文件管 ...

  4. Hadoop读书笔记(二)HDFS的shell操作

    Hadoop读书笔记(一)Hadoop介绍:http://blog.csdn.net/caicongyang/article/details/39898629 1.shell操作 1.1全部的HDFS ...

  5. HDFS建筑与shell操作

    一个.hadoop1.1.0演示 hadoop它适合于大容量数据存储和分布式计算平台 hadoop核心由hdfs和mapreduce组成 hdfs这是一个主从结构,仅有一个.是namenode:从节点 ...

  6. Linux shell 操作 postgresql,并设置crontab任务

    Linux shell 操作 postgresql:删除间隔日期的数据-删除指定日期的数据-vacuumdb 清理数据库 -清理日志 -定期执行脚本 *修改pg_hba.conf 设置本地连接无密码, ...

  7. 每篇半小时1天入门MongoDB——2.MongoDB环境变量配置和Shell操作

    上一篇:每篇半小时1天入门MongoDB——1.MongoDB介绍和安装 配置环境变量 Win10系统为例 右键单击“此电脑”——属性——高级系统设置——高级——环境变量,添加C:\Program F ...

  8. Kafka命令行操作及常用API

    一.Kafka命令行操作 1.查看当前集群已存在的主题 bin/kafka-topic.sh --zookeeper hd09-01:2181 --list 2.创建主题 bin/kafka-topi ...

  9. 4、Kafka命令行操作

    Kafka命令行操作 1)查看当前服务器中的所有topic [test@ip101 kafka]$ bin/kafka-topics.sh --zookeeper ip101:2181 --list ...

  10. Hadoop2.7.6_04_HDFS的Shell操作与常见问题

    1. HDFS的shell操作 1.1. 支持的命令及参数 [yun@mini05 zhangliang]$ hadoop fs Usage: hadoop fs [generic options] ...

随机推荐

  1. k8s 安装ingress nginx controller 并部署.net core ingress服务

    k8s 安装ingress nginx controller 并部署.net core ingress服务 本地k8s集群概览 192.168.28.132 k8smaster 192.168.28. ...

  2. 像 Google SRE 一样 OnCall

    在 Google SRE 的著作<Google运维解密>(原作名:Site Reliability Engineering: How Google Runs Production Syst ...

  3. 第四届物联网与机器学习国际学术会议(IoTML 2024)

    [ACM独立出版,高录用,见刊检索快速稳定]第四届物联网与机器学习国际学术会议(IoTML 2024) [IoTML 2023会后三个半月内完成EI检索]2024 4th International ...

  4. gitlab自动定时备份文件,备份失败发送邮件

    一.需求 为预防gitlab出现故障,每天定时备份,备份完成后把之前的备份文件删除,备份成功或失败的时候自动发送邮件提醒,这里的gitlab为docker部署. 二.备份命令准备 1)备份命令 创建一 ...

  5. 解读MySQL 8.0数据字典的初始化与启动

    本文分享自华为云社区<MySQL全文索引源码剖析之Insert语句执行过程>,作者:GaussDB 数据库. 本文主要介绍MySQL 8.0数据字典的基本概念和数据字典的初始化与启动加载的 ...

  6. Windows下USB声卡音量调整

    买了一个绿联的USB声卡, 但是默认的音量太大了,最低音量都响的不行. 查了一下, 发现了一个叫EqualizerAPO的软件可以调整输出设备的音量. https://equalizerapo.com ...

  7. ZYNQ:使用SDK打包BOOT.BIN、烧录BOOT.BIN到QSPI-FLASH

    打包程序为BOOT.BIN 注意,做好备份是一个好习惯. Vivado Vivado 添加QSPI Flash的IP,重新编译: Launch SDK(推荐方法):或者用SDK指定一个workspac ...

  8. Freertos学习:02-FreeRTOSConfig.h

    --- title: rtos-freertos-02-FreeRTOSConfig.h EntryName: rtos-freertos-02-FreeRTOSConfig date: 2020-0 ...

  9. P9210 题解

    学长给我们讲了就顺便来写一篇题解. 首先最优解一定包括根,不然一定可以从当前根连接一条到根的链. 然后考虑假若最大导出子树深度为 \(n\) 则显然可以把深度为 \(n\) 的节点全部选上,然后每个节 ...

  10. SpringBoot 解决跨域问题

    今天遇到一个很神奇的问题,之前写的项目,后端跨域都处理好的,按部就班使用原来的方式,前后端都开发完之后,部署本地后,跨域没起效,一脸懵逼,然后使用公司另外一个同事的跨域解决方案,具体我也没深入研究到底 ...