Construction of kafka environment on Windows platform

Note: Please make sure that the local Java environment variables are configured successfully

1. Install Zookeeper The operation of Kafka depends on Zookeeper, so before running Kafka we need to install and run Zookeeper  1.1 Download the installation file:  http://mirror.bit.edu.cn/apache/zookeeper/ 1.2 Unzip the file (this article unzips to D:\zookeeper-3.4.8)  1.3 Open D:\zookeeper-3.4.8\conf, rename zoo_sample.cfg to zoo.cfg  1.4 Open zoo.cfg from a text editor  1.5 Modify dataDir and dataLogDir save path  dataDir =D:\data\logs\zookeeper  dataLogDir=D:\data\logs\zookeeper  1.6 Add the following system variables: Path: Add 1.7 after the existing value  Run Zookeeper: Open cmd and execute the  command. If the following information is printed, it means that zookeeper has been installed successfully and is running on port 2181.  

 






ZOOKEEPER_HOME: D:\zookeeper-3.4.8 
;%ZOOKEEPER_HOME%\bin; 
zkserver

write picture description here

2. Install and run Kafka 
2.1 Download the installation file:  http://kafka.apache.org/downloads.html 
2.2 Unzip the file (this article unzips to D:\kafka_2.11-0.10.2.0) 
2.3 Open D:\kafka_2.11 -0.10.2.0\config\ server.properties 
2.4 Change the value of log.dirs to log.dirs=D:\data\logs\kafka 
2.5 D:\kafka_2.11-0.10.2.0\bin folder.sh The command script is run under the shell. There is also a windows folder under this folder, which is the .bat command script running under windows. 
2.6 "Shift+right mouse button" in the D:\kafka_2.11-0.10.2.0 folder Click on the empty space to open the command prompt window 
2.7 Enter and execute the following command to open kafka:

.\bin\windows\kafka-server-start.bat .\config\server.properties
  • 1

The displayed information is as follows, it means normal operation 
write picture description here

Error: Could not find or load main class 
 The solution is as follows: 在kafka安装目录中找到bin\windows目录中的kafka-run-class.bat找到142行为%CLASSPATH%加上双引

Before modification : 
set COMMAND=%JAVA% %KAFKA_HEAP_OPTS% %KAFKA_JVM_PERFORMANCE_OPTS% %KAFKA_JMX_OPTS% %KAFKA_LOG4J_OPTS% -cp %CLASSPATH% %KAFKA_OPTS% %* 
After modification
set COMMAND=%JAVA% %KAFKA_HEAP_OPTS% %KAFKA_JVM_PERFORMANCE_OPTS% %KAFKA_JMX_OPTS% %KAFKA_LOG4J_OPTS% -cp "%CLASSPATH%" %KAFKA_OPTS% %*

3. Create topics 

3.1 In the D:\kafka_2.11-0.10.2.0\bin\windows folder, click "Shift+right mouse button" to open the command prompt window
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
  • 1

4. Open a Producer 
4.1 in the D:\kafka_2.11-0.10.2.0\bin\windows folder "Shift + right mouse button" click on the blank space to open the command prompt window

kafka-console-producer.bat --broker-list localhost:9092 --topic test
  • 1

5. Open a Consumer 
5.1 in the D:\kafka_2.11-0.10.2.0\bin\windows folder "Shift + right mouse button" click on the blank space to open the command prompt window

kafka-console-consumer.bat --zookeeper localhost:2181 --topic test
  • 1

Note: Do not close the window opened above 
and then you can enter messages in the Producer console window. Soon after the message is entered, the Consumer window will display the message sent by the Producer: 
write picture description here


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325527288&siteId=291194637
Recommended