如何为Kafka设置Java选项? [英] How do I set the Java options for Kafka?

查看:267
本文介绍了如何为Kafka设置Java选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用Kafka,并从主站点上的文档中看到,您可以为jvm设置不同的选项,例如堆大小和它使用的垃圾收集器:

I've been experimenting with Kafka and saw from the documentation on the main site that you're able to set different options for the jvm like heap size and the garbage collector that it uses:

http://kafka.apache.org/documentation.html#java

然而,它没有说明如何/在何处设置这些选项。该应用程序附带一个/ config目录,其中包含许多用于配置目的但没有用于Java的文件。它还带有一个/ bin目录,其中包含一堆Kafka脚本,但同样没有真正说明如何配置Java。

What it doesn't say, however, is how/where to set these options. The application comes with a /config directory containing a lot of files used for configuration purposes but none that are for Java. It also comes with a /bin directory containing a bunch of scripts for Kafka but again, nothing really indicating how to configure Java.

所以我的问题是,如何配置Kafka使用的Java选项?它是通过文件完成还是以不同的方式完成?

So my question is, how do I configure the Java options that Kafka uses? Is it done through a file or is there a different way?

推荐答案

我不同意接受的答案。修改 bin 目录中的脚本是非常不推荐的。将Kafka升级到下一版本时,提取新二进制文件将覆盖脚本中所做的更改。

I disagree with the accepted answer. Modifying a script in the bin directory is highly unrecommended. When upgrading Kafka to the next version, extracting the new binaries would override the changes made in the script.

首选方法是在脚本外部设置环境变量 KAFKA_HEAP_OPTS

The preferred way should be to set the environment variable KAFKA_HEAP_OPTS outside the script.

export KAFKA_HEAP_OPTS = - Xmx1G -Xms1G

如果在通过脚本启动Kafka之前设置了var,它将使用var而不是 /bin/kafka-server-start.sh 中定义的默认值

If the var is set before starting Kafka via the script it will use the var instead of the default values defined in /bin/kafka-server-start.sh

这篇关于如何为Kafka设置Java选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