kafka目录结构
# kafka安装目录
/usr/local/Cellar/kafka/2.6.0
# 配置文件目录
/usr/local/etc/kafka/
# 如果超时,在server.properties中增加
zookeeper.connection.timeout.ms=6000000
先启动zookeeper
/usr/local/Cellar/kafka/2.6.0/bin/zookeeper-server-start
/usr/local/etc/kafka/zookeeper.properties &
cd /usr/local/Cellar/kafka/2.6.0/bin
./zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties &
# 不使用配置启动的方式
zkServer start
zkServer stop
检测是否启动成功
ps aux | grep zookeeper
(上图为启动成功时截图)
后启动kafka
/usr/local/Cellar/kafka/2.6.0/bin/kafka-server-start
/usr/local/etc/kafka/server.properties &
# zk如果使用配置启动,kafka也得使用配置启动,不然会报错
cd /usr/local/Cellar/kafka/2.6.0/bin
./kafka-server-start /usr/local/etc/kafka/server.properties &
检测是否启动成功
ps aux | grep kakfka
(上图为启动成功时截图)
创建topic
kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic basket_test
查看topic list
kafka-topics --list --zookeeper localhost:2181
要是报:Timed out waiting for connection while in state: CONNECTING ,那就是没有启动zk、kafka
创建一个生产者
kafka-console-producer --broker-list localhost:9092 --topic basket_test
进入指定生产者
kafka-console-producer --broker-list localhost:9092 --topic basket_test
创建一个消费者
kafka-console-consumer --bootstrap-server localhost:9092 --topic basket_test --from-beginning