02. Kafka 빠르게 설치해보기

Apache Kafka 설치

Apache Kafka

실습은 Scala 2.13 - kafka_2.13-3.1.0.tgz 로 진행

설치 및 zookeeper, broker 실행

// Apache Kafka down
$ wget <https://dlcdn.apache.org/kafka/3.1.0/kafka_2.13-3.1.0.tgz>

// 압축 해제
$ tar zxvf kafka_2.13-3.1.0.tgz kafka_2.13-3.1.0/

// zookeeper 실행
$ bin/zookeeper-server-start.sh config/zookeeper.properties
// zookeepr 실행 확인.
$ ./ bin/zookeeper-shell.sh localhost:2181

// broker를 띄우기 위한 설정
$ vi config/server.properties

31 line '#' 제거및
listeners = 127.0.0.1:9092 기입 후 저장.

// broker 실행
$ bin/kafka-server-start.sh config/server.properties

위의 사진은 주키퍼 실행, 아래의 사진은 브로커 실행

Topic 생성

// bin 폴더로 이동
$ cd bin

// topic 생성
$ kafka-topics.sh --create --topic fastcampus --bootstrap-server localhost:9092

// topic 생성 확인
$ kafka-topics.sh --list --topic fastcampus --bootstrap-server local
host:9092
  • topic name 생성 제약

    • 공백 불가

    • ‘_’ , ’.’ 은 내부의 메트릭과의 충돌로 인해 권장하지 않는다.

    • name max length = 249

Message Producing

// 메시지를 입력하기 위해 producer-console로 이동
$ ./kafka-console-producer.sh --bootstrap-server localhost:9092 --topic fastcampus

// producing
hello
fastcampus

Message Consuming

// consume을 시작한 뒤 produce된 메시지가 보인다.
$ ./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic fastcampus

// 전체 message를 보고 싶은 경우 --from-beginning 옵션을 추가.
$ ./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic fastcampus --from-beginning

Zookeeper shell 확인

// zookeeper shell 실행
$ ./zookeeper-shell.sh localhost:2181

Last updated