当前位置: 首页 > news >正文

Kafka - Install Kafka-4.1.1

 

frank@ZZHPC:~/download$ sudo adduser --system --no-create-home --group kafkafrank@ZZHPC:~/download$ wget https://dlcdn.apache.org/kafka/4.1.1/kafka_2.13-4.1.1.tgzfrank@ZZHPC:~/download$ tar -xzf kafka_2.13-4.1.1.tgzfrank@ZZHPC:~/download$ sudo mv kafka_2.13-4.1.1 /opt

 

export KAFKA_HOME=/opt/kafka_2.13-4.1.1
export PATH=$PATH:$SPARK_HOME/sbin:$SPARK_HOME/bin:$FLINK_HOME/bin:$KAFKA_HOME/bin

 

Here is a complete, copy-paste-ready setup for a single-node Kafka 4.1.1 KRaft cluster on Ubuntu.
This is the simplest reliable configuration for development or local testing.


✅ 1. Create a minimal KRaft config file

Create:

$KAFKA_HOME/config/kraft/server.properties

Paste this exact file:

 

✅ 2. Generate a cluster ID

 
$KAFKA_HOME/bin/kafka-storage.sh random-uuid

You will get output like:

 
Gv4j8tB8QFu8m6BQ8fQQAA

✅ 3. Format the KRaft metadata directory

Use the generated cluster ID here:

 
$KAFKA_HOME/bin/kafka-storage.sh format \-t Gv4j8tB8QFu8m6BQ8fQQAA \-c $KAFKA_HOME/config/kraft/server.properties

You should see:

 
Formatted log directories in /tmp/kraft-combined-logs

✅ 4. Start Kafka (no ZooKeeper required)

 
$KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/kraft/server.properties

Kafka 4.1.1 is now running in combined controller + broker mode.


🎉 5. Test your Kafka instance

Create a topic:

 
$KAFKA_HOME/bin/kafka-topics.sh \--create \--topic test-topic \--bootstrap-server localhost:9092

Produce messages:

 
$KAFKA_HOME/bin/kafka-console-producer.sh \--topic test-topic \--bootstrap-server localhost:9092

(type messages, press Enter)

Consume messages:

 
$KAFKA_HOME/bin/kafka-console-consumer.sh \--topic test-topic \--from-beginning \--bootstrap-server localhost:9092

🚀 You now have a working single-node Kafka 4.1.1 setup!

If you'd like, I can also provide:

    • Systemd service files to run Kafka automatically on boot

    • A docker-compose setup for Kafka 4.x

    • A multi-node KRaft cluster config

 

frank@ZZHPC:~$ kafka-topics.sh --create --topic test-topic --bootstrap-server localhost:9092
Created topic test-topic.
frank@ZZHPC:~$ kafka-console-producer.sh --topic test-topic --bootstrap-server localhost:9092
>msg1
>msg2
>

 

frank@ZZHPC:~$ kafka-console-consumer.sh --topic test-topic --from-beginning --bootstrap-server localhost:9092
msg1
msg2