1.下載並解壓到/usr/local/src目錄下

2.運行kafka需要使用Zookeeper,先啟動Zookeeper,如果沒有Zookeeper,可以使用kafka自帶打包和配置好的Zookeeper
前台運行:
bin/zookeeper-server-start.sh config/zookeeper.properties
后台運行:
nohup bin/zookeeper-server-start.sh config/zookeeper.properties > zookeeper-run.log 2>&1 &

3.啟動kafka
前台運行:
bin/kafka-server-start.sh config/server.properties
后台運行:
nohup bin/kafka-server-start.sh config/server.properties > kafka-run.log 2>&1 &

4.創建topic
創建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.創建生產者和消費者
創建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


