1、首先安装 zookeeper
2、下载kafka
1 | wget https://mirrors.cnnic.cn/apache/kafka/2.1.0/kafka_2.11-2.1.0.tgz |
cd kafka_2.11-2.1.0/config/
vim server.properties
1 |
|
cd /Users/onlyone/software/kafka/kafka_2.11-2.1.0
bin/kafka-server-start.sh config/server.properties &
1 |
|
bin/kafka-server-stop.sh
1 |
|
➜ jps
41505 QuorumPeerMain
66244 Jps
64472 Kafka
252
1 |
|
bin/kafka-topics.sh –create –zookeeper localhost:2181 –replication-factor 1 –partitions 1 –topic test1
1 | * 查看topic创建情况 |
bin/kafka-topics.sh –list –zookeeper localhost:2181
1 |
bin/kafka-topics.sh –describe –zookeeper localhost:2181
1 |
|
Topic:test1 PartitionCount:1 ReplicationFactor:1 Configs:
Topic: test1 Partition: 0 Leader: 1 Replicas: 1 Isr: 1
1 | 参数解析:https://www.cnblogs.com/shengulong/p/9013282.html |
bin/kafka-console-producer.sh –broker-list 192.168.0.14:9092 –topic test1
注意:首次,topic不存在时,会自动创建
上面命令是在控制台输入要发送的消息,“回车”单条消息结束。
echo ‘{“name”:”Steve”, “title”:”Captain America”}’ | bin/kafka-console-producer.sh –broker-list 192.168.0.14:9092 –topic test1
将发送的消息放在执行命令中。
1 |
|
bin/kafka-console-consumer.sh –bootstrap-server 192.168.0.14:9092 –topic test1 –from-beginning