To prepare

Middleware version information used by the cluster

The middleware version
jdk 1.8
kafka 2.7.1
zookeeper 3.7.0

Before installing Kafka and ZooKeeper, ensure that the Java environment has been configured.

Download address portal

kafka zookeeper

For details about how to install the ZooKeeper cluster, see

Blog.csdn.net/u010277958/…

Or use Docker-compose to install ZooKeeper

Github.com/xiao-ren-wu…

The kafka-broker cluster complement is as follows

Three Kafka-Broker nodes are deployed, and the metadata is stored in the ZooKeeper cluster.

Broker ports are used as follows:

broker id port
Broker – 0 0 9090
broker-1 1 9091
broker-2 2 9092

All kafka nodes and ZK nodes are installed on the same physical machine. Do not do this in production environment 🙂


The body of the

1. Create a kafka cluster installation directory, unzip the Kafka installation package, change it to a nice name, and make three copies
$tar - XVF kafka_2.13-2.7.0. TGZ $MV Kafka_2.7.0Broker_0 $CP - R broker_0 broker_1 $CP - R broker_0 broker_2Copy the code
2. Enter theconfigThe directory editorserver.properties
$ cd config/
$ vim server.properties
Copy the code
3. Set the broker. Id, listeners, the dirs, zookeeper. Connect

Broker_0 has the following configuration

broker.id=0
listeners=PLAINTEXT://:9090
log.dirs=/usr/local/kafka-cluster/kafka_0/kafka-logs
zookeeper.connect=localhost:2181,localhost:2182,localhost:2183
Copy the code

Broker_1 has the following configuration

broker.id=1
listeners=PLAINTEXT://:9091
log.dirs=/usr/local/kafka-cluster/kafka_1/kafka-logs
zookeeper.connect=localhost:2181,localhost:2182,localhost:2183
Copy the code

Broker_2 is configured as follows

broker.id=2
listeners=PLAINTEXT://:9092
log.dirs=/usr/local/kafka-cluster/kafka_3/kafka-logs
zookeeper.connect=localhost:2181,localhost:2182,localhost:2183
Copy the code
4. Start the kafka

Execute startup commands in each directory

$ sh ./bin/kafka-server-start.sh -daemon ./config/server.properties
Copy the code
Through 5.jpsThe command displays that Kafka has been started successfully
$ jps
4848 Jps
4204 Kafka
4846 Kafka
4527 Kafka
Copy the code
Create a topic

Create a topic named foo with 6 partitions and 3 copies

$ ./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 6 --topic foo
Copy the code
7. Check the topic you created
./bin/kafka-topics.sh --list --zookeeper localhost:2181
Copy the code

Alternatively, you can view the Topic information of ZooKeeper directly

8. Stop the Kafka cluster

Execute on any node

$ ./bin/kafka-server-stop.sh
Copy the code