前言
OS: Ubuntu 20.04 LTS
docker: 20.10.12
docker-compose: 1.25.0
kafka: 2.8.1
kafka-map: 1.2.0
搭建 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]
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}'
docker image search --list-tags wurstmeister/kafka --limit 1000
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
docker-compose up -d
- 檢視 kafka 和 zookeeper 是否正常執行
docker stats kafka zookeeper
視覺化工具
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
Python 讀寫 kafka
本文出自 qbit snap