环境准备
环境:jdk8,三台centos机器,基于kraft模式(不使用zk)
kafka安装包:https://mirrors.aliyun.com/apache/kafka/3.4.0/kafka_2.13-3.4.0.tgz
机器ip | hostname | 配置 |
---|---|---|
192.168.1.138 | kafka01 | 8c16g |
192.168.1.139 | kafka02 | 8c16g |
192.168.1.140 | kafka03 | 8c16g |
# 根据规划设置主机名,这里三台主机的hostname不一样
hostnamectl set-hostname kafka01
hostnamectl set-hostname kafka02
hostnamectl set-hostname kafka03
#每台机器执行
cat >> /etc/hosts << EOF
192.168.1.138 kafka01
192.168.1.139 kafka02
192.168.1.140 kafka03
EOF
确保机器直接能ping通:
修改kafka01机器上config/kraft/server.properties
文件,部分参数需要根据自己需要进行修改
其他机器的advertised.listeners
和node.id
也需要修改
process.roles=broker,controller
#这里需要修改
node.id=1
#这里需要修改
controller.quorum.voters=1@kafka01:9093,2@kafka02:9093,3@kafka03:9093
listeners=PLAINTEXT://:9092,CONTROLLER://:9093
inter.broker.listener.name=PLAINTEXT
#这里需要修改
advertised.listeners=PLAINTEXT://kafka01:9092
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
#kraft日志存储目录
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
初始化集群数据目录:
bin/kafka-storage.sh random-uuid
每台机器执行:
bin/kafka-storage.sh format -t EzhjsV8IS3SwDFK42SbSnA -c /opt/kafka_2.13-3.4.0/config/kraft/server.properties
#启动kafka集群
bin/kafka-server-start.sh -daemon config/kraft/server.properties
测试集群
#创建topic
bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server kafka01:9092,kafka02:9092,kafka03:9092 --partitions 3 --replication-factor 2
#查看该topic信息
bin/kafka-topics.sh --describe --topic quickstart-events --bootstrap-server kafka01:9092,kafka02:9092,kafka03:9092
测试消息发送:
#消息发送
bin/kafka-console-producer.sh --topic quickstart-events --bootstrap-server kafka01:9092,kafka02:9092,kafka03:9092
消息接收:
bin/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server kafka01:9092,kafka02:9092,kafka03:9092
查看日志文件:
压测Producer:一百万条消息
bin/kafka-producer-perf-test.sh --topic quickstart-events --record-size 200 --num-records 1000000 --throughput -1 --producer-props bootstrap.servers=kafka01:9092,kafka02:9092,kafka03:9092
平均每条数据延迟两百毫秒,最大延迟八百毫秒
标签:bin,Kafka3.4,--,9092,kafka,集群,kraft,kafka01,server From: https://www.cnblogs.com/wwjj4811/p/17173188.html