Many small partners may know kafka as a middleware, and then want to build it themselves, so let's integrate SpringBoot from scratch to build it now. Please give me more advice if there are any problems in the writing.
"Preface" On the premise that we want to do this demo, we need to build the environment
Build ZooKeeper, because Kafka is strongly dependent on ZooKeeper, and Kafka cannot run without ZooKeeper . ZooKeeper provides Kafka with metadata management, such as some Broker information, topic data, partition data, etc.- Build a Kafka cluster
- After building the cluster, we create a Maven project based on SpringBoot
- Write code and debug code here "GitHub"
Next, let's build Zookeeper together
1 First download zookeeper
apache zookeeper official website: https://zookeeper.apache.org/
apache zookeeper download address: https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/
Look good, download this "bin. tar.gz” suffix, here we take the Apple notebook system as an example, because it is more similar to the Linux system
1.1 decompression software
tar -zxvf apache-zookeeper-3.7.0-bin.tar.gz
1.2 Copy three copies of zookeeper, named zookeeper-1, zookeeper-2, zookeeper-3 respectively
1.3 Copy the zoo.example.cfg file in zookeeper-1 and change its name to: zoo.cfg
**Remarks: **Modified config/zoo.cfg file " the datalog folder does not exist, create it manually "
This is the configuration of the second file "I am optimistic about the location of dataDir, the location of my computer files"
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/Users/myh/soft-learn/zookeeper-2/datalog
clientPort=2182
server.1=localhost:2887:3887
server.2=0.0.0.0:2888:3888
server.3=localhost:2889:3889
This is the content of the third file
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/Users/myh/soft-learn/zookeeper-3/datalog
clientPort=2183
server.1=localhost:2887:3887
server.2=localhost:2888:3888
server.3=0.0.0.0:2889:3889
The "datalog" folder mentioned above is created, and then do the following step
分别-- 在datalog目录下 -- 执行以下命令,写入myid。
创建的时候看着点,看着点,看着点,这个路径
/Users/myh/soft-learn/ 是你自己电脑的路径,别抄我这个
echo "1" > /Users/myh/soft-learn/zookeeper-1/datalog/myid
echo "2" > /Users/myh/soft-learn/zookeeper-2/datalog/myid
echo "3" > /Users/myh/soft-learn/zookeeper-3/datalog/myid
Finally, start the zookeeper cluster separately
/Users/myh/soft-learn/zookeeper-1/bin/zkServer.sh start
/Users/myh/soft-learn/ zookeeper-2/bin/zkServer.sh start
/Users/myh/soft-learn/ zookeeper-3/bin/zkServer.sh start
Don't worry about the following, execute all three commands, start the three zookeepers, and then look down for
each execution to see this. If it has been started, first use the PS command to view the number, and then use kill command to kill this process
Use the following command to determine whether the startup is successful
/Users/myh/soft-learn/ zookeeper-1/bin/zkServer.sh status
/Users/myh/soft-learn/ zookeeper-2/bin/zkServer.sh status
/Users/myh/soft-learn/ zookeeper-3/bin/zkServer.sh status
Execute the above command and you should be able to see the information in the red box on the line and surface, so Zookeeper has been built successfully.
If you want to see the steps of building a Kafka cluster, read the next article