kafka编译和启动
背景
了解kafka使用
编译
## 拉代码
git clone https://github.com/apache/kafka.git
## 切换目录
cd kafka/
## 编译 打包
./gradlew jar
编译好之后需要启动zookeeper 和kafka
## 生成uuid
KAFKA_CLUSTER_ID="$(bin/kafka-storage.sh random-uuid)"
bin/kafka-storage.sh format -t $KAFKA_CLUSTER_ID -c config/kraft/server.properties
## 启动kafka
bin/kafka-server-start.sh config/kraft/server.properties
在这里为什么要用kafka-storage.sh
生成uuid
, 其实是要和普通的uuid 有点区别,如果重复了,还得丢掉
/**
* Static factory to retrieve a type 4 (pseudo randomly generated) UUID.
*/
public static Uuid randomUuid() {
java.util.UUID uuid = java.util.UUID.randomUUID();
while (uuid.equals(METADATA_TOPIC_ID_INTERNAL) || uuid.equals(ZERO_ID_INTERNAL)) { // 不等于这两个值
uuid = java.util.UUID.randomUUID();
}
return new Uuid(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
}
相关命令
## 查看topic
./bin/kafka-topics.sh --list --bootstrap-server=localhost:9092
相关引用
- kafka 命令
- https://stackoverflow.com/questions/68581003/apache-kafka-kraft-kafka-storage-tool
- https://github.com/apache/kafka/blob/c2ea0c2e1d44332639214b921ddf3dc1edf478c0/clients/src/main/java/org/apache/kafka/common/Uuid.java
- https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/tools/StorageTool.scala
- kafka 的Partitioner
- kafka 使用