How to install Kafka as windows service? The official website project uses kafka and zookeeper. It was originally started through the command line. The risk is that other people on the server may shut down the command line cmd for you at any time or accidentally, so that kafka and zookeeper will die. Then how to install Kafka as a windows service? Also install zookeeper as a windows service.
Install Kafka as windows service
Usually only need to execute the command to start Kafka:
kafka-server-start.bat E:\Tool\kafka_2.12-2.2.0\config\server.properties
After the startup is successful, you will see the prompt as shown in the figure below:
The above are common in the windows service using the command line mode on the device to start kafka, disadvantages already mentioned above, next, a look at how to install it as a service.
Let’s take a look at the effect of installing Kafka as a service.
Similarly, after zookeeper is installed as a windows service, it can also be seen in the service list.
The service names above kafka and zookeeper can be taken at will. Whatever you are happy to call, for example: jhrs.com is also possible.
If you also plan to install kafka and zookeeper as windows services, here are the steps to be introduced in this article, and introduce a small software called nssm.
Introduction to NSSM
NSSM is a service packaging program. It can encapsulate ordinary exe, bat, and any program into a service, making it run like a windows service, just like a service shell, package your program in NSSM.
The official website explains as follows:
NSSM – the Non-Sucking Service Manager
nssm is a service helper which doesn’t suck. srvany and other service helper programs suck because they don’t handle failure of the application running as a service. If you use such a program you may see a service listed as started when in fact the application has died. nssm monitors the running service and will restart it if it dies. With nssm you know that if a service says it’s running, it really is. Alternatively, if your application is well-behaved you can configure nssm to absolve all responsibility for restarting it and let Windows take care of recovery actions.
nssm logs its progress to the system Event Log so you can get some idea of why an application isn’t behaving as it should.
nssm also features a graphical service installation and removal facility. Prior to version 2.19 it did suck. Now it’s quite a bit better.
how to use
- Download NSSM download .
- According to your platform, unzip the 32/64-bit nssm.exe file to any folder.
- Cmd locates the directory where nssm.exe is located.
- Enter
nssm install {service name}
the name of the registered service. The registration service pops up the following NSSM interface.
Kafka installed as a win service
Just follow the above steps, the core is the screenshot below, you can also add dependent services.
Path:E:\Tool\kafka_2.12-2.2.0\bin\windows\kafka-server-start.bat Startup directory:E:\Tool\kafka_2.12-2.2.0\bin\windows Arguments:E:\Tool\kafka_2.12-2.2.0\config\server.properties
The Path parameter is the startup command of Kafka, generally in the windows directory. Startup directory is the startup directory, and Arguments are startup parameters. Only the startup parameters need to be filled in manually. When you click the button on the right of Path, the first two parameters will be automatically filled in. Under the experience of own operation, you will understand.
After that, click Install Service .
If there are dependent services, just fill in as shown in the figure below.
zookeeper installed as a windows service
Zookeeper can also be installed as a service for windows, as shown in the figure below:
No need to fill if there is no parameter.
If you think the interface operation is troublesome, you can make a batch file and install it all at once.
One-click installation of BAT as a Windows service
@echo off @echo install zookeeper nssm install zookeeper E:\Tool\zookeeper-3.4.10\bin\zkServer.cmd @echo install kafka nssm install kafka E:\Tool\kafka_2.12-2.2.0\bin\windows\kafka-server-start.bat E:\Tool\kafka_2.12-2.2.0\config\server.properties @echo start zookeeper service nssm start zookeeper @echo start kafka service nssm start kafka pause
The above command is one-click installation as a windows service through a batch file, and start zookeeper and kafka services. You can use it directly. Note that you need to modify the following parameters. For example, modify E:\Tool\zookeeper-3.4.10\bin\zkServer.cmd to the zookeeper directory on your server, and E:\Tool\kafka_2.12- 2.2.0\bin\windows\kafka-server-start.bat E:\Tool\kafka_2.12-2.2.0\config\server.properties is also the corresponding path modified to kafka.
If you want to uninstall, use the bat below.
@echo off @echo uninstall zookeeper nssm remove zookeeper confirm @echo uninstall kafka nssm remove kafka confirm pause
Copy the above code, use Notepad to create a new file, paste it in, and change the suffix to bat. When using it, double-click to run it.
nssm commonly used commands
- nssm install servername //Create servername service
- nssm start servername //Start the service
- nssm stop servername //Stop service
- nssm restart servername //Restart the service
- nssm remove servername //Delete the created servername service
Conclusion
NSSM can install the console program as a service, and cooperate with the timing tasks to do a lot of things.