如何在 Windows 上安装 Kafka?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23115013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:31:03  来源:igfitidea点击:

How to install Kafka on Windows?

windowsapache-kafkaapache-zookeeper

提问by Yves M.

I'm trying to install Kafkamessage queue on Windows for testingpurposes (not for production).

我正在尝试在 Windows 上安装Kafka消息队列以进行测试(不是用于生产)。

I found this article on how to install Apache Kafka 0.8 on Windows: http://janschulte.wordpress.com/2013/10/13/apache-kafka-0-8-on-windows/

我发现这篇关于如何在 Windows 上安装 Apache Kafka 0.8 的文章:http: //janschulte.wordpress.com/2013/10/13/apache-kafka-0-8-on-windows/

It's a good article, but it's outdated, unfortunately.

这是一篇好文章,但不幸的是,它已经过时了。

Does someone know a way to achieve that?

有人知道实现这一目标的方法吗?

采纳答案by Yves M.

Ok, it's finally not complicated :)

好了,终于不复杂了:)

The only steps are:

唯一的步骤是:

  1. Download Kafkaand uncompress it somewhere nice (let's say C:/Kafka)
  2. Install Cygwin
  3. Edit \bin\kafka-run-class.shand at the end of the file, change

    exec $JAVA $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@"

    to

    exec java $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp `cygpath -wp $CLASSPATH` $KAFKA_OPTS "$@"

  4. In Environment Variables, Add java to your PathSystem Variable:

    enter image description here

  1. 下载Kafka并将其解压缩到合适的地方(比方说C:/Kafka
  2. 安装Cygwin
  3. 编辑\bin\kafka-run-class.sh并在文件末尾更改

    exec $JAVA $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@"

    exec java $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp `cygpath -wp $CLASSPATH` $KAFKA_OPTS "$@"

  4. Environment Variables 中,将 java 添加到您的路径系统变量:

    在此处输入图片说明

That's it.. you can now run ZooKeeper and Kafka servers and start playing with topics and stuff..

就是这样......你现在可以运行 ZooKeeper 和 Kafka 服务器并开始玩主题和东西......

回答by noelyahan

These are the steps I followed to run kafka on Windows

这些是我在 Windows 上运行 kafka 所遵循的步骤

  1. Install Zookeeper first (I downloadedv3.3.6) zookeeper-3.3.6.tar.gz
  2. Extract Zookeeper and run this command in powershell/cmd \zookeeper-3.3.6\bin> .\zkServer.cmdNow this should up a Zookeeper instance on localhost:2181
  3. Download Kafka binary version (I downloadedv0.10.0.1)kafka_2.10-0.10.0.1.tgz
  4. Extract Kafka, time to modify some configs
  5. Inside Kafka extraction you can find .\config\server.properties
  6. In .\config\server.propertiesreplace log.dirs=c:/kafka/kafka-logs
  7. Note: Make sure to create those folders in relevant paths
  8. Happy news: Now Kafka ships with windows .bat scripts, You can find these files inside ./bin/windowsfolder
  9. Start powershell/cmd and run this command to start Kafka broker .\bin\windows\kafka-server-start.bat .\config\server.properties
  10. DONE!, Now you have a running Zookeeper instance and a Kafka broker.
  1. 先安装Zookeeper(我下载的是v3.3.6)zookeeper-3.3.6.tar.gz
  2. 提取 Zookeeper 并在 powershell/cmd 中运行此命令\zookeeper-3.3.6\bin> .\zkServer.cmd现在这应该启动一个 Zookeeper 实例localhost:2181
  3. 下载Kafka二进制版本(我下载的是v0.10.0.1)kafka_2.10-0.10.0.1.tgz
  4. 提取Kafka,是时候修改一些配置了
  5. 在 Kafka 提取中,您可以找到 .\config\server.properties
  6. .\config\server.properties替换log.dirs=c:/kafka/kafka-logs
  7. 注意:确保在相关路径中创建这些文件夹
  8. 好消息:现在 Kafka 附带了 windows .bat 脚本,您可以在./bin/windows文件夹中找到这些文件
  9. 启动 powershell/cmd 并运行此命令以启动 Kafka broker .\bin\windows\kafka-server-start.bat .\config\server.properties
  10. 完成!,现在您有一个正在运行的 Zookeeper 实例和一个 Kafka 代理。

回答by Joseph Blair

A more current answer for the benefit of anyone else still wondering about this, I downloaded the binary and everything worked right out of the box. The source version, however, didn't work.

为了让其他人仍然对此感到疑惑,我下载了二进制文件,一切都开箱即用。但是,源版本不起作用。

回答by Anilot

You will probably find that Kafka comes with Windows .bat files under the binfolder to help you run Kafka under windows. However, those bat files are not updated since version 0.8.0 and some of Kafka's logic has changed (regarding topics, etc.).

你可能会发现Kafka自带bin文件夹下的Windows .bat文件,可以帮助你在windows下运行Kafka。但是,这些 bat 文件自 0.8.0 版本以来没有更新,并且 Kafka 的一些逻辑发生了变化(关于主题等)。

I have tried two ways to solve this problem. One is to use Cygwin or MinGW to simulate Linux environment and run the Linux shell script, but there would be tons of other problems related to path names. The other solution, which is simpler and come with less trouble, is to use the corrected version of Windows bat files.

我尝试了两种方法来解决这个问题。一种是使用Cygwin或MinGW来模拟Linux环境并运行Linux shell脚本,但是与路径名相关的其他问题会很多。另一种更简单且麻烦更少的解决方案是使用 Windows bat 文件的更正版本。

Please refer to this blog post.

请参考这篇博文

回答by Do?an Etkin

  1. Download any binaryversion(I've downloaded kafka_2.11-0.10.2.0) of Kafka from https://kafka.apache.org/downloads
  2. Extract it to any folder(I've extracted to "C:\Kafka")
  3. Open Command Prompt
  4. Go to the folder that you extract Kafka(C:\Kafka\kafka_2.11-0.10.2.0)
  5. Run this command .\bin\windows\zookeeper-server-start.bat .\config\zookeeper.propertiesto start Zookeeper
  6. Run this command .\bin\windows\kafka-server-start.bat .\config\server.propertiesto start Kafka
  1. https://kafka.apache.org/downloads下载 Kafka 的任何二进制版本(我已经下载了 kafka_2.11-0.10.2.0)
  2. 将其解压缩到任何文件夹(我已解压缩到“C:\Kafka”)
  3. 打开命令提示符
  4. 转到您提取 Kafka 的文件夹(C:\Kafka\kafka_2.11-0.10.2.0)
  5. 运行这个命令.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties来启动 Zookeeper
  6. 运行这个命令.\bin\windows\kafka-server-start.bat .\config\server.properties来启动 Kafka


Now it works!


现在它起作用了!

回答by hatmaca

In version 0.9.0. there are scripts in "bin" folder for windows. You can use them.

在 0.9.0 版本中。Windows的“bin”文件夹中有脚本。你可以使用它们。

回答by Gonen I

Running From A windows Shell

从 Windows Shell 运行

As of April 2019, downloading Kafka from their website worked on Windows almost right out of the box

截至 2019 年 4 月,从他们的网站下载 Kafka 几乎可以立即在 Windows 上运行

Downloading and using the windows version .bat files is described here: https://kafka.apache.org/quickstart

此处描述了下载和使用 Windows 版本 .bat 文件:https: //kafka.apache.org/quickstart

I ran into two problems when I did this:

当我这样做时,我遇到了两个问题:

1) JAVA_HOME was set to an unsupported JDK which led to this kind of error

1) JAVA_HOME 设置为不受支持的 JDK 导致此类错误

Exception in thread "main" java.lang.VerifyError: Uninitialized object exists on backward branch 209

线程“main”中的异常 java.lang.VerifyError:反向分支 209 上存在未初始化的对象

Replacing with JDK 11 solved the problem.

替换为 JDK 11 解决了这个问题。

2) The JAVA_HOME must not contain spaces which caused a 'cannot find the specified file' error. To fix this I used a shortened path like set JAVA_HOME=C:\Progra~1\Java\jdk-11.0.1

2) JAVA_HOME 不能包含导致“找不到指定文件”错误的空格。为了解决这个问题,我使用了一条缩短的路径,例如set JAVA_HOME=C:\Progra~1\Java\jdk-11.0.1



