Last active
October 2, 2023 14:09
-
-
Save craigminihan/e9c3dbe02788ab357900 to your computer and use it in GitHub Desktop.
A batch script to install Kafka and Zookeeper on Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
rem ************************************************************ | |
rem Installs Kafka (and Zookeeper) as services and runs them | |
rem ************************************************************ | |
set NSSM_VER=2.24 | |
set TMP_ROOT=c:\tmp | |
set OPT_ROOT=c:\opt | |
set KAFKA_ROOT=%OPT_ROOT%\kafka | |
mkdir %OPT_ROOT% | |
mkdir %TMP_ROOT% | |
rem stop and from zookeeper and kafka services | |
sc stop kafka | |
sc stop zookeeper | |
timeout 5 | |
sc delete kafka | |
sc delete zookeeper | |
timeout 2 | |
rem remove the old kafka install if there | |
rmdir /q /s %KAFKA_ROOT% | |
rem remove the old zookeeper and kafka config if there | |
pushd %TMP_ROOT% | |
rmdir /q /s kafka-logs | |
rmdir /q /s zookeeper | |
popd | |
rem install kafka and zookeeper to %OPT_ROOT% | |
7z x -y kafka_*.tgz | |
7z x -y -o%OPT_ROOT% kafka_*.tar | |
move /Y %OPT_ROOT%\kafka* %KAFKA_ROOT% | |
echo delete.topic.enable = true >> %KAFKA_ROOT%/config/server.properties | |
rem install kafka and zookeeper as services and start them | |
rmdir /s /q nssm-%NSSM_VER% | |
7z x -y nssm-%NSSM_VER%.zip | |
pushd nssm-%NSSM_VER%\win64 | |
nssm install zookeeper %KAFKA_ROOT%\bin\windows\zookeeper-server-start.bat ..\..\config\zookeeper.properties | |
nssm install kafka %KAFKA_ROOT%\bin\windows\kafka-server-start.bat %KAFKA_ROOT%\config\server.properties | |
nssm set kafka DependOnService zookeeper | |
sc start zookeeper | |
timeout 5 | |
sc start kafka | |
popd |
interesting solution if it works it will save ton of time
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script assumes it is run in the same directory as:
You also need Java installed. The script must be run inside an administrator console.
After installation Kafka and Zookeeper will be running as Windows services.