前言
- 技术栈
OS: Ubuntu 20.04 LTS
docker: 20.10.12
docker-compose: 1.25.0
kafka: 2.8.1
kafka-map: 1.2.0
搭建 kafka
- kafka docker 镜像:https://hub.docker.com/r/wurs…
- kafka docker 镜像 github:https://github.com/wurstmeister
- 搜寻 kafka 镜像
# docker search kafka
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
wurstmeister/kafka Multi-Broker Apache Kafka Image 1469 [OK]
spotify/kafka A simple docker image with both Kafka and Zo… 414 [OK]
sheepkiller/kafka-manager kafka-manager 214 [OK]
kafkamanager/kafka-manager Docker image for Kafka manager 145
ches/kafka Apache Kafka. Tagged versions. JMX. Cluster-… 117 [OK]
- 列出 tag
wget -q https://registry.hub.docker.com/v1/repositories/wurstmeister/kafka/tags -O - | sed -e 's/[][]//g' -e 's/"//g'-e's/ //g'| tr'}''\n' | awk -F: '{print $3}'
- 也能够用 podman 命令列出
docker image search --list-tags wurstmeister/kafka --limit 1000
- 编排文件 docker-compose.yml
version: '3.5'
services:
zookeeper:
image: wurstmeister/zookeeper:3.4.6
container_name: zookeeper
ports:
- "2181:2181"
restart: unless-stopped
kafka:
image: wurstmeister/kafka:2.13-2.8.1
container_name: kafka
ports:
- "9092:9092"
environment:
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.1.46:9092
- KAFKA_LISTENERS=PLAINTEXT://:9092
volumes:
- /var/run/docker.sock:/var/run/docker.sock
restart: unless-stopped
- 启动 kafka 和 zookeeper
docker-compose up -d
- 查看 kafka 和 zookeeper 是否失常运行
docker stats kafka zookeeper
可视化工具
- 试用了 LogiKM 2.6.0、Offset Explorer 2.2(kafka tool)都不太称心
- 最初差强人意的抉择了国产的 kafka-map
- docker 装置 kafka-map
docker run -d \
-p 8888:8080 \
-v /opt/kafka-map/data:/usr/local/kafka-map/data \
-e DEFAULT_USERNAME=admin \
-e DEFAULT_PASSWORD=admin \
--name kafka-map \
--restart unless-stopped dushixiang/kafka-map:latest
- 装置完后用浏览器关上 http://192.168.1.46:8888,在 web 界面中接入 kafka
Python 读写 kafka
- 未完待续 …
本文出自 qbit snap