Kafka服务端参数配置

1. zookeeper.connect

​ broker要连接zookeeper集群服务地址(包括端口号),没有默认值,此参数为必填项。如果zk集群中有多个节点,则可以用,分开。可以加一个chroot路径这样既可以明确指明该chroot路径下的节点为kafka所用,也可以实现多个kafka集群复用一套zk集群,这样可以节省更多的硬件资源。类似于hadoop:2181/kafka而不是hadoop:2181

# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=hadoop:2181/kafka
复制代码

2. listeners

​ 指明broker监听客户端连接的地址列表,即客户端要连接broker的入口地址列表,配置格式为protocol1://hostname1:port1,protocol2:hostname2:port2,其中protocol代表协议类型,Kfaka支持的协议类型有PLAINTEXT、SSL、SASL_SSL等。如果有多个地址则以,分开,如果不指定主机名,则表示绑定默认网卡,注意有可能会绑定到127.0.0.1,这样无法对外提供服务,所以主机名最好不要为空;如果主机名是0.0.0.0,则表示绑定所有网卡。

​ 与此关联的参数还有advertised.listeners作用和listeners类似,默认值也为null。不过advertised.listeners多用于Iaas环境,比如公有云上的机器通常配置有多块网卡,即私有网卡和公网网卡,对于这种情况而言,可以设置advertised.listeners参数绑定公网IP供外部客户端使用,而listeners参数来绑定私网IP地址供broker间通信使用。

# The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://hadoop:9092

# Hostname and port the broker will advertise to producers and consumers. If not set,
# it uses the value for "listeners" if configured.  Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
#advertised.listeners=PLAINTEXT://your.host.name:9092

复制代码

3. broker.id

​ 该参数用来指定kafka集群中broker的唯一标识,默认值为-1。如果没有设置,那么kafka会自动生成一个。这个参数和meta.properties文件及服务端参数broker.id.generation.enable和reserved.broker.max.id有关。

# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0
复制代码

4. log.dir和log.dirs

kafka把所有消息都保存在磁盘上,而这两个参数用来配置kafka日志文件存放的根目录。一般情况下log.dir用来配置单个根目录,log.dirs用来配置多个根目录,但kafka并没有做强制限制。log.dirs优先级比log.dir高。

# A comma separated list of directories under which to store log files
log.dirs=/opt/module/kafka_2.12-2.3.1/logs/
复制代码

5. message.max.bytes

​ 该参数用来指定broker所能接收消息的最大值,默认值为1000012B,约等于976.6KB。如果大于此值会抛出RecordToolLargeException的异常。如果要修改此参数,那么还要考虑max.request.size(客户端参数)和max.message.bytes(topic端参数)的影响。为了避免修改此参数而引起的级联的影响,建议在修改之前充分考虑拆分消息的可行性。

6. delete.topic.enable

是否真正的删除消息

delete.topic.enable=true
复制代码

7. auto.create.topics.enable

是否允许自动创建消息 默认true