kafka-topics.sh脚本详解
通过脚本进行主题的管理,包括:创建主题、查看主题、修改主题、删除主题等操作。内部是靠kafka.admin.TopicCommand
接收参数运行。
[xuhaixing@xhx151 ~]$ kafka-topics.sh --help
This tool helps to create, delete, describe, or change a topic.
Option Description
------ -----------
--alter Alter the number of partitions, replica assignment, and/or configuration for the topic.
--at-min-isr-partitions if set when describing topics, only show partitions whose isr count is equal to the configured minimum. Not supported with the --zookeeper option.
--bootstrap-server <String: server to REQUIRED: The Kafka server to connect connect to> to. In case of providing this, a direct Zookeeper connection won't be required.
--command-config <String: command Property file containing configs to be config property file> passed to Admin Client. This is used only with --bootstrap-server option for describing and altering broker configs.
--config <String: name=value> A topic configuration override for the topic being created or altered. The following is a list of valid configurations: cleanup.policy compression.type delete.retention.ms file.delete.delay.ms flush.messages flush.ms follower.replication.throttled. replicas index.interval.bytes leader.replication.throttled.replicas max.compaction.lag.ms max.message.bytes message.downconversion.enable message.format.version message.timestamp.difference.max.ms message.timestamp.type min.cleanable.dirty.ratio min.compaction.lag.ms min.insync.replicas preallocate retention.bytes retention.ms segment.bytes segment.index.bytes segment.jitter.ms segment.ms unclean.leader.election.enable See the Kafka documentation for full details on the topic configs. It is supported only in combination with --create if --bootstrap-server option is used (the kafka-configs CLI supports altering topic configs with a --bootstrap-server option).
--create Create a new topic.
--delete Delete a topic
--delete-config <String: name> A topic configuration override to be removed for an existing topic (see the list of configurations under the --config option). Not supported with the --bootstrap-server option.
--describe List details for the given topics.
--disable-rack-aware Disable rack aware replica assignment
--exclude-internal exclude internal topics when running list or describe command. The internal topics will be listed by default
--force Suppress console prompts
--help Print usage information.
--if-exists if set when altering or deleting or describing topics, the action will only execute if the topic exists.
--if-not-exists if set when creating topics, the action will only execute if the topic does not already exist.
--list List all available topics.
--partitions <Integer: # of partitions> The number of partitions for the topic being created or altered (WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected). If not supplied for create, defaults to the cluster default.
--replica-assignment <String: A list of manual partition-to-broker broker_id_for_part1_replica1 : assignments for the topic being broker_id_for_part1_replica2 , created or altered. broker_id_for_part2_replica1 : broker_id_for_part2_replica2 , ...>
--replication-factor <Integer: The replication factor for each replication factor> partition in the topic being created. If not supplied, defaults to the cluster default.
--topic <String: topic> The topic to create, alter, describe or delete. It also accepts a regular expression, except for --create option. Put topic name in double quotes and use the '\' prefix to escape regular expression symbols; e.g. "test\.topic".
--topics-with-overrides if set when describing topics, only show topics that have overridden configs
--unavailable-partitions if set when describing topics, only show partitions whose leader is not available
--under-min-isr-partitions if set when describing topics, only show partitions whose isr count is less than the configured minimum. Not supported with the --zookeeper option.
--under-replicated-partitions if set when describing topics, only show under replicated partitions
--version Display Kafka version.
--zookeeper <String: hosts> DEPRECATED, The connection string for the zookeeper connection in the form host:port. Multiple hosts can be given to allow fail-over.
kafka-topics.sh脚本中的参数
参数名称 | 释义 |
---|---|
alter | 用于修改主题 |
config 键值对 | 创建或修改主题时,用于设置主题级别的参数 |
create | 创建主题 |
delete | 删除主题 |
delete-config 配置名称 | 删除主题级别被覆盖的配置 |
describe | 查看主题的详细信息 |
disable-rack-aware | 创建主题时不考虑机架信息 |
help | 打印帮助信息 |
if-exists | 修改或删除主题时使用,只有当主题存在时才会执行动作 |
if-not-exists | 创建主题时使用,只有主题不存在时才会执行动作 |
list | 列出所有可用的主题 |
partitons 分区数 | 创建主题或增加分区时指定的分区数 |
replica-assignment 分配方案 | 手工指定分区副本分配方案 |
replication-factor 副本数 | 创建主题时指定副本因子 |
topic 主题名称 | 指定主题名称 |
topics-with-overrides | 使用describe查看主题信息时,只展示包含覆盖配置的主题 |
unavailable-partitions | 使用describe查看主题信息时,只展示包含没有leader副本的分区 |
under-replicated-partitions | 使用describe查看主题信息时,只展示包含失效副本的分区 |
zookeeper | 指定连接的zk的地址,已经过时,可以改成 --bootstrap-server |
1. 常用命令
查看所有topic
kafka-topics.sh --zookeeper 192.168.94.151:2181/kafka --list
kafka-topics.sh --bootstrap-server 192.168.94.151:9092 --list
创建topic
kafka-topics.sh --zookeeper 192.168.94.151:2181/kafka --create --topic test-topic --replication-factor 2 --partitions 3kafka-topics.sh --bootstrap-server 192.168.94.151:9092 --create --topic test-topic-2 --replication-factor 2 --partitions 3 --config retention.ms=36000000000 --config max.message.bytes=64000
查看topic配置信息
kafka-topics.sh --zookeeper 192.168.94.151:2181/kafka --describe --topic test-topic
扩大分区
kafka-topics.sh --zookeeper 192.168.94.151:2181/kafka --alter --topic test-topic --partitions 6
修改topic配置
kafka-topics.sh --bootstrap-server 192.168.94.151:9092 -topic test-topic --alter --config retention.ms=259200000
kafka topic config参数
cleanup.policy
过期或达到日志上限的清理策略(delete-删除;compact-压缩)默认值为delete
compression.type
指定给该topic最终的压缩类型(uncompressed;snappy;lz4;gzip;producer)默认值为producer
delete.retention.ms
压缩日志保留的最长时间,也是消费端消息的最长时间。单位为毫秒(默认值:86400000)
file.delete.delay.ms
从文件系统中删除前所等待的时间(默认值:60000)
flush.messages
在消息刷到磁盘前,日志分区收集的消息数(默认值:Long.MAX_VALUE)
flush.ms
消息刷到磁盘前,保存在内存中的最长时间,单位ms(默认值:Long.MAX_VALUE)
index.interval.bytes
当执行fetch操作后,需要一定的空间来扫描最近的offset大小。设置越大,扫描速度更快但更耗内存,一般情况下不用设置此参数。(默认值:4096)
max.message.bytes
log中能够容纳消息的最大字节数(默认值:1000012)
min.cleanable.dirty.ratio
日志清理的频率控制,越大清理更高效(默认值:0.5)
retention.bytes
topic每个分区的最大文件大小。(默认值:-1没有限制)
retention.ms
日志文件保留的ms。数据存储的最大时间超过这个时间会根据cleanup.policy策略处理数据。
segment.bytes
topic的文件是以segment文件存储的,该参数控制每个segment文件的大小(默认值:1073741824)
segment.index.bytes
对于segment日志的索引文件大小限制(默认值:10M)
实时内容请关注微信公众号,公众号与博客同时更新:程序员星星toC
kafka-topics.sh脚本详解相关推荐
- Kafka服务端脚本详解(2)一log,verifiable
2019独角兽企业重金招聘Python工程师标准>>> 脚本名称 脚本用途 kafka-log-dirs.sh 查看指定broker上日志目录使用情况 kafka-verifiabl ...
- Hadoop的hadoop-config.sh脚本详解
先简要说明下我的读该脚本的环境,集群是CDH5.3,在研究命令行中hadoop -jar ***.jar命令的相关脚本时,在hadoop文件中追到了hadoop-config.sh这个文件,所以下边的 ...
- shell脚本详解(二)——条件测试、if语句和case分支语句
shell脚本详解(二)--条件测试.if语句和case分支语句 一.条件测试 1.test命令 2.文件测试 3.整数值比较 4.字符串比较 5.逻辑测试 二.if条件语句 1.单分支 2.双分支 ...
- shell脚本详解(一)——初学shell脚本必看哦
shell脚本详解 一.Shell脚本概述 1.1.shell脚本的概念 1.2.shell脚本应用场景 1.3.shell脚本能干什么 1.4. shell的作用--命令翻译器,"翻译官& ...
- Kafka卡夫卡详解
Kafka卡夫卡详解 Kafka设计方式 Topics Producers Consumers 参考:https://www.cnblogs.com/shijiaoyun/p/4860734.html ...
- sshd系统自带启动脚本详解
SSH 为 Secure Shell 的缩写.sshd服务是linux系统中最经常使用的服务之一.由于其规避了明文传送口令.内容本文及中间人***的安全隐患,因此经常作为远程管理系统的首选方案.虽然各 ...
- shell脚本详解(十二)——Here Document免交互及Expect自动化交互
shell脚本详解(十二)--Here Document免交互及Expect自动化交互 一.Here Document 免交互 1.格式 2.注意事项 3.免交互方式实现对行数的统计,将要统计的内容置 ...
- shell脚本详解(十)——sed编辑器的使用方法
shell脚本详解(十)--sed编辑器的使用方法 一.sed编辑器 二.sed编辑器工作流程 1.读取: 2.执行: 3.显示: 4.注: 三.命令格式 四.常用选项 五.常用操作 六.使用地址 s ...
- shell脚本详解(九)——一键部署DNS正向解析
shell脚本详解(九)--一键部署DNS正向解析 一.DNS正向解析 二.shell脚本一键部署 一.DNS正向解析 详情请点击:DNS正向解析 二.shell脚本一键部署 #!/bin/bash ...
最新文章
- tomcat对URL合法字符的判断(RFC 7230 and RFC 3986 异常排查)
- 系统架构师 项目经理 哪个更有前景_中央空调加地暖与五恒系统,哪个更省钱?...
- apache大师+伪静态_Apache开启伪静态示例
- maven覆盖setting_maven-如何为.m2文件夹或settings.xml永久指定替代位置?
- C# 操作World生成报告
- 【机器学习】Pandas读取存在Github上的数据集
- [转] linux 下查看一个进程运行路径的方法
- volte的sip信令流程_VOLTE-SIP代码详解及SIP流程图解
- 《遥感基础导论》知识图——第五章 微波遥感数据
- 学大数据专业未来应该怎么就业?有什么岗位?
- MFC求一元二次方程的根(三种情况:相同根,不同根,虚根)
- 美国贝勒大学计算机科学专业怎么样,美国贝勒大学怎么样
- IO流实现写入规定的acci码值
- JQ局域网通信软件(C/S)
- 李宏毅2020机器学习深度学习 笔记1(理论上持续更新中)
- 称重传感器的构造与测重形式
- python 使用wxpy实现获取微信好友列表 头像 群成员
- 无模型预测控制(model-free predictive control)+ESO
- python灰帽子学习感想
- 微信开发上传多张图片html,微信JSSDK一次性上传多张图片卡死解决方案
热门文章
- 关于ERP系统提前期运算逻辑的三点介绍(转)
- 真正的Netflix文化
- 女人拉屎故事_一个敏锐的女性下午的故事
- 上传身份证--uc手机浏览器拍照覆盖问题
- python实现md5加密和解密_Python中的加密和解密
- 不忘初心,牢记使命——SSM始于Maven,终于Maven(关于Maven的大总结)
- pymysql数据库的水果店销售系统之管理员端1.0
- 基于Vue移动音乐webapp跨域获取QQ音乐歌单接口
- html怎么设置img样式,img 元素可以用 CSS 设置样式吗?
- 整理软件行业职位介绍(PM,RD,FE,UE,UI,QA,OP,DBA,BRD,MRD, PRD,FSD等)、组织结构、职责