Kafka3.0 安装镜像下载

阿里云镜像

Kafka配置

在kafka2.8中就已经开始弃用外部的zookeeper依赖了,而在内部集成了高适配的zk

kafka.png

内置的zk端口默认是2181,而kafka broker默认的端口是9092这里需要区分

# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0

# A comma separated list of directories under which to store log files
log.dirs=/usr/local/kafka/datas

# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=localhost:2181

kafka broker端口

############################# Producer Basics #############################

# list of brokers used for bootstrapping knowledge about the rest of the cluster
# format: host1:port1,host2:port2 ...
bootstrap.servers=localhost:9092

命令行基本使用

这里演示单机情况,kafka安装路径 /usr/local/kafka

1、首先启动kafka自带的zk

bin/zookeeper-server-start.sh -daemon config/zookeeper.properties

2、启动kafka

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

3、创建topic

bin/kafka-topics.sh --bootstrap-server localhost:9092 --topic first --create --partitions 1 --replication-factor 1
Created topic first.

4、查看topic列表

bin/kafka-topics.sh --bootstrap-server localhost:9092 --topic first --describe
Topic: first    TopicId: d1AD5F-2Sf-gBatOuEev6Q    PartitionCount: 1    ReplicationFactor: 1    Configs: segment.bytes=1073741824
    Topic: first    Partition: 0    Leader: 0    Replicas: 0    Isr: 0

5、创建producer进程

bin/kafka-console-producer.sh --bootstrap-server localhost:9092 -topic first

producer.png

6、创建consumer进程

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic first

consumer.png

最后修改:2022 年 06 月 23 日
如果觉得我的文章对你有用,请随意赞赏