Download the kafka installation file

Visit the official address: kafka.apache.org/downloads I download version are the following:

Upload to server /opt and decompress:

[root@iZ2ze7sn66bchxncut8rgsZ /]# CD /opt [root@iZ2ze7sn66bchxncut8rgsZ opt]# tar-xvf kafka_2.12-2.1.0.tgz [root@iZ2ze7sn66bchxncut8rgsZ opt]# CD kafka_2.12-2.7.0/ [root@iZ2ze7sn66bchxncut8rgsZ kafka_2.12-2.7.0]# ll total dosage 56 Drwxr-xr-x 3 root root 4096 12月 16 22:01 bin drwxr-xr-x 2 root root 4096 12月 16 22:01 config drwxr-xr-x 2 root root 8192 2月 1 14:44 libs-RW-r --r-- 1 root root 29975 月 16 21:58 license-RW-r --r-- 1 root root 337 月 16 21:58 NOTICE Drwxr-xr-x 2 root root 44 12月 16 22:01 site-docsCopy the code

2. Start the service

There are two ways to configure ZK: 1) build your own set of services and 2) use the single-node ZK service provided by Kafka.

For demonstration purposes and zK is not a concern, we will use the native ZK directly.

[root@iZ2ze7sn66bchxncut8rgsZ bin]# cd .. / [root @ iZ2ze7sn66bchxncut8rgsZ kafka_2. 12-2.7.0] #. / bin/zookeeper - server - start. Sh config/zookeeper. PropertiesCopy the code

Start the Kafka service:

./bin/kafka-server-start.sh config/server.properties
Copy the code

The above startup is directly started, please use the background to start nohup:

# # # # start zk nohup. / bin/zookeeper - server - start. Sh config/zookeeper properties > / dev/null & # # # # start nohup kafka service ./bin/kafka-server-start.sh config/server.properties >/dev/null &Copy the code

Three, validation,

There is a plug-in, friends can download, to help us separate offline problems. The download address is www.kafkatool.com/

Create a topic named “test-kafka” with one partition and one copy:

[root@iZ2ze7sn66bchxncut8rgsZ kafka_2.12-2.7.0]# bin/kafka-topics --replication-factor 1 --partitions 1 --topic test-kafka Created topic test-kafka.Copy the code

2. Check the existing topics

[root@iZ2ze7sn66bchxncut8rgsZ kafka_2.12-2.7.0]# bin/kafka-topics.sh --list --zookeeper localhost:2181
__consumer_offsets
test
test-kafka
Copy the code

3. Create producers

[root@iZ2ze7sn66bchxncut8rgsZ kafka_2.12-2.7.0]# bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test-kafka
>
Copy the code

4. Open a new window and create a consumer

[root@iZ2ze7sn66bchxncut8rgsZ kafka_2.12-2.7.0]# bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic  test-kafka --from-beginningCopy the code

Send message “Hello world” with producer:

View consumers:

You can see from above that the consumer successfully received the message sent by the producer.

In the next section, we’ll look at how to deploy a Kafka cluster.