kafka4.0集群部署

kafka4.0是最新版kafka,可在kafka官网下载,依赖的jdk版本要求在jdk17及jdk17以上

tar -xzf kafka_2.13-4.0.0.tgz

mv kafka_2.13-4.0.0 kafka

cd kafka

随便一台节点运行生成随机uuid,后面每台节点都要使用此uuid

bin/kafka-storage.sh random-uuid 生成的uuid(IyyjPwZcTa2LHKkV1rj5pg)

每个节点需要在config/server.properties中配置相关内容

node.id

controller.quorum.voters=1@192.168.10.10:9093,2@192.168.10.20:9093,3@192.168.10.30:9093

log.dirs=/opt/kafka/log/kraft-combined-logs

num.partitions=16

每台节点设置日志目录的格式,$KAFKA_CLUSTER_ID应为上面生成的值,每个节点都要用相同的uuid

bin/kafka-storage.sh format -t IyyjPwZcTa2LHKkV1rj5pg -c config/server.properties

启动 Kafka 服务,每台节点都执行

bin/kafka-server-start.sh -daemon /opt/kafka/config/server.properties

测试kafka集群

创建主题名为cluster-topic存储事件

bin/kafka-topics.sh --bootstrap-server 192.168.10.10:9092 --create --topic cluster-topic1 --partitions 3 --replication-factor 3

在其他节点(9092)查询该topic

bin/kafka-topics.sh --describe --topic cluster-topic1 --bootstrap-server 192.168.10.20:9092

将事件写入主题

bin/kafka-console-producer.sh --topic cluster-topic1 --bootstrap-server 192.168.10.10:9092

This is my first event

This is my second event

读取事件

bin/kafka-console-consumer.sh --topic cluster-topic --from-beginning --bootstrap-server 192.168.10.10:9092

删除主题

bin/kafka-topics.sh --bootstrap-server 192.168.10.10:9092 --delete --topic cluster-topic

配置systemd服务

先关闭kafka服务

/opt/kafka/bin/kafka-server-stop.sh config/server.properties

配置服务

bash 复制代码
cat >>/etc/systemd/system/kafka.service << EOF

[Unit]

Description=Apache Kafka Service (KRaft Mode)

After=network.target



[Service]

Type=simple

User=root

Group=root

ExecStart=/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties

ExecStop=/opt/kafka/bin/kafka-server-stop.sh

Restart=on-abnormal

WorkingDirectory=/opt/kafka

Environment="JAVA_HOME=/usr/local/jdk-17.0.12"



[Install]

WantedBy=multi-user.target

EOF



systemctl daemon-reload

systemctl start kafka

systemctl status kafka
相关推荐
yh云想20 小时前
《从入门到精通:Kafka核心原理全解析》
分布式·kafka
武子康21 小时前
大数据-70 Kafka 日志清理:删除、压缩及混合模式最佳实践
大数据·后端·kafka
花酒锄作田2 天前
Nginx反向代理Kafka集群
nginx·kafka
武子康2 天前
大数据-69 Kafka 存储结构解析:日志文件与索引文件的内部机制
大数据·后端·kafka
自由自在的小Bird3 天前
kafka初步介绍
spring boot·后端·kafka
愚昧之山绝望之谷开悟之坡3 天前
Kafka 的消费
分布式·kafka
BD_Marathon3 天前
Kafka下载和安装
分布式·kafka
孫治AllenSun3 天前
【Docker】安装kafka案例
docker·容器·kafka
bing_1584 天前
kafka 消费者组的概念是什么?它是如何实现消息的点对点和发布/订阅模式?
分布式·kafka
会飞的架狗师4 天前
【Kafka系列】第三篇| 在哪些场景下会选择使用 Kafka?
kafka