赞
踩
1.编写docker-compose.yml文件
version: '3.9' services: zookeeper: image: wurstmeister/zookeeper volumes: - ./zookeeper/data:/data ports: - 2181:2181 kafka: image: wurstmeister/kafka ports: - 9092:9092 environment: KAFKA_BROKER_ID: 0 KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.33.249:9092 # 暴露在外的地址 KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092 volumes: - ./kafka/etc/localtime:/etc/localtime - ./kafka/kafka-logs:/kafka depends_on: - zookeeper links: - zookeeper kafka-manager: image: sheepkiller/kafka-manager ## 镜像:开源的web管理kafka集群的界面 environment: ZK_HOSTS: zookeeper:2181 KAFKA_MANAGER_AUTH_ENABLED: "true" KAFKA_MANAGER_USERNAME: "admin" KAFKA_MANAGER_PASSWORD: "admin" ports: - "9000:9000" depends_on: - zookeeper - kafka links: - zookeeper
2.docker-compose ps查看是否启动成功
3.查看启动的容器,进入kafka容器
docker ps
docker exec -it kafka_kafka_1 /bin/bash
4.创建一个名称为test的topic:
kafka-topics.sh --create --topic test \
--zookeeper zookeeper:2181 --replication-factor 1 \
--partitions 1
5.查看刚刚创建的topic信息
kafka-topics.sh --zookeeper zookeeper:2181 \
--describe --topic test
6.打开生产者发送若干条消息
kafka-console-producer.sh --topic=test \
--broker-list kafka:9092
7.新开一个shell窗口,进入kafka容器,打开消费者接收消息
kafka-console-consumer.sh \
--bootstrap-server kafka:9092 \
--from-beginning --topic test
8.如果发送消息和接收消息成功,则证明kafka可用
9.查看kafka的版本
find / -name \*kafka_\* | head -1 | grep -o '\kafka[^\n]*'
查出的这个文件名称中,2.13是Scala版本,2.7.0是Kafka版本
10.访问kafka的管理页面
http://192.168.31.249:9000/
11.添加cluster
点击保存刷新页面
进入可查看kafka相关信息
方式二:安装kafdrop
version: '3.9' services: zookeeper: image: wurstmeister/zookeeper volumes: - ./zookeeper/data:/data ports: - 2181:2181 kafka: image: wurstmeister/kafka ports: - 9092:9092 environment: KAFKA_BROKER_ID: 0 KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://127.0.0.1:9092 # 暴露在外的地址这里改为自己的 KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092 volumes: - ./kafka/etc/localtime:/etc/localtime - ./kafka/kafka-logs:/kafka depends_on: - zookeeper links: - zookeeper kafdrop: image: obsidiandynamics/kafdrop:3.27.0 container_name: kafdrop restart: "no" environment: KAFKA_BROKERCONNECT: "kafka:9092" JVM_OPTS: "-Xms64M -Xmx128M" ports: - "9000:9000" depends_on: - kafka
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。