Running From Cygwin

从 Cygwin 运行

If instead of the .bat files, you want to run the .sh files from cygwin, there is actually quite a bit that needs to be done, and even after that there may be problems that come up later. I can't really recommend this option, but I do use it as it's pretty convenient for some purposes.

如果您想从cygwin运行 .sh 文件而不是 .bat 文件,则实际上需要完成很多工作,即使在此之后也可能会出现问题。我真的不能推荐这个选项,但我确实使用它,因为它对于某些目的非常方便。

If your JAVA_HOME path contains a space e.g. "C:\Program Files\Java\Jdk..." you will see something like this:

如果您的 JAVA_HOME 路径包含一个空格,例如“C:\Program Files\Java\Jdk...”,您将看到如下内容:

bin/kafka-run-class.sh: line 305: exec: C:\Program: not found

bin/kafka-run-class.sh: line 305: exec: C:\Program: not found

One solution is to copy the jdk to a path without spaces, and change the Java home accordingly.

一种解决方案是将jdk复制到一个没有空格的路径,并相应地更改Java home。

If you don't want to change the JDK location, you can change the cygwin env variable as follows:

如果不想更改 JDK 位置,可以按如下方式更改 cygwin 环境变量:

JAVA_HOME="/cygdrive/c/Program Files/Java/jdk-11.0.1"

and change the line

并改变线

exec $JAVA $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@"

to

exec "$JAVA" $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@"

There was another problem with the log parameters in kafka-run-class.sh and I had to replace the line

kafka-run-class.sh 中的日志参数还有一个问题,我不得不替换该行

KAFKA_GC_LOG_OPTS="-Xlog:gc*:file=$LOG_DIR/$GC_LOG_FILE_NAME:time,tags:filecount=10,filesize=102400"

with

KAFKA_GC_LOG_OPTS="-Xlog:gc*"

