1、下载
2、修改配置
vim zookeeper.properties
vim server.properties
3、运行zk
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
./zookeeper-server-start.sh -daemon ../config/zookeeper.properties #启动zookeeper
./zookeeper-server-stop.sh #停止zookeeper
4、运行kafa
bin/kafka-server-start.sh -daemon config/server.properties
./kafka-server-start.sh -daemon ../config/server.properties #启动kafka
./kafka-server-stop.sh #停止kafka
5、测试
(1)创建主题
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic iot_topic
(2)列出主题
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
(3)生产者发消息
./kafka-console-producer.sh --broker-list localhost:9092 --topic iot_topic
(4)消费者接收消息
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic iot_topic --from-beginning
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group iot_group
(5)查看消费组信息
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group iot_group
[root@localhost kafka]# bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
[root@localhost kafka]# bin/kafka-server-start.sh -daemon config/server.properties
[root@localhost kafka]# bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic iot_topic
WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to use either, but not both.
Created topic iot_topic.
[root@localhost kafka]# bin/kafka-topics.sh --list --bootstrap-server localhost:9092
iot_topic
#生产者发消息
[root@localhost kafka]# bin/kafka-console-producer.sh --broker-list localhost:9092 --topic iot_topic
>hah
>sdw
>1
>2
>3
#消费者收消息
[root@localhost kafka]# bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic iot_topic --group iot_group
hah
sdw
wuqing
1
2