0%

kafka配置

配置管理

kafka-configs脚本管理配置,支持修改(alter)和查看(describe)配置两个基本操作

对于配置类型entity-type包含topics、clients、users、brokers

  • topics 指定主题名称
  • clients 指定客户端id
  • users 设置了用户权限控制的用户名
  • brokers 对应kafka代理的broke.id值

对于这些配置存储在zookeeper中,写在zookeeper的 /config//节点中,由于配置存储在zookeeper中,所以zookeeper参数是必传的

  • 若是修改类型的操作(alter)

    • 将相应配置写入/config//节点中,在zookeeper中使用get /config// 命令查看

    • 在/config/changes/节点下创建一个以config_change_为前缀,之后连接按序递增的10位数字 通过get /config/changes/config_change_seqNo命令查看该节点信息

  • 若是查看类型操作(describe),则从/config//节点的元数据信息中获取config对应的配置

脚本

1
exec $(dirname $0)/kafka-run-class.sh kafka.admin.ConfigCommand "$@"

配置命令

主题级别配置

1
2
3
4
5
6
7
8
9
#查看主题配置
>kafka-configs --zookeeper localhost:2181 --describe --entity-type topics --entity-name kafka-test
Configs for topic 'kafka-test' are max.message.bytes=204800

#修改/添加主题配置 如果多个配置使用逗号隔开
>kafka-configs --zookeeper localhost:2181 --entity-type topics --entity-name kafka-test --alter --add-config max.message.bytes=102400

#删除主题配置 多个配置用逗号隔开
>kafka-configs --zookeeper localhost:2181 --entity-type topics --entity-name kafka-test --alter --delete-config max.message.bytes

代理级别配置

提供了对于副本传输流量控制的配置,在分区迁移时很有用,通过对复制流量合理的控制,可以实现数据间的平滑迁移。

  • follower.replication.throttled.rate 设置Follower复制的速率,单位B/s

  • leader.replication.throttled.rate 设置Leader节点传输速率,单位B/s

1
2
#修改/新增配置
>kafka-configs --zookeeper localhost:2181 --entity-type brokers --entity-name 0 --alter --add-config follower.replication.throttled.rate=10485760,leader.replication.throttled.rate=10485760

客户端/用户级别配置

仅支持配置生产者每秒最多写入消息的字符数(producer_byte_rate)以及消费者每秒拉取消息的字节数(consumer_byte_rate),称为流控设置

为用户添加流控
1
2
3
4
5
#为用户mm配置生产者和消费者流量控制  在zookeeper的/config/users路径下创建mm节点,并将相应的限流信息存储到该节点中
kafka-configs --zookeeper localhost:2181 --alter --add-config 'producer_byte_rate=1024,consumer_byte_rate=2048' --entity-type users --entity-name mm

# 查看用户的流控信息
kafka-configs --zookeeper localhost:2181 --describe --entity-type users
为客户端添加流控
1
2
3
4
5
#为客户端acl配置生产者和消费者流量控制  在zookeeper的/config/clients路径下创建节点,并将相应的限流信息存储到该节点中
kafka-configs --zookeeper localhost:2181 --alter --add-config 'producer_byte_rate=1024,consumer_byte_rate=2048' --entity-type clients --entity-name acl

# 查看客户端的流控信息
kafka-configs --zookeeper localhost:2181 --describe --entity-type clients
为特定用户的客户端添加流控
1
2
#同时指定用户和客户端
kafka-configs --zookeeper localhost:2181 --alter --add-config 'producer_byte_rate=1024,consumer_byte_rate=2048' --entity-type users --entity-name mm --entity-type clients --entity-name acl

欢迎关注我的其它发布渠道