동기화
나 마스터 선출
등의 작업을 쉽게 구현할 수 있게 해준다.version: '3'
services:
zookeeper:
image: zookeeper:3.7
hostname: zookeeper
ports:
- "2181:2181"
environment:
ZOO_MY_ID: 1
ZOO_PORT: 2181
volumes:
- ./data/zookeeper/data:/data
- ./data/zookeeper/datalog:/datalog
메세지큐
version: '3'
services:
kafka1:
image: confluentinc/cp-kafka:7.0.0
hostname: kafka1
ports:
- "9091:9091"
environment:
KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka1:19091,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9091
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
KAFKA_BROKER_ID: 1
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
volumes:
- ./data/kafka1/data:/tmp/kafka-logs
depends_on:
- zookeeper
environment # KAFKA_BROKER_ID
클러스터 각 노드에 할당할 브로커의 아이디(중복불가)
# KAFKA_ZOOKEEPER_CONNECT
클러스터 구성에 사용할 주키퍼 호스트 정보
# KAFKA_ADVERTISEMENT_LISTENERS
카프카 브로커를 가리키는 주소 목록. 카프카 브로커는 초기 연결 시 이를 클라이언트에게 보낸다.
# KAFKA_INTER_BROKER_LISTENER_NAME
브로커 간 통신에 사용할 리스너명
# KAFKA_LISTENER_SECURITY_PROTOCOL_MAP
보안 프로토콜 지정. PLAINTEXT는 리스너가 암호화되지 않은 것을 말함.
# KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR
토픽 파티션의 복제 개수
docker-compose.yml
을 통해 설치version: '3'
services:
zookeeper:
image: zookeeper:3.7
hostname: zookeeper
ports:
- "2181:2181"
environment:
ZOO_MY_ID: 1
ZOO_PORT: 2181
volumes:
- ./data/zookeeper/data:/data
- ./data/zookeeper/datalog:/datalog
kafka1:
image: confluentinc/cp-kafka:7.0.0
hostname: kafka1
ports:
- "9091:9091"
environment:
KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka1:19091,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9091
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
KAFKA_BROKER_ID: 1
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
volumes:
- ./data/kafka1/data:/tmp/kafka-logs
depends_on:
- zookeeper
kafka2:
image: confluentinc/cp-kafka:7.0.0
hostname: kafka2
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka2:19092,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
KAFKA_BROKER_ID: 2
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
volumes:
- ./data/kafka2/data:/tmp/kafka-logs
depends_on:
- zookeeper
kafka3:
image: confluentinc/cp-kafka:7.0.0
hostname: kafka3
ports:
- "9093:9093"
environment:
KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka3:19093,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9093
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL
KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
KAFKA_BROKER_ID: 3
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
volumes:
- ./data/kafka3/data:/tmp/kafka-logs
depends_on:
- zookeeper
kafdrop:
image: obsidiandynamics/kafdrop
restart: "no"
ports:
- "9000:9000"
environment:
KAFKA_BROKER_CONNECT: "kafka1:19091"
depends_on:
- kafka1
- kafka2
- kafka3
작성이 완료되었다면 아래와 같이 실행한다
$ docker-compose -f docker-compose.yml up -d
종료하는 방법은 아래를 참고한다.
$ docker-compose -f docker-compose.yal down
이후 kafka 컨테이너에 접속해 kafka 명령어를 사용할 수 있다.
$ docker exec -it ${컨테이너명} /bin/bash
혹은 kafdrop에 접속해(yml에 작성한 port로 접속) GUI로 kafka 클러스터를 관리할 수도 있다!