1.下载并解压到/usr/local/src目录下
bootstrap
2.运行kafka须要使用Zookeeper,先启动Zookeeper,若是没有Zookeeper,可使用kafka自带打包和配置好的Zookeeper3d
前台运行: bin/zookeeper-server-start.sh config/zookeeper.properties 后台运行: nohup bin/zookeeper-server-start.sh config/zookeeper.properties > zookeeper-run.log 2>&1 &
3.启动kafkacode
前台运行: bin/kafka-server-start.sh config/server.properties 后台运行: nohup bin/kafka-server-start.sh config/server.properties > kafka-run.log 2>&1 &
4.建立topicserver
建立kafka topic: bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test 显示kafka topic: bin/kafka-topics.sh -list -zookeeper localhost:2181
5.建立生产者和消费者blog
建立kafka生产者: bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test 建立kafka消费者: bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning 设置kafka消费组名: bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning --consumer-property group.id=test-group