Skip to content

Commit

Permalink
Update KafkaQuickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
T5750 committed Mar 30, 2024
1 parent fef1d5d commit d4c5f3c
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions doc/source/big-data/kafka/KafkaQuickstart.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
# Kafka Quickstart
## 1.Download the code
```
```sh
tar -xzf kafka_2.11-0.9.0.0.tgz
```

## 2.Start the server
```
```sh
bin/zookeeper-server-start.sh config/zookeeper.properties
```
```
```sh
bin/kafka-server-start.sh config/server.properties &
```

## 3.Create a topic
创建名为test的topic,1个分区分别存放数据,数据备份总共1份:
```
```sh
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
```
查看topic列表:
```
```sh
bin/kafka-topics.sh --list --zookeeper localhost:2181
```

## 4.Send some messages
kafka命令发送数据:
```
```sh
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
```

## 5.Start a consumer
kafka命令接收数据:
```
```sh
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
# bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
```

## 6.Setting up a multi-broker cluster
```
```sh
cp config/server.properties config/server-1.properties
cp config/server.properties config/server-2.properties
```
Expand All @@ -51,48 +52,48 @@ cp config/server.properties config/server-2.properties
listeners=PLAINTEXT://:9094
log.dirs=/tmp/kafka-logs-2
```
```
```sh
bin/kafka-server-start.sh config/server-1.properties &
bin/kafka-server-start.sh config/server-2.properties &
```
```
```sh
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic my-replicated-topic
```
```
```sh
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test
```
```
```sh
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic my-replicated-topic
```
```
```sh
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --from-beginning --topic my-replicated-topic
```
```
```sh
ps aux | grep server-1.properties
kill -9 7564
```
```
```sh
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic
```
```
```sh
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --from-beginning --topic my-replicated-topic
```

## 7.Use Kafka Connect to import/export data
```
```sh
echo -e "foo\nbar" > test.txt
```
```
```sh
bin/connect-standalone.sh config/connect-standalone.properties config/connect-file-source.properties config/connect-file-sink.properties
```
```
```sh
cat test.sink.txt
```
```
```sh
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic connect-test --from-beginning
```
```
```sh
echo "Another line" >> test.txt
```

Expand Down

0 comments on commit d4c5f3c

Please sign in to comment.