Kafka网址:https://kafka.apache.org/
PS:因环境原因此文档内端口都有修改!
PS:3.4.0是目前最新的版本!需要jdk1.8及以上版本启动。
[root@k8s-node1 ~]# wget https://downloads.apache.org/kafka/3.4.0/kafka_2.12-3.4.0.tgz
[root@k8s-node1 ~]# tar zxvf kafka-3.4.0-src.tgz
[root@k8s-node1 ~]# cd kafka_2.12-3.4.0/
[root@k8s-node1 kafka_2.12-3.4.0]# ls
bin config libs LICENSE licenses NOTICE site-docs
[root@k8s-node1 ~]# cd kafka_2.12-3.4.0/config/kraft/
[root@k8s-node1 kraft]# vim server.properties
......
process.roles=broker,controller
node.id=1
controller.quorum.voters=1@192.168.1.10:9094,2@192.168.1.11:9094,3@192.168.1.12:9094
listeners=PLAINTEXT://192.168.12.10:9093,CONTROLLER://192.168.12.10:9094
inter.broker.listener.name=PLAINTEXT
advertised.listeners=PLAINTEXT://192.168.1.10:9093
log.dirs=logs
集群内配置文件示例:
PS:配置文件内是三controller,五broker;
#node1
process.roles=broker,controller
node.id=1
controller.quorum.voters=1@192.168.1.10:9094,2@192.168.1.11:9094,3@192.168.1.12:9094
listeners=PLAINTEXT://192.168.12.10:9093,CONTROLLER://192.168.12.10:9094
inter.broker.listener.name=PLAINTEXT
advertised.listeners=PLAINTEXT://192.168.1.10:9093
log.dirs=logs
#node2
process.roles=broker,controller
node.id=1
controller.quorum.voters=1@192.168.1.10:9094,2@192.168.1.11:9094,3@192.168.1.12:9094
listeners=PLAINTEXT://192.168.12.11:9093,CONTROLLER://192.168.12.11:9094
inter.broker.listener.name=PLAINTEXT
advertised.listeners=PLAINTEXT://192.168.1.11:9093
log.dirs=logs
#node3
process.roles=broker,controller
node.id=1
controller.quorum.voters=1@192.168.1.10:9094,2@192.168.1.11:9094,3@192.168.1.12:9094
listeners=PLAINTEXT://192.168.12.12:9093,CONTROLLER://192.168.12.12:9094
inter.broker.listener.name=PLAINTEXT
advertised.listeners=PLAINTEXT://192.168.1.12:9093
log.dirs=logs
#node4
process.roles=broker
node.id=1
controller.quorum.voters=1@192.168.1.10:9094,2@192.168.1.11:9094,3@192.168.1.12:9094
listeners=PLAINTEXT://192.168.12.13:9093
inter.broker.listener.name=PLAINTEXT
advertised.listeners=PLAINTEXT://192.168.1.13:9093
log.dirs=logs
#node5
process.roles=broker
node.id=1
controller.quorum.voters=1@192.168.1.10:9094,2@192.168.1.11:9094,3@192.168.1.12:9094
listeners=PLAINTEXT://192.168.12.14:9093
inter.broker.listener.name=PLAINTEXT
advertised.listeners=PLAINTEXT://192.168.1.14:9093
log.dirs=logs
# 生成集群uuid
[root@k8s-node1 kafka_2.12-3.4.0]# KAFKA_CLUSTER_ID="$(bin/kafka-storage.sh random-uuid)"# 格式日志目录
[root@k8s-node1 kafka_2.12-3.4.0]# bin/kafka-storage.sh format -t $KAFKA_CLUSTER_ID -c config/kraft/server.properties
# 格式日志目录
[root@k8s-node2 kafka_2.12-3.4.0]# bin/kafka-storage.sh format -t (node01生成的UUID) -c config/kraft/server.properties
[root@k8s-node3 kafka_2.12-3.4.0]# bin/kafka-storage.sh format -t (node01生成的UUID) -c config/kraft/server.properties
[root@k8s-node4 kafka_2.12-3.4.0]# bin/kafka-storage.sh format -t (node01生成的UUID) -c config/kraft/server.properties
[root@k8s-node5 kafka_2.12-3.4.0]# bin/kafka-storage.sh format -t (node01生成的UUID) -c config/kraft/server.properties
[root@k8s-node1 kafka_2.12-3.4.0]# bin/kafka-server-start.sh config/kraft/server.properties
[root@k8s-node1 kafka_2.12-3.4.0]# ss -lnt| grep -E '9093|9094'
LISTEN 0 50 [::ffff:192.168.12.134]:9093 [::]:*
LISTEN 0 50 [::ffff:192.168.12.134]:9094 [::]:*
PS:9093是PLAINTEXT的端口,9094是broker的端口。
[root@k8s-node1 kafka_2.12-3.4.0]# ./kafka-topics.sh --create --bootstrap-server 192.168.1.10:9093 --replication-factor 2 --partitions 5 --topic test
PS:Kafka Map是一款可视化平台软件,可参考链接自行搭建。 https://gitee.com/dushixiang/kafka-map/