kafka 提供了 kafka-configs.sh 脚本用于对配置进行管理操作,支持修改配置(--alter)和查看(--describe)两个基本操作。

--alter 和 --add-config 指令组合可以实现增加或者修改配置;

--alter 和 --delete-config 指令组合可以实现删除配置;

应用该脚本管理配置需要指定操作配置类型(entity-type)和 类型名称(entity-name),该脚本支持的配置类型有 topics、clients、users 和 brokers;

执行该脚本的--alter操作会在zookeeper创建相应的节点:

  1):将配置写入到 /config/<entity-type>/<entity-name>节点中;

  2):在/config/changes/ 节点下创建以 config_change_ 为前缀,之后连接按序递增的10位数字字符串作为节点名的节点。

 

1、主题级别配置

  查看主题配置:kafka-configs.sh --zookeeper localhost:2181 --describe --entity-type topics --entity-name kafka-action 

  增加/修改主题配置: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>

 

2、代理级别设置

  代理级别主要设置以下两个配置参数:

    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

 

3、客户端/用户级别设置

  1、为用户添加流控

    给用户 admin 配置生产者和消费者流量控制

      kafka-configs.sh --zookeeper localhost:2181 --entity-type users --entity-name admin --alter --add-config producer_byte_rate=1024,consumer_byte_rate=1024

  2、给客户端添加流控

    给一个 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

  3、为特定用户的客户端添加流控

    对客户端添加流控时,若没有指定用户则表示该配置对所有的用户起作用。当然也可以为某个用户的客户端添加流控,如为用户 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

 

posted on 2019-06-28 15:00  布咚嘞  阅读(245)  评论(0编辑  收藏  举报