And even after all these changes I occasionally run into problems of Kafka shutting down because of an incompatible windows style path in the logs directories as described here: Kafka 1.0 stops with FATAL SHUTDOWN error. Logs directory failedIn short, you may be better off running the Kafka .bat scripts from the windows directory...

即使在所有这些更改之后,由于日志目录中的 Windows 样式路径不兼容,我偶尔也会遇到 Kafka 关闭的问题,如下所述: Kafka 1.0 因 FATAL SHUTDOWN 错误而停止。日志目录失败简而言之,您最好从 windows 目录运行 Kafka .bat 脚本...

回答by Karthik P

Refer the official documentation,

参考官方文档,

https://kafka.apache.org/quickstart

https://kafka.apache.org/quickstart

On Windows platforms use bin\windows\instead of bin/, and change the script extension to .bat.

在 Windows 平台上使用bin\windows\代替bin/,并将脚本扩展名更改为.bat.

回答by Ravi K

Kafka & Zookeeper have inbuilt Windows specific scripts as verified in the latest version. As mentioned in other other answers, the directory for windows scripts will be under kafka_2.12-2.4.0\bin\windowsfor Kafka. Zookeeper scripts are under /bin only but ending with "*.cmd"

Kafka 和 Zookeeper 内置了 Windows 特定的脚本,这些脚本已在最新版本中得到验证。正如其他其他答案中所述,Windows 脚本的目录将位于kafka_2.12-2.4.0\bin\windowsKafka 下。Zookeeper 脚本仅在 /bin 下,但以“*.cmd”结尾

There will be few minor additional steps you will have to do with ZooKeeper & Kafka like

您将需要使用 ZooKeeper 和 Kafka 执行一些小的额外步骤,例如

  • Creating zoo.cfg for ZooKeeper
  • Configuring windows specific data directory for ZeeKeeper
  • Kafka comes with default configuration file & it has very good OS specific handling i.e. log.dirs=/tmp/kafka-logsbut it will create that directory structure under C:/directory seamlessly without failing.
  • 为 ZooKeeper 创建 zoo.cfg
  • 为 ZeeKeeper 配置 Windows 特定的数据目录
  • Kafka 带有默认配置文件,它具有非常好的操作系统特定处理能力,即log.dirs=/tmp/kafka-logs它会在目录下C:/无缝创建该目录结构而不会失败。

It is also easy to quickly setup a Kafka Cluster with multiple Kafka Brokers on Windows with minor configurations. You can also create topics, publish/consume messages, verify topics/partitions etc. all from Windows Command Prompt. Here is a good detailed reference for the windows specific setup Kafka Setup on Windows OS | Basic Installation, Setup, Verification, Cluster Setup, Storage

在 Windows 上通过少量配置快速设置具有多个 Kafka Broker 的 Kafka 集群也很容易。您还可以从 Windows 命令提示符创建主题、发布/使用消息、验证主题/分区等。这是Windows 操作系统上 Windows特定设置Kafka Setup 的一个很好的详细参考| 基本安装、设置、验证、集群设置、存储

回答by hansaplast

With Chocolatey and Powershell:

使用 Chocolatey 和 Powershell:

  1. chocolatey.exe install kafka-> installs Kafka into C:\ProgramData\chocolatey\lib\kafka\tools\kafka_2.11-1.0.0\- your version might differ of course
  2. add C:\ProgramData\chocolatey\lib\kafka\tools\kafka_2.11-1.0.0\to your powershell path using notepad $PROFILE
  1. chocolatey.exe install kafka-> 将 Kafka 安装到C:\ProgramData\chocolatey\lib\kafka\tools\kafka_2.11-1.0.0\- 您的版本当然可能不同
  2. 使用添加C:\ProgramData\chocolatey\lib\kafka\tools\kafka_2.11-1.0.0\到您的 powershell 路径notepad $PROFILE

After restarting powershell kafka-console-consumershould work as a command.

重新启动 powershell 后kafka-console-consumer应该可以作为命令工作。

You also need to install ssl.properties with keystore and truststore. Put them e.g. into C:\ProgramData\kafkaand put that into ssl.properties(please note the escaping of the backslashes):

您还需要使用密钥库和信任库安装 ssl.properties。将它们放入例如放入C:\ProgramData\kafka并放入ssl.properties(请注意反斜杠的转义):

security.protocol=SSL

ssl.truststore.location=C:\ProgramData\kafka\kafka-truststore.jks
ssl.truststore.password=PASSWORD

ssl.keystore.location=C:\ProgramData\kafka\kafka-keystore.jks
ssl.keystore.password=PASSWORD
ssl.key.password=PASSWORD

client.id=console-test

Now things like kafka-consumer-groups --bootstrap-server SERVERNAME:9094 --command-config C:\ProgramData\kafka\ssl.properties --listshould first pop up a firewall warning which you'd need to accept and then output a list of groups.

现在kafka-consumer-groups --bootstrap-server SERVERNAME:9094 --command-config C:\ProgramData\kafka\ssl.properties --list应该首先弹出一个防火墙警告,你需要接受它,然后输出一个组列表。