【Kafka】-Kafka服务端脚本详解(1)-topics

本文涉及的产品
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
简介: Kafka服务端脚本详解(1)-topics

WX20220610-163115@2x.png

脚本名称 脚本用途
kafka-topics.sh topic管理脚本
connect-distributed.sh 连接分布式模式脚本
connect-standalone.sh 连接单机模式脚本

kafka-topics.sh

--partitions

创建或修改主题的分区数

--replication-factor

副本因子,副本数量

--replica-assignment

手动指定分区副本分配方案,使用该参数,不用指定--partitions 和 --replication-factor

--topic

主题名称

--zookeeper

连接kafka zk地址

--alter

修改分区,副本,配置

--bootstrap-server

kafka服务器地址

--create

创建主题

--delete

删除主题

--list

列出所有的可用主题

1[root@10 kafka_2]# bin/kafka-topics.sh --zookeeper 10.211.55.3:2181 --list
 2__consumer_offsets
 3first
 4test
 5topic-3
 6topic-4
 7topic-5
 8topic-6
 9topic-admin
10topic-create-diff
11topic-two
--describe

列出主题的详细信息

--exclude-internal

使用--list --describe 命令时是否列出内部主题,默认列出内部主题

--command-config

以配置文件的形式修改Admin Client的配置,支持的配置见org.apache.kafka.clients.admin.AdminClientConfig

1//me.properties
2request.timeout.ms=200000
3
4//
5bin/kafka-topics.sh --bootstrap-server  10.211.55.3:9092 --topic topic-two --list  --command-config config/me.properties
--config

在创建/修改主题的时候可以对主题默认参数进行覆盖,具体支持的参数见http://kafka.apachecn.org/documentation.html#topicconfigs

该参数将在以后废弃,请使用kafka-configs.sh

1[root@10 kafka_2.11-2.2.0]# bin/kafka-topics.sh --bootstrap-server  10.211.55.3:9092 --topic topic-two --describe
 2Topic:topic-two PartitionCount:1        ReplicationFactor:1     Configs:segment.bytes=1073741824,retention.bytes=1073741824
 3Topic: topic-two        Partition: 0    Leader: 0       Replicas: 0     Isr: 0
 4
 5[root@10 kafka_2.11-2.2.0]# bin/kafka-topics.sh --zookeeper  10.211.55.3:2181 --alter --topic topic-two --config segment.bytes=1048577
 6WARNING: Altering topic configuration from this script has been deprecated and may be removed in future releases.
 7         Going forward, please use kafka-configs.sh for this functionality
 8Updated config for topic topic-two.
 9
10[root@10 kafka_2.11-2.2.0]# bin/kafka-topics.sh --zookeeper  10.211.55.3:2181 --describe --topic topic-two
11Topic:topic-two PartitionCount:1        ReplicationFactor:1     Configs:segment.bytes=1048577
12Topic: topic-two        Partition: 0    Leader: 0       Replicas: 0     Isr: 0
----delete-config

删除一个配置项

1[root@10 kafka_2.11-2.2.0]# bin/kafka-topics.sh --zookeeper 10.211.55.3:2181 --topic topic-two --alter --delete-config segment.bytes 
2WARNING: Altering topic configuration from this script has been deprecated and may be removed in future releases.
3         Going forward, please use kafka-configs.sh for this functionality
4Updated config for topic topic-two.
5
6[root@10 kafka_2.11-2.2.0]# bin/kafka-topics.sh --zookeeper 10.211.55.3:2181 --topic topic-two --describe
7Topic:topic-two PartitionCount:1        ReplicationFactor:1     Configs:
8        Topic: topic-two        Partition: 0    Leader: 0       Replicas: 0     Isr: 0
--disable-rack-aware

忽略机架信息

有两个broker,一个配了机架信息,另一个没配,在创建topic的时候就会报错

1[root@10 kafka_2.11-2.2.0]# bin/kafka-topics.sh --zookeeper 10.211.55.3:2181 --create --topic topic-6 --replication-factor 1  --partitions 2
 2Error while executing topic command : Not all brokers have rack information. Add --disable-rack-aware in command line to make replica assignment without rack information.
 3[2018-12-27 05:22:40,834] ERROR kafka.admin.AdminOperationException: Not all brokers have rack information. Add --disable-rack-aware in command line to make replica assignment without rack information.
 4        at kafka.zk.AdminZkClient.getBrokerMetadatas(AdminZkClient.scala:71)
 5        at kafka.zk.AdminZkClient.createTopic(AdminZkClient.scala:54)
 6        at kafka.admin.TopicCommand$ZookeeperTopicService.createTopic(TopicCommand.scala:274)
 7        at kafka.admin.TopicCommand$TopicService$class.createTopic(TopicCommand.scala:134)
 8        at kafka.admin.TopicCommand$ZookeeperTopicService.createTopic(TopicCommand.scala:266)
 9        at kafka.admin.TopicCommand$.main(TopicCommand.scala:60)
10        at kafka.admin.TopicCommand.main(TopicCommand.scala)
11 (kafka.admin.TopicCommand$)
12
13[root@10 kafka_2.11-2.2.0]# bin/kafka-topics.sh --zookeeper 10.211.55.3:2181 --create --topic topic-6 --replication-factor 1  --partitions 2 --disable-rack-aware
14Created topic topic-6.
--if-exists

只有当主题存在时,相关命令才会执行,不会显示错误

