Install Kafka with docker

By | 2020년 8월 20일
Table of Content

Install Kafka with docker

참조
참조
참조

Kafka 설치하기

mkdir kafka
cd kafka/

vi docker-compose.yml
version: '2'

networks:
  test:

services:
  zookeeper:
    image: wurstmeister/zookeeper
    container_name: zookeeper
    ports:
      - "2181:2181"
    networks:
      - test
    restart: always

  kafka:
    image: wurstmeister/kafka:2.13-2.6.0
    container_name: kafka
    depends_on:
      - zookeeper
    environment:
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://172.31.11.235:9092
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
      KAFKA_ADVERTISED_HOST_NAME: 172.31.11.235
      KAFKA_ADVERTISED_PORT: 9092
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "9092:9092"
    networks:
      - test
    restart: always
docker-compose up -d

docker container logs zookeeper
docker container logs kafka

# docker-compose down
# docker-compose stop

Kafka 정상작동 확인하기

인스턴스에 접속합니다.

docker exec -it kafka /bin/bash

토픽을 생성합니다.

/opt/kafka/bin/kafka-topics.sh --create \
    --zookeeper 172.31.11.235:2181 \
    --replication-factor 1 \
    --partitions 1 \
    --topic test

생성된 토픽을 확인합니다.

/opt/kafka/bin/kafka-topics.sh --list \
    --zookeeper 172.31.11.235:2181

토픽에 메시지를 전송합니다.

/opt/kafka/bin/kafka-console-producer.sh \
    --broker-list 172.31.11.235:9092 \
    --topic test

새로운 터미널을 열고, 메시지가 전송되었는지 확인합니다.

docker exec -it kafka /bin/bash

/opt/kafka/bin/kafka-console-consumer.sh \
    --bootstrap-server 172.31.11.235:9092 \
    --topic test \
    --from-beginning

2 thoughts on “Install Kafka with docker

  1. Pingback: Kafka 를 이용한 메시징 – 상구리의 기술 블로그

  2. Pingback: (Deprecated) Kafka 설치하기 – 상구리의 기술 블로그

답글 남기기