0
点赞
收藏
分享

微信扫一扫

kafka---broker相关配置

敬亭阁主 2024-04-15 阅读 20

一、Broker 相关配置

1、一般配置

broker.id

reserved.broker.max.id

broker.id.generation.enable

注意 1000以上的Broker ID现在默认保留为自动分配的Broker ID。如果集群的现有broker id高于该阈值,请确保相应地增加reserved.broker.max.id broker配置属性。

advertised.listeners

2、 日志数据相关配置

log.dir

log.dirs

log.flush.interval.messages

在一个日志分区( log partition)上需要达到多少个消息,才会将这些消息持久化(刷新)到磁盘上

log.flush.interval.ms

topic中的消息存放在内存中的最大时间,超过这个时间就会被刷新到磁盘上,如果未设置,就使用
log.flush.scheduler.interval.ms

log.flush.scheduler.interval.ms

log flusher检查日志是否需要刷新到磁盘的频率

3、ZK相关配置

zookeeper.connect

zookeeper.connection.timeout.ms

kafka连接zk的超时时长,如果未设置,将会使用zookeeper.session.timeout.ms值

zookeeper.session.timeout.ms

kafka连接zk的一个session的超时时间

二、如何更新broker相关配置

broker的配置有三种更新模式:read-only、per-broker、cluster-wide;

  • read-only:需要重启才能生效
  • per-broker: 可以针对每一个broker动态更新
  • cluster-wide:在集群范围内更新,或者针对每一个broker更新(只为了测试)

对于read-only模式配置,只能通过修改config/server.properties配置文件然后重启生效;
对于 per-broker模式的,可以使用命令行进行修改

## 修改
bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type brokers --entity-name 0 --alter --add-config log.cleaner.threads=2
## 查询
bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type brokers --entity-name 0 --describe
##删除
bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type brokers --entity-name 0 --alter --delete-config log.cleaner.threads

对于这些被修改的per-broker模式的配置,会被存储在zk 的==/config/brokers/id==中;
对于 cluster-wide模式的,可以使用命令行进行修改

## 新增
bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type brokers --entity-default --alter --add-config log.cleaner.threads=2
## 查询
bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type brokers --entity-default --describe

对于这些被修改的cluster-wide模式的配置,会被存储在zk 的==/config/brokers/<default>==中;

注意 在(cluster-wide)集群级别可配置的所有配置也可以在(per-broker)级别进行配置,如果在不同级别定义配置值,则使用以下优先顺序:

  • Dynamic per-broker config stored in ZooKeeper(存储在zk中的 per-broker配置)
  • Dynamic cluster-wide default config stored in ZooKeeper(存储在zk中的 cluster-wide配置)
  • Static broker config from server.properties
    对于一个新启动的kafka,在zk中是没有per-broker和 cluster-wide 动态配置存储的,所以这个时候是以配置文件为主,当对某些动态配置进行配置之后,对应的ZK node中就会有相应数据了,使用顺序如上。

三、kafka-configs.sh 命令详解

kafka-configs.sh 命令必须包含 --alter 或者 --describe 其中一个
kafka-configs.sh --help
kafka-configs.sh --version
–bootstrap-server <lStrng ocalhost:9092> 指定kafka的地址;
–entity-type <String> 指定要修改的实体类型,topics、clients、users、brokers、broker-loggers、ips;
–entity-name String 指定上述实体类型的名;
–entity-default 在上述类型中的cluster-wide范围内更新配置
–alter 修改相应配置
–add-config ’k1=v1‘ 修改或者更新相应配置 log.cleaner.threads=2,多个值,需要用引号引住,并用逗号分隔开,即’k1=v1,k2=v2,k3=[v1,v2,v3]‘
–describe 列出相应配置
–all 列出所有配置
–delete-config String 删除相应配置
–broker id 指定要配置的brokerid
–broker-defaults 更新所有的broker,即cluster-wide模式

举报

相关推荐

0 条评论