系统基础环境JDK
1.下载kafka
https://mirror.bit.edu.cn/apache/kafka/2.5.0/kafka_2.12-2.5.0.tgz
2.解压目录,进入目录config
3.修改server.properties,其他默认即可
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://172.16.20.53:9092
4.先运行kafka目录内自带的zookeeper
nohup ./bin/zookeeper-server-start.sh config/zookeeper.properties > zookeeper.log &
5.在运行kafka
nohup ./bin/kafka-server-start.sh config/server.properties > kafka.log &
6.查看日志以及端口没有错误之后,创建topic命名为elas
./bin/kafka-topics.sh --create --zookeeper localhost:2181 --topic elas --partitions 1 --replication-factor 1
7.查看topic状态
./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic elas
8.模拟生产端
./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic elas
9.模拟消费端
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic elas --from-beginning
备注:0.9之前版本命令格式
kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
10.查看信息
[root@demo001 bin]# ./kafka-console-producer.sh --broker-list localhost:9092 --topic elas
hello
kafa
test
ceshi shuju
[root@demo001 kafka_2.12-2.5.0]# ./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic elas --from-beginning
hello
kafa
test
ceshi shuju
11.查看topic列表
kafka-topics.sh --zookeeper 127.0.0.1:2180 --list
12.删除topic有以下几种方式
(1)通过kafka命令删除
server.properties添加:delete.topic.enable=true,然后重启
kafka-topics.sh --delete --zookeeper 127.0.0.1:2180 --topic test
(2)手动删除,无需重启服务
登陆kafka服务端,进入topic生成的目录里,可通过server.properties配置文件查看
数据目录
然后rm -rf TopticDirname
进入zookeeper
./zkCli.sh
ls /brokers/topics
rmr /brokers/topics/test
ls /config/topics
rmr /config/topics/test
网友评论