kafka 提供了 kafka-configs.sh 脚本用于对配置进行管理操做,支持修改配置(--alter)和查看(--describe)两个基本操做。代理
--alter 和 --add-config 指令组合能够实现增长或者修改配置;server
--alter 和 --delete-config 指令组合能够实现删除配置;字符串
应用该脚本管理配置须要指定操做配置类型(entity-type)和 类型名称(entity-name),该脚本支持的配置类型有 topics、clients、users 和 brokers;kafka
执行该脚本的--alter操做会在zookeeper建立相应的节点:it
1):将配置写入到 /config/<entity-type>/<entity-name>节点中;io
2):在/config/changes/ 节点下建立以 config_change_ 为前缀,以后链接按序递增的10位数字字符串做为节点名的节点。test
一、主题级别配置cli
查看主题配置:kafka-configs.sh --zookeeper localhost:2181 --describe --entity-type topics --entity-name kafka-action zookeeper
增长/修改主题配置:kafka-configs.sh --zookeeper localhost:2181--entity-type topics --entity-name kafka-action --describe --add-config <name1>=<value1>,<name2>=<value2>配置
删除主题配置:kafka-configs.sh --zookeeper localhost:2181 --entity-type topics --entity-name kafka-action --describe --delete-config <name1>,<name2>
二、代理级别设置
代理级别主要设置如下两个配置参数:
follower.replication.throttled.rate 设置Follower 复制的速率,单位为B/s
leader.replication.throttled.rate 设置Leader 节点传输速率,单位为B/s
设置对 server-1 对应的代理(broker.=1)上分布的Leader副本和Follower副本的复制速率控制为10MB/s
kafka-configs.sh --zookeeper server-1:2181 --entity-type brokers --entity-name 1 --alter --add-config follower.replication.throttled.rate=10485760,leader.replication.throttled.rate=10485760
三、客户端/用户级别设置
一、为用户添加流控
给用户 admin 配置生产者和消费者流量控制
kafka-configs.sh --zookeeper localhost:2181 --entity-type users --entity-name admin --alter --add-config producer_byte_rate=1024,consumer_byte_rate=1024
二、给客户端添加流控
给一个 client.id=test-client 的客户端添加流量控制
kafka-configs.sh --zookeepre localhost:2181 --entity-type clients --entity-name test-client --alter --add-config producer_byte_rate=1024,consumer_byte_rate=1024
三、为特定用户的客户端添加流控
对客户端添加流控时,若没有指定用户则表示该配置对全部的用户起做用。固然也能够为某个用户的客户端添加流控,如为用户 adming 名为 test-client 的客户端设置流控:
kafka-configs.sh --zookeeper localhost:2181 --entity-type users --entity-name admin --entity-type clients --entity-name test-client --alter --add-config producer_byte_rate=1024,consumer.byte_rate=1024