1[root@10 kafka_2]# bin/kafka-topics.sh --zookeeper 10.211.55.3:2181 --topic topic-7  --alter --config segment.bytes=104857 --if-exists
 2
 3[root@10 kafka_2]# bin/kafka-topics.sh --zookeeper 10.211.55.3:2181 --topic topic-7  --alter --config segment.bytes=104857
 4Error while executing topic command : Topics in [] does not exist
 5[2018-12-27 06:01:25,638] ERROR java.lang.IllegalArgumentException: Topics in [] does not exist
 6        at kafka.admin.TopicCommand$.kafka$admin$TopicCommand$$ensureTopicExists(TopicCommand.scala:416)
 7        at kafka.admin.TopicCommand$ZookeeperTopicService.alterTopic(TopicCommand.scala:294)
 8        at kafka.admin.TopicCommand$.main(TopicCommand.scala:62)
 9        at kafka.admin.TopicCommand.main(TopicCommand.scala)
10 (kafka.admin.TopicCommand$)
--if-not-exists

创建主题的时候,只有当主题不存在时,命令才执行,存在时不会报错

1[root@10 kafka_2]# bin/kafka-topics.sh --zookeeper 10.211.55.3:2181 --topic topic-6  --create --partitions 1 --replication-factor 1 --if-not-exists
2
3[root@10 kafka_2]# bin/kafka-topics.sh --zookeeper 10.211.55.3:2181 --topic topic-6  --create --partitions 1 --replication-factor 1 
4Error while executing topic command : Topic 'topic-6' already exists.
5[2018-12-27 06:07:54,185] ERROR org.apache.kafka.common.errors.TopicExistsException: Topic 'topic-6' already exists.
6 (kafka.admin.TopicCommand$)
--topics-with-overrides

显示覆盖过配置的主题

--unavailable-partitions

查看没有leader副本的分区

1[root@10 kafka_2]# bin/kafka-topics.sh --zookeeper 10.211.55.3:2181 --topic topic-6  --describe --unavailable-partitions
2        Topic: topic-6  Partition: 0    Leader: -1      Replicas: 1     Isr: 1
--under-replicated-partitions

查看所有包含失效副本的分区


connect-distributed.sh & connect-standalone.sh

Kafka Connect 是一款可扩展并且可靠的在 Apache Kafka 和其他系统之间进行数据传输的工具。

1bin/connect-standalone.sh config/connect-standalone.properties  config/connect-file-source.properties
2
3bin/connect-distributed.sh config/connect-distributed.properties

参考:

[1] Kafka之实战指南-朱小厮

[2] 阿飞的博客

[3] Apache Kafka

相关文章
|
2月前
|
消息中间件 Java Kafka
【Kafka】Kafka-Server-start.sh 启动脚本分析(Ver 2.7.2)
【Kafka】Kafka-Server-start.sh 启动脚本分析(Ver 2.7.2)
33 0
|
4月前
|
消息中间件 Java Shell
Linux【脚本 03】shell脚本离线安装配置集结JDK+InfluxDB+Zookeeper+Kafka(安装文件及脚本源码网盘分享)
Linux【脚本 03】shell脚本离线安装配置集结JDK+InfluxDB+Zookeeper+Kafka(安装文件及脚本源码网盘分享)
28 0
|
4月前
|
消息中间件 Kafka Shell
Linux【脚本 02】shell脚本离线安装配置Zookeeper及Kafka并添加service服务和开机启动(脚本分析)
Linux【脚本 02】shell脚本离线安装配置Zookeeper及Kafka并添加service服务和开机启动(脚本分析)
47 0
|
消息中间件 XML 存储
【夯实Kafka实战性能调优技能】消息队列服务端出现内存溢出OOM以及相关性能调优实战分析
【夯实Kafka实战性能调优技能】消息队列服务端出现内存溢出OOM以及相关性能调优实战分析
551 0
|
消息中间件 Java Kafka
Kafka技术专题之「问题分析篇」消息队列服务端出现内存溢出OOM以及相关实战分析系列
Kafka技术专题之「问题分析篇」消息队列服务端出现内存溢出OOM以及相关实战分析系列
333 0
|
消息中间件 运维 Java
【kafka运维】Leader重新选举运维脚本
【kafka运维】Leader重新选举运维脚本
|
消息中间件 缓存 Kafka
Kafka流程流转-服务端
kafka分为客户端和服务端,通常我们知道broker是服务端,而生产者和消费者作为客户端。因此在服务端就必定需要解决并发和网络IO的问题。因此不可避免需要用到SocketChannel和ServerSocketChannel,可以看到kafka就使用了ServerSocketChannel,采用Netty来解决这个问题,这里socketServer采用了1个Acceptor,多个Processor。同时将请求发送到请求通道RequestChannel中。而我们知道RequestChannel中有一个请求队列和多个响应队列,通常响应队列是3个,这个参数是在kafka的配置中配置的。通过kafk
103 0
Kafka流程流转-服务端
|
消息中间件 监控 Kafka
发送kafka消息的shell脚本
开发和学习时需要造一些kafka消息,于是写了段脚本实现,在这里记录备忘,后面会常用到
356 0
发送kafka消息的shell脚本
|
消息中间件 运维 网络协议
【kafka运维】Topic的生产和消费运维脚本
1.Topic的发送kafka-console-producer.sh 1.1 生产无key消息 ## 生产者 bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test --producer.config config/producer.properties 1.2 生产有key消息加上属性--property parse.key=true
|
消息中间件 运维 监控
【kafka运维】ConfigCommand运维脚本
ConfigCommand Config相关操作; 动态配置可以覆盖默认的静态配置; 1 查询配置 Topic配置查询 展示关于Topic的动静态配置 1.1.查询单个Topic配置(只列举动态配置)
【kafka运维】ConfigCommand运维脚本

热门文章

最新文章