kafka KRaft 集群搭建

kafka KRaft集群安装

包下载

https://downloads.apache.org/kafka/3.6.1/kafka_2.13-3.6.1.tgz

kafka集群构建好后的数据目录结构

[root@localhost data]# tree /data/kafka
/data/kafka
├── kafka-1	# 节点1源码目录
├── kafka-2	# 节点2源码目录
├── kafka-3	# 节点3源码目录
└── kafkadata	# kafka数据存放目录
    ├── kafkadata1	# 节点1数据存放目录
    ├── kafkadata2	# 节点2数据存放目录
    └── kafkadata3	# 节点3数据存放目录

更改kafka配置文件

kafka节点1配置文件
[root@localhost kraft]# cat cat /data/kafka/kafka-1/config/kraft/server.properties  |grep -Ev "#|^$"
# 表示kafka的KRaft模式
process.roles=broker,controller
# 集群节点的标记
node.id=1
# 参与集群投票节点
controller.quorum.voters=1@localhost:19093,2@localhost:29093,3@localhost:39093
# 定义监听地址
listeners=PLAINTEXT://:19092,CONTROLLER://:19093
inter.broker.listener.name=PLAINTEXT
# 对外宣告地址
advertised.listeners=PLAINTEXT://localhost:19092
controller.listener.names=CONTROLLER
listener.security.protocol.map=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/tmp/kraft-combined-logs
num.partitions=1
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
kafka节点2配置文件
[root@localhost kafka]# cat /data/kafka/kafka-2/config/kraft/server.properties  |grep -Ev "#|^$"
process.roles=broker,controller
node.id=2
controller.quorum.voters=1@localhost:19093,2@localhost:29093,3@localhost:39093
listeners=PLAINTEXT://:29092,CONTROLLER://:29093
inter.broker.listener.name=PLAINTEXT
advertised.listeners=PLAINTEXT://localhost:29092
controller.listener.names=CONTROLLER
listener.security.protocol.map=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/data/kafka/kafkadata/kafkadata2
num.partitions=1
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
kafka节点3配置文件
[root@localhost kafka]# cat /data/kafka/kafka-3/config/kraft/server.properties  |grep -Ev "#|^$"
process.roles=broker,controller
node.id=3
controller.quorum.voters=1@localhost:19093,2@localhost:29093,3@localhost:39093
listeners=PLAINTEXT://:39092,CONTROLLER://:39093
inter.broker.listener.name=PLAINTEXT
advertised.listeners=PLAINTEXT://localhost:39092
controller.listener.names=CONTROLLER
listener.security.protocol.map=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/data/kafka/kafkadata/kafkadata3
num.partitions=1
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000

获取集群uuid

[root@localhost kafka]# /data/kafka/kafka-1/bin/kafka-storage.sh random-uuid
fzSBf0PjTRi3zNH_0Abc-g

格式化kafka数据存储目录

/data/kafka/kafka-1/bin/kafka-storage.sh format -t fzSBf0PjTRi3zNH_0Abc-g -c /data/kafka/kafka-1/config/kraft/server.properties
/data/kafka/kafka-2/bin/kafka-storage.sh format -t fzSBf0PjTRi3zNH_0Abc-g -c /data/kafka/kafka-2/config/kraft/server.properties
/data/kafka/kafka-3/bin/kafka-storage.sh format -t fzSBf0PjTRi3zNH_0Abc-g -c /data/kafka/kafka-3/config/kraft/server.properties

启动kafka

nohup /data/kafka/kafka-1/bin/kafka-server-start.sh /data/kafka/kafka-1/config/kraft/server.properties >> /data/kafka/kafkadata/kafka-1.log &
nohup /data/kafka/kafka-2/bin/kafka-server-start.sh /data/kafka/kafka-2/config/kraft/server.properties >> /data/kafka/kafkadata/kafka-2.log &
nohup /data/kafka/kafka-3/bin/kafka-server-start.sh /data/kafka/kafka-3/config/kraft/server.properties >> /data/kafka/kafkadata/kafka-3.log &

创建主题,3个分区,3个副本

 /data/kafka/kafka-3/bin/kafka-topics.sh --create --topic test-topic --bootstrap-server localhost:39092 --replication-factor 3 --partitions 3

列出主题,查看主题是否创建

 /data/kafka/kafka-3/bin/kafka-topics.sh --list --bootstrap-server localhost:39092

生产消息

 /data/kafka/kafka-3/bin/kafka-console-producer.sh --topic test-topic --bootstrap-server localhost:39092

消费消息

 /data/kafka/kafka-3/bin/kafka-console-consumer.sh --topic test-topic --from-beginning --bootstrap-server localhost:39092

检查集群脚本状态

/data/kafka/kafka-3/bin/kafka-broker-api-versions.sh --bootstrap-server localhost:39092

集群的性能测试

生产者性能测试
 /data/kafka/kafka-3/bin/kafka-producer-perf-test.sh --topic test-topic --num-records 50000 --record-size 1000 --throughput -1 --producer-props bootstrap.servers=localhost:39092
消费者性能测试
 /data/kafka/kafka-3/bin/kafka-consumer-perf-test.sh --topic test-topic --bootstrap-server localhost:39092 --fetch-size 1048576 --messages 50000 --threads 1
相关推荐
weixin_453965001 小时前
[单master节点k8s部署]31.ceph分布式存储(二)
分布式·ceph·kubernetes
坎坎坷坷.1 小时前
分布式理论:拜占庭将军问题
分布式
极客先躯7 小时前
高级java每日一道面试题-2024年10月3日-分布式篇-分布式系统中的容错策略都有哪些?
java·分布式·版本控制·共识算法·超时重试·心跳检测·容错策略
niu_sama8 小时前
仿RabbitMQ实现消息队列三种主题的调试及源码
分布式·rabbitmq
鸡c8 小时前
rabbitMq------客户端模块
分布式·rabbitmq·ruby
猿java9 小时前
使用 Kafka面临的挑战
java·后端·kafka
Dylanioucn9 小时前
【分布式微服务云原生】探索Redis:数据结构的艺术与科学
数据结构·redis·分布式·缓存·中间件
路上^_^9 小时前
00_概览_kafka
分布式·kafka
极客先躯16 小时前
Hadoop krb5.conf 配置详解
大数据·hadoop·分布式·kerberos·krb5.conf·认证系统
CopyLower17 小时前
Kafka 消费者状态及高水位(High Watermark)详解
分布式·kafka