配置管理

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

相關文章
相關標籤/搜索