인프런 커뮤니티 질문&답변

jae yeol lee님의 프로필 이미지
jae yeol lee

작성한 질문수

카프카 완벽 가이드 - 커넥트(Connect) 편

수강환경 VirtualBox -> Docker

작성

·

72

0

어디에 올리는 것이 적합한지 모르겠어서 여기에 올려봅니다.

혹시 virtual box 사용하여 강의 환경설정하시는 것이 조금 번거로우신 분들을 위해, 강의 실습을 진행하며 사용했던 docker-compose 파일을 공유드립니다!

강의의 세부적인 부분까지 따라하진 못할수도 있지만, 좀 더 편하고 빠르게 수업을 따라가실 수 있으실거에요. 너무나 좋은 강의 감사드립니다!

(사용하시게 되면 connector config 파일들에서 DB connection url localhost 부분을 mysql로 바꿔서 등록하시면 되요)

name: 'plz_kafka'
services:
  zookeeper:
    image: confluentinc/cp-zookeeper:7.5.3
    hostname: zookeeper
    container_name: zookeeper
    ports:
      - "2181:2181"
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
    healthcheck:
      test: echo srvr | nc zookeeper 2181 || exit 1
      start_period: 10s
      retries: 20
      interval: 10s

  broker:
    image: confluentinc/cp-enterprise-kafka:7.5.3
    hostname: broker
    container_name: broker
    depends_on:
      zookeeper:
         condition: service_healthy
    ports:
      - "29092:29092"
      - "9092:9092"
      - "9101:9101"
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
      KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
      KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'
      KAFKA_JMX_PORT: 9101
      KAFKA_JMX_HOSTNAME: localhost
      KAFKA_CONFLUENT_SCHEMA_REGISTRY_URL: http://schema-registry:8081
    healthcheck:
      test: nc -z localhost 9092 || exit -1
      start_period: 15s
      interval: 5s
      timeout: 10s
      retries: 10

  kafka-connect:
    image: confluentinc/cp-kafka-connect-base:7.7.1
    container_name: kafka-connect
    depends_on:
      - broker
#      - schema-registry
    ports:
      - 8083:8083
    environment:
      CONNECT_BOOTSTRAP_SERVERS: "broker:29092"
      CONNECT_REST_PORT: 8083
      CONNECT_GROUP_ID: kafka-connect
      CONNECT_CONFIG_STORAGE_TOPIC: _connect-configs
      CONNECT_OFFSET_STORAGE_TOPIC: _connect-offsets
      CONNECT_STATUS_STORAGE_TOPIC: _connect-status
      CONNECT_KEY_CONVERTER: org.apache.kafka.connect.json.JsonConverter
      CONNECT_VALUE_CONVERTER: org.apache.kafka.connect.json.JsonConverter
#      CONNECT_VALUE_CONVERTER: io.confluent.connect.avro.AvroConverter
      CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL: 'http://schema-registry:8081'
      CONNECT_REST_ADVERTISED_HOST_NAME: "kafka-connect"
      CONNECT_LOG4J_APPENDER_STDOUT_LAYOUT_CONVERSIONPATTERN: "[%d] %p %X{connector.context}%m (%c:%L)%n"
      CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: "1"
      CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: "1"
      CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: "1"
      #  ---------------
      CONNECT_PLUGIN_PATH: /usr/share/java,/usr/share/confluent-hub-components
    # If you want to use the Confluent Hub installer to d/l component, but make them available
    # when running this offline, spin up the stack once and then run :
    #   docker cp kafka-connect:/usr/share/confluent-hub-components ./data/connect-jars
    volumes:
      - $PWD/data:/data
    # In the command section, $ are replaced with $$ to avoid the error 'Invalid interpolation format for "command" option'
    command:
      - bash
      - -c
      - |
        echo "Installing Connector"
        confluent-hub install --no-prompt debezium/debezium-connector-mysql:1.7.0
        confluent-hub install --no-prompt jcustenborder/kafka-connect-spooldir:2.0.65
        confluent-hub install --no-prompt confluentinc/kafka-connect-jdbc:10.8.0
        curl -o /usr/share/confluent-hub-components/confluentinc-kafka-connect-jdbc/lib/mysql-connector-java.jar \
        https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.26/mysql-connector-java-8.0.26.jar
        #
        echo "Launching Kafka Connect worker"
        /etc/confluent/docker/run &
        #
        sleep infinity

  schema-registry:
    image: confluentinc/cp-schema-registry:6.2.0
    container_name: schema-registry
    ports:
      - "8081:8081"
    depends_on:
      - broker
    environment:
      SCHEMA_REGISTRY_HOST_NAME: schema-registry
      SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: broker:29092

  mysql:
    image: mysql:8.0
    container_name: mysql
    environment: # 환경 변수 설정
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: 'connect_dev'
      MYSQL_PASSWORD: 'connect_dev'
      MYSQL_DATABASE: om
      TZ: Asia/Seoul
    ports:
      - "3306:3306"
    volumes:
      - ./mysql/:/var/lib/mysql

답변 1

1

권 철민님의 프로필 이미지
권 철민
지식공유자

안녕하십니까

오, 이걸 Docker로 다 환경 구성 해보셨군요.

많은 분께 도움이 되겠지만, 누구보다 저한테 더 큰 도움일 것 같습니다.

좋은 자료 주셔서 감사합니다.

jae yeol lee님의 프로필 이미지
jae yeol lee

작성한 질문수

질문하기