博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Kafka 配置调整方法
阅读量:7114 次
发布时间:2019-06-28

本文共 3218 字,大约阅读时间需要 10 分钟。

  hot3.png

在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
 
 

转载于:https://my.oschina.net/guol/blog/413677

你可能感兴趣的文章
symbian s60权限详解
查看>>
一 APPIUM基本理论知识(转)
查看>>
String、StringBuffer和StringBulder
查看>>
mysql 数据类型,字符集
查看>>
电力系统【第1章:电力系统概述】
查看>>
web环境搭建
查看>>
Codeigniter出现Unable to connect to your database server using the provided settings错误解决办法...
查看>>
html相对定位绝对定位
查看>>
YII 框架在 MAC OS下 连接数据库失败 提示 DB connection: SQLSTATE[HY000] [2002]
查看>>
poj 2551 Ones
查看>>
HDU 4433 locker
查看>>
PHP----------php-fpm进程数的一些相关配置
查看>>
初始Spring
查看>>
装箱与拆箱
查看>>
设计模式概要
查看>>
053(七)
查看>>
django admin 登陆快速添加验证码功能
查看>>
JS生成二维码
查看>>
免考申请
查看>>
接口和抽象类
查看>>