Docker Compose - Kafka 클러스터 구성하기

목차

zookeeper 설정

version: "3.6"

services:
zookeeper:
container_name: zookeeper
image: wurstmeister/zookeeper:3.4.6
volumes:
- "./zookeeper/data:/data"
- "./zookeeper/logs:/datalog"
ports:
- "2181:2181"

Kafka 설정

  • KAFKA_BROKER_ID
  • KAFKA_ZOOKEEPER_CONNECT
  • KAFKA_ADVERTISED_HOST_NAME
  • KAFKA_ADVERTISED_PORT
  • KAFKA_CREATE_TOPICS
  • KAFKA_ADVERTISED_LISTENERS
  • KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 2
version: "3.6"

...

kafka1:
container_name: kafka1
image: wurstmeister/kafka:2.12-2.3.0
restart: on-failure
ports:
- "9092:9092"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_HOST_NAME: 192.168.0.2
KAFKA_ADVERTISED_PORT: 9092
KAFKA_CREATE_TOPICS: "temp_topic:1:1"
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.0.2:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 2
depends_on:
- zookeeper

전체 소스 코드

version: "3.6"

services:
zookeeper:
container_name: zookeeper
image: wurstmeister/zookeeper:3.4.6
volumes:
- "./zookeeper/data:/data"
- "./zookeeper/logs:/datalog"
ports:
- "2181:2181"

kafka1:
container_name: kafka1
image: wurstmeister/kafka:2.12-2.3.0
restart: on-failure
ports:
- "9092:9092"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_HOST_NAME: 192.168.0.2
KAFKA_ADVERTISED_PORT: 9092
KAFKA_CREATE_TOPICS: "temp_topic:1:1"
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.0.2:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 2
depends_on:
- zookeeper
kafka2:
container_name: kafka2
image: wurstmeister/kafka:2.12-2.3.0
restart: on-failure
ports:
- "9093:9092"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
KAFKA_BROKER_ID: 2
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_HOST_NAME: 192.168.0.2
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.0.2:9093
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 2
depends_on:
- zookeeper
kafka3:
container_name: kafka3
image: wurstmeister/kafka:2.12-2.3.0
restart: on-failure
ports:
- "9094:9092"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
KAFKA_BROKER_ID: 3
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_HOST_NAME: 192.168.0.2
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.0.2:9094
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 2
depends_on:
- zookeeper
Share