本篇筆記紀錄一下如何用 docker 建置 Kafka Cluster。
配置為 3 台 Brokers,1 台 Zookeeper。
建立一個 docker-compose.yml 內容如下:
version: '3'
services:
zookeeper:
container_name: zookeeper
hostname: zookeeper
image: confluentinc/cp-zookeeper:7.0.1
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- "2181:2181"
networks:
- kafka-net
kafka1:
container_name: kafka1
hostname: kafka1
image: confluentinc/cp-kafka:7.0.1
depends_on:
- zookeeper
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka1:9092
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 3
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 2
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 3
KAFKA_LOG_RETENTION_HOURS: 168
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
networks:
- kafka-net
kafka2:
container_name: kafka2
hostname: kafka2
image: confluentinc/cp-kafka:7.0.1
depends_on:
- zookeeper
ports:
- "9093:9093"
environment:
KAFKA_BROKER_ID: 2
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka2:9093
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9093
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 3
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 2
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 3
KAFKA_LOG_RETENTION_HOURS: 168
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
networks:
- kafka-net
kafka3:
container_name: kafka3
hostname: kafka3
image: confluentinc/cp-kafka:7.0.1
depends_on:
- zookeeper
ports:
- "9094:9094"
environment:
KAFKA_BROKER_ID: 3
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka3:9094
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9094
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 3
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 2
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 3
KAFKA_LOG_RETENTION_HOURS: 168
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
networks:
- kafka-net
kafka-manager:
container_name: kafka-manager
hostname: kafka-manager
image: hlebalbau/kafka-manager:latest
depends_on:
- zookeeper
- kafka1
- kafka2
- kafka3
ports:
- "9000:9000"
environment:
ZK_HOSTS: zookeeper:2181
networks:
- kafka-net
networks:
kafka-net:
driver: bridge
建置完成後在 yml 文件路徑下執行 docker-compose
指令:
docker-compose up -d
在瀏覽器上開啟 kafka manager: http://localhost:9000
新增 Cluster:
輸入 cluster name 和 zookeeper DOMAIN & port:
保存:
檢視 Brokers:
建立 Topic(設定為 3 個分區,3 個副本):
檢視 Topic:
docker exec -it kafka1 /bin/bash
kafka-console-producer --topic=test-topic --broker-list kafka1:9092,kafka2:9093,kafka3:9094
docker exec -it kafka2 /bin/bash
kafka-console-consumer --bootstrap-server kafka1:9092,kafka2:9093,kafka3:9094 --from-beginning --topic test-topic
留学生在选择作业代写服务时,如何选择题目以避免被发现,是一个需要高度重视的问题。通过选择合适的题目类型、充分了解教授的偏好、避免与之前作业内容重复、注意留学生作业代写机构的专业领域和写手背景等策略,学生可以在一定程度上降低被发现的风险。