docker 설치
docker-compose 설치
docker-compose파일 작성
version: '2'
services:
# wurstmeister/zookeeper:3.4.6
zookeeper:
hostname: zookeeper
container_name: zookeeper
image: wurstmeister/zookeeper:3.4.6
ports:
- "2181:2181"
# wurstmeister/kafka:2.13-2.8.1 - broker 1
kafka1:
hostname: kafka1
container_name: kafka1
image: wurstmeister/kafka:2.13-2.8.1
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_HOST_NAME: kafka1
BOOTSTRAP_SERVERS: kafka1:9092, kafka2:9093, kafka3:9094
ports:
- "9092:9092"
depends_on:
- zookeeper
# wurstmeister/kafka:2.13-2.8.1 - broker 2
kafka2:
hostname: kafka2
container_name: kafka2
image: wurstmeister/kafka:2.13-2.8.1
environment:
KAFKA_BROKER_ID: 2
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_HOST_NAME: kafka2
BOOTSTRAP_SERVERS: kafka1:9092, kafka2:9093, kafka3:9094
ports:
- "9093:9092"
depends_on:
- zookeeper
# wurstmeister/kafka:2.13-2.8.1 - broker 3
kafka3:
hostname: kafka3
container_name: kafka3
image: wurstmeister/kafka:2.13-2.8.1
environment:
KAFKA_BROKER_ID: 3
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_HOST_NAME: kafka3
BOOTSTRAP_SERVERS: kafka1:9092, kafka2:9093, kafka3:9094
ports:
- "9094:9092"
depends_on:
- zookeeper
컨테이너에 접속
sudo docker exec -it kafka1 /bin/bash
토픽 생성
kafka-topics.sh --create --bootstrap-server kafka1:9092 --topic test
토픽에 데이터 넣기 테스트
kafka-console-producer.sh --bootstrap-server kafka1:9092 --topic test
토픽 데이터 읽기
kafka-console-consumer.sh --bootstrap-server kafka1:9092 --topic test --from-beginning