需要java环境,推荐1.8以上


下载kafka,解压,进入kafka的bin目录

wget http://archive.apache.org/dist/kafka/2.4.0/kafka_2.11-2.4.0.tgz 

启动zookeeper(Kafka 0.5.x版本以上已经自带ZooKeper)

nohup ./zookeeper-server-start.sh ../config/zookeeper.properties > zookeeper.log 2>&1 &

备注:自测的话直接使用自带的zookeeper就行,要是生产的话,建议分离,另起一套。 

启动kafka

nohup ./kafka-server-start.sh ../config/server.properties > kafka.log 2>&1 &

查看zookeeper和kafka是否启动

netstat -tanlp | egrep "2181|9092"

创建主题:test

./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

生产主题:test

./kafka-console-producer.sh --broker-list localhost:9092 --topic test

消费主题:test

./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test 

查看所有主题

 ./kafka-topics.sh  --zookeeper localhost:2181 --list

查看指定主题描述信息

./kafka-topics.sh --describe  --zookeeper localhost:2181  --topic test

配置外网访问kafka

修改server.properties的两行默认配置

# 允许外部端口连接                                            
listeners=PLAINTEXT://0.0.0.0:9092  
# 外部代理地址                                                
advertised.listeners=PLAINTEXT://192.168.23.143:9092

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