kafkatool 配置_Kafka 配置调整方法

本文详细介绍了Kafka配置的调整,包括创建和修改topics、停止Kafka、平衡leadership、集群数据镜像、消费者位置检查、集群扩展以及自定义分区分配。还提到了kafka-reassign-partitions.sh工具在数据迁移中的使用,并推荐了kafka-manager和kafkacat两个实用工具。
摘要由CSDN通过智能技术生成

在kafka部署完成后,后面还会遇到配置参数调整一系列的调试,关于配置调整方面,kafka做的确实不太友好,

1 创建topics

kafka-topics.sh --zookeeper zk_host:port/chroot --create --topic my_topic_name --partitions 20 --replication-factor 3 --config x=y

2 修改topics

kafka-topics.sh --zookeeper zk_host:port/chroot --alter --topic my_topic_name --partitions 40

增加配置

kafka-topics.sh --zookeeper zk_host:port/chroot --alter --topic my_topic_name --config x=y

删除配置

kafka-topics.sh --zookeeper zk_host:port/chroot --alter --topic my_topic_name --deleteConfig x

删除topic

kafka-topics.sh --zookeeper zk_host:port/chroot --delete --topic my_topic_name 该功能还是beta在0.8.1中

目前kafka还不支持给topic减少partitions和replication

3 停止kafka

优雅的停止kafka有两个好处:

1 它会sync它的log到磁盘上,避免下次重启时需要修复log

2 它会移动partitions leader服务器之前关闭其他副本

sync log是自动发生的,但是控制leadership的迁移需要设置controlled.shutdown.enable=true

4 平衡leadership

kafka-preferred-replica-election.sh --zookeeper zk_host:port/chroot

设置auto.leader.rebalance.enable=true,让这个平衡过程自动执行

5 在两个kafka集群间mirror数据

6 检查consumer的位置

kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zkconnect localhost:2181 --group test

7 扩展你的集群

加入集群是很容易的,只要分配一个唯一的broker id,然后启动kafka进程即可,但是这样并不会自动的分配数据partitions,除非把partitions移动到新的kafka节点上面,或者新建的topics可能把数据partitions分配在新的kafka节点上面,当你把新节点加入集群的时候,你可能会想移动一些存在的数据到该机器上。但这个过程需要手动完成,有三种模式可选:

--generate: In this mode, given a list of topics and a list of brokers, the tool generates a candidate reassignment to move all partitions of the specified topics to the new brokers. This option merely provides a convenient way to generate a partition reassignment plan given a list of topics and target brokers.

--execute: In this mode, the tool kicks off the reassignment of partitions based on the user provided reassignment plan. (using the --reassignment-json-file option). This can either be a custom reassignment plan hand crafted by the admin or provided by using the --generate option

--verify: In this mode, the tool verifies the status of the reassignment for all partitions listed during the last --execute. The status can be either of successfully completed, failed or in progress

1 编写扩容文件topics-to-move.json

{"topics": [{"topic": "foo1"},

{"topic": "foo2"}],

"version":1

}

2 生成数据迁移配置

kafka-reassign-partitions.sh --zookeeper localhost:2181 --topics-to-move-json-file topics-to-move.json --broker-list "5,6" --generate

3 执行迁移

kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file expand-cluster-reassignment.json --execute

4 查询执行的状态

kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file expand-cluster-reassignment.json --verify

8  自定义分区的分配和迁移

topic foo1 partition0 -->brokers 5 6

topic foo2 partition1 -->brokers 2 3

1 设置配置文件custom-reassignment.json

{"version":1,"partitions":[{"topic":"foo1","partition":0,"replicas":[5,6]},{"topic":"foo2","partition":1,"replicas":[2,3]}]}

2 开始迁移

kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file custom-reassignment.json --execute

3 检查

kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file custom-reassignment.json --verify

下面介绍两个好工具:

kafka-manage

https://github.com/yahoo/kafka-manager

kafkacat

https://github.com/edenhill/kafkacat

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值