1. Install Zookeeper and Kafka
brew install kafka
brew install zookeeper
Kafka version: 2.2.0; zk version: 3.4.13
Both installation directories are in: /usr/local/Cellar directory.
2. ZK starts
ZK related catalog
ZK安装目录: /usr/local/Cellar
ZK配置文件目录: /usr/local/etc/zookeeper
ZK dataDir目录:/usr/local/var/run/zookeeper/data
Execute the command:, zkserver start
you can see that ZK is started, and the started port is 2181.
Execute the command:, zkCli
you can see the data node;
Execute the command:, zkServer status
you can see Mode: standalone
the stand-alone mode.
Zoo.cfg configuration content:
3. Kafka starts
Kafka related directories:
kafka安装目录: /usr/local/Cellar/kafka/2.1.0
Kafka配置文件目录(server/consumer/producer配置都在这里): /usr/local/etc/kafka/*
start up
(1) First, ensure that ZK is started;
(2) Start Kafka Server:kafka-server-start /usr/local/etc/kafka/server.properties
If no error is reported and the log [KafkaServer id=0] started (kafka.server.KafkaServer)
is seen , it means that Kafka has started normally;
KafkaTopic, producer, consumer creation
(1) Create a replica as 1, partition as 1, topic as TestKafkaTopic
kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic TestKafkaTopic
(2) View the created Topic
kafka-topics --list --zookeeper localhost:2181
Note: Before creating a consumer, there will only be topics created:TestKafkaTopic
(3) Create a producer
kafka-console-producer --broker-list localhost:9092 --topic TestKafkaTopic
(4) Create 2 consumers
kafka-console-consumer --bootstrap-server localhost:9092 --topic TestKafkaTopic --from-beginning
(5) Test
Open two windows for testing, the producer sends a test send message from producer
message:, the consumer receives the message:
At this time, let’s look at the topic again, and there will be one more topic:, __consumer_offsets
this topic is an internal topic in Kafka, used to record the consumer's consumption displacement